From: Radek Czajka Date: Thu, 15 Dec 2022 12:04:55 +0000 (+0100) Subject: Book stats in exports. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/a1f86966aff87868cbc419b2d1a55d505aead21d?ds=inline Book stats in exports. --- diff --git a/src/catalogue/admin.py b/src/catalogue/admin.py index e0c4242b..bfa911fb 100644 --- a/src/catalogue/admin.py +++ b/src/catalogue/admin.py @@ -213,7 +213,20 @@ class BookAdmin(WikidataAdminMixin, NumericFilterModelAdmin): "gazeta_link", "estimated_chars", "estimated_verses", - "estimate_source" + "estimate_source", + + "monthly_views_page", + "monthly_views_reader", + + # content stats + "chars", + "chars_with_fn", + "words", + "words_with_fn", + "verses", + "chars_out_verse", + "verses_with_fn", + "chars_out_verse_with_fn", ] )] fieldsets = [ diff --git a/src/catalogue/models.py b/src/catalogue/models.py index 1eb497f0..7a203dd9 100644 --- a/src/catalogue/models.py +++ b/src/catalogue/models.py @@ -315,6 +315,25 @@ class Book(WikidataModel): self.monthly_views_reader = stats['views_reader'] / months self.save(update_fields=['monthly_views_page', 'monthly_views_reader']) + @property + def content_stats(self): + if hasattr(self, '_content_stats'): + return self._content_stats + try: + stats = self.document_books.first().wldocument().get_statistics()['total'] + except Exception as e: + stats = {} + self._content_stats = stats + return stats + + chars = lambda self: self.content_stats.get('chars', '') + chars_with_fn = lambda self: self.content_stats.get('chars_with_fn', '') + words = lambda self: self.content_stats.get('words', '') + words_with_fn = lambda self: self.content_stats.get('words_with_fn', '') + verses = lambda self: self.content_stats.get('verses', '') + verses_with_fn = lambda self: self.content_stats.get('verses_with_fn', '') + chars_out_verse = lambda self: self.content_stats.get('chars_out_verse', '') + chars_out_verse_with_fn = lambda self: self.content_stats.get('chars_out_verse_with_fn', '') class CollectionCategory(models.Model): name = models.CharField(_("name"), max_length=255)