Skip to content

Commit

Permalink
more on count & documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
frimpongopoku committed Oct 12, 2023
1 parent a0b7e3d commit c0a7686
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
14 changes: 5 additions & 9 deletions src/api/store/media_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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]
Expand Down Expand Up @@ -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 = (
Expand All @@ -308,15 +305,14 @@ 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)
.exclude(id__gte=lower_limit, id__lte=upper_limit)
.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
Expand Down
27 changes: 26 additions & 1 deletion src/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c0a7686

Please sign in to comment.