From 3a260fb2f7f9a5a7984c0dcbfcdb095f37add11c Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Mon, 14 Mar 2022 15:52:22 -0400 Subject: [PATCH] Adding count to activity for exported OPML, for #1646. --- apps/feed_import/models.py | 6 +++++- apps/feed_import/views.py | 2 +- apps/profile/models.py | 2 +- apps/social/models.py | 6 +++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/feed_import/models.py b/apps/feed_import/models.py index 45a392680..6371a1ab8 100644 --- a/apps/feed_import/models.py +++ b/apps/feed_import/models.py @@ -106,7 +106,11 @@ class OPMLExporter(Importer): except Feed.DoesNotExist: continue self.feeds = dict(self.feeds) - + + @property + def feed_count(self): + return len(self.feeds) + class OPMLImporter(Importer): diff --git a/apps/feed_import/views.py b/apps/feed_import/views.py index 56842085e..9eaf98df5 100644 --- a/apps/feed_import/views.py +++ b/apps/feed_import/views.py @@ -83,7 +83,7 @@ def opml_export(request): opml = exporter.process() from apps.social.models import MActivity - MActivity.new_opml_export(user_id=user.pk) + MActivity.new_opml_export(user_id=user.pk, count=exporter.feed_count) response = HttpResponse(opml, content_type='text/xml; charset=utf-8') response['Content-Disposition'] = 'attachment; filename=NewsBlur-%s-%s.opml' % ( diff --git a/apps/profile/models.py b/apps/profile/models.py index c36a7c8e6..172bf21f6 100644 --- a/apps/profile/models.py +++ b/apps/profile/models.py @@ -759,7 +759,7 @@ class Profile(models.Model): msg.send(fail_silently=True) from apps.social.models import MActivity - MActivity.new_opml_export(user_id=self.user.pk, automated=True) + MActivity.new_opml_export(user_id=self.user.pk, count=exporter.feed_count, automated=True) logging.user(self.user, "~BB~FM~SBSending OPML backup email to: %s" % self.user.email) diff --git a/apps/social/models.py b/apps/social/models.py index 781a5237f..2b62e679b 100644 --- a/apps/social/models.py +++ b/apps/social/models.py @@ -3232,14 +3232,14 @@ class MActivity(mongo.Document): cls.objects.create(**params) @classmethod - def new_opml_export(cls, user_id, automated=False): + def new_opml_export(cls, user_id, count, automated=False): params = { "user_id": user_id, "category": 'opml_export', - 'content': "You exported an OPML backup of your subscriptions" + 'content': f"You exported an OPML backup of {count} subscriptions" } if automated: - params['content'] = "An automatic OPML backup was emailed to you" + params['content'] = f"An automatic OPML backup of {count} subscriptions was emailed to you" cls.objects.create(**params) @classmethod