From e469f3e3ea78d1bdbcb26e9ad2781469e820ecab Mon Sep 17 00:00:00 2001 From: trin Date: Sun, 23 Jun 2024 11:42:58 +0300 Subject: [PATCH] =?UTF-8?q?minorfix.=20=D0=A0=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=D0=B4=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA?= =?UTF-8?q?=D0=B0=D0=BC=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commands/import_posts_to_dev.py | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) rename {authn => posts}/management/commands/import_posts_to_dev.py (83%) diff --git a/authn/management/commands/import_posts_to_dev.py b/posts/management/commands/import_posts_to_dev.py similarity index 83% rename from authn/management/commands/import_posts_to_dev.py rename to posts/management/commands/import_posts_to_dev.py index f99ba81ec..b65643538 100644 --- a/authn/management/commands/import_posts_to_dev.py +++ b/posts/management/commands/import_posts_to_dev.py @@ -42,6 +42,7 @@ def handle(self, *args, **options): result = { 'post_exists': 0, 'post_created': 0, + 'post_updated': 0, 'user_created': 0 } @@ -71,6 +72,7 @@ def handle(self, *args, **options): html=markdown_text(item['content_text']), image=author.avatar, # хак для постов типа "проект", чтобы не лазить по вастрику лишний раз created_at=item['date_published'], + last_activity_at=item['date_modified'], comment_count=item['_club']['comment_count'], view_count=item['_club']['view_count'], upvotes=item['_club']['upvotes'], @@ -85,28 +87,26 @@ def handle(self, *args, **options): coauthors=[] ) - exists = False try: post = Post.objects.get(id=item['id']) - exists = True + if options['force']: + post.__dict__.update(**defaults) + post.save() + result['post_updated'] += 1 + self.stdout.write(" 📝 \"{}\" запись отредактирована".format(item['title'])) + else: + result['post_exists'] += 1 + self.stdout.write(" 📌 \"{}\" уже существует".format(item['title'])) except Post.DoesNotExist: - post = Post.objects.create(**defaults) - - if exists and not options['force']: - result['post_exists'] += 1 - self.stdout.write(" 📌 \"{}\" уже существует".format(item['title'])) - continue - - post.__dict__.update(defaults) - post.save() - - result['post_created'] += 1 - self.stdout.write(" 📄 \"{}\" запись создана".format(item['title'])) + Post.objects.create(**defaults) + result['post_created'] += 1 + self.stdout.write(" 📄 \"{}\" запись создана".format(item['title'])) self.stdout.write("") self.stdout.write("Итого:") self.stdout.write("📄 Новых постов: {}".format(result['post_created'])) self.stdout.write("📌 Уже существовало: {}".format(result['post_exists'])) + self.stdout.write("📝 Отредактировано: {}".format(result['post_updated'])) self.stdout.write("👤 Новых пользователей: {}".format(result['user_created']))