From c0a7686f32ec8e354fddd380f84547f5125a4ab6 Mon Sep 17 00:00:00 2001 From: frimpongopoku Date: Thu, 12 Oct 2023 07:15:30 +0000 Subject: [PATCH] more on count & documentation --- src/api/store/media_library.py | 14 +++++--------- src/database/models.py | 27 ++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/api/store/media_library.py b/src/api/store/media_library.py index 78678e563..3f768b928 100644 --- a/src/api/store/media_library.py +++ b/src/api/store/media_library.py @@ -204,9 +204,8 @@ def get_most_recent(self, args, context: Context): else: query |= qObj - count = 0 + count = Media.objects.filter(query).distinct().count() if not upper_limit and not lower_limit: - count = Media.objects.filter(query).distinct().count() images = Media.objects.filter(query).distinct().order_by("-id")[:limit] else: images = ( @@ -220,11 +219,10 @@ def get_most_recent(self, args, context: Context): def get_public_images(self, args): upper_limit = args.get("upper_limit") lower_limit = args.get("lower_limit") - count = 0 - if not upper_limit and not lower_limit: - count = Media.objects.filter( + count = Media.objects.filter( user_upload__publicity=UserMediaConstants.open() ).count() + if not upper_limit and not lower_limit: images = Media.objects.filter( user_upload__publicity=UserMediaConstants.open() ).order_by("-id")[:limit] @@ -289,9 +287,8 @@ def get_by_keywords(self, args): else: query |= queryObj - count = 0 + count = Media.objects.filter(query).distinct().count() if not upper_limit and not lower_limit: - count = Media.objects.filter(query).distinct().count() images = Media.objects.filter(query).distinct().order_by("-id")[:limit] else: images = ( @@ -308,7 +305,7 @@ def get_uploads_by_user(self, args): upper_limit = args.get("upper_limit") lower_limit = args.get("lower_limit") query = Q(user_upload__user__id__in=user_ids) - count = 0 + count = Media.objects.filter(query).count() if upper_limit and lower_limit: images = ( Media.objects.filter(query) @@ -316,7 +313,6 @@ def get_uploads_by_user(self, args): .order_by("-id")[:limit] ) else: - count = Media.objects.filter(query).count() images = Media.objects.filter(query).order_by("-id")[:limit] return images, {"total": count}, None diff --git a/src/database/models.py b/src/database/models.py index d89951054..9cb0cf98b 100644 --- a/src/database/models.py +++ b/src/database/models.py @@ -1171,7 +1171,32 @@ class Meta: class UserMediaUpload(models.Model): - """A class that creates a relationship between a user(all user kinds) on the platform and media they have uploaded""" + """A class that creates a relationship between a user(all user kinds) on the platform and media they have uploaded + + Attributes + ---------- + user : UserProfile + A user profile object of the currently signed in user who uploaded the media + + communities: Community + All communities that have access to the attached media object + + media : Media + A reference to the actual media object + + is_universal: bool + True/False value that indicates whether or not an image is open to everyone. + PS: Its no longer being used (as at 12/10/23). We want more than two states, so we now use "publicity" + + publicity: str + This value is used to determine whether or not an upload is OPEN_TO specific communities, CLOSED_TO, or wide open to any communities check UserMediaConstants for all the available options + + info: JSON + Json field that stores very important information about the attached media. Example: has_copyright_permission,copyright_att,guardian_info,size etc. + + settings: JSON + Just another field to store more information about the media (I dont think we use this...) + """ id = models.AutoField(primary_key=True) user = models.ForeignKey(