update_names.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:epuap-watchdog 作者: ad-m 项目源码 文件源码
def handle(self, comment, no_progress, dry_run, institutions_id, *args, **options):
        self.updated, self.skipped, self.errored = 0, 0, 0
        with transaction.atomic():
            for institution in self.get_iter(self.get_queryset(institutions_id), no_progress):
                name_resp = normalize(institution.resp.data.get('name'))
                name_regon = normalize(institution.regon_data.data.get('nazwa'))
                best_name = name_resp if len(name_resp) >= len(name_regon) else name_regon
                if institution.name != best_name:
                    if dry_run:
                        pprint({'id': institution.id,
                                'best_name': best_name,
                                'current_x': institution.name,
                                'resp_name': institution.resp.data.get('name'),
                                'regn_name': institution.regon_data.data.get('nazwa')
                                })
                    institution.name = best_name
                    if not dry_run:
                        institution.save(update_fields=['name'])
                    self.updated += 1
                else:
                    self.skipped += 1
        self.stdout.write(("There is {} institutions changed, which "
                           "{} updated and "
                           "{} skipped.").format(self.updated + self.skipped, self.updated, self.skipped))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号