Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1756 | user summary to have bookmark count
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Feb 6, 2024
1 parent 5b55dba commit 7b70153
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions core/common/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,10 @@ def get_object_from_namespace(namespace):

return None

@property
def bookmarks_count(self):
return self.pins.count()

@property
def sources(self):
return self.source_set.filter(version=HEAD)
Expand Down
6 changes: 4 additions & 2 deletions core/users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ class UserSummarySerializer(serializers.ModelSerializer):
sources = IntegerField(source='public_sources')
collections = IntegerField(source='public_collections')
organizations = IntegerField(source='orgs_count')
bookmarks = IntegerField(source='bookmarks_count')

class Meta:
model = UserProfile
fields = (
'username', 'name', 'url', 'logo_url', 'sources', 'collections', 'organizations',
'is_superuser', 'is_staff', 'first_name', 'last_name', 'status'
'is_superuser', 'is_staff', 'first_name', 'last_name', 'status', 'bookmarks'
)


Expand Down Expand Up @@ -137,6 +138,7 @@ class UserDetailSerializer(AbstractResourceSerializer):
orgs = serializers.IntegerField(read_only=True, source='orgs_count')
owned_orgs = serializers.IntegerField(read_only=True, source='owned_orgs_count')
sources = serializers.IntegerField(read_only=True, source='all_sources_count')
bookmarks = serializers.IntegerField(read_only=True, source='bookmarks_count')
collections = serializers.IntegerField(read_only=True, source='all_collections_count')
created_on = serializers.DateTimeField(source='created_at', read_only=True)
updated_on = serializers.DateTimeField(source='updated_at', read_only=True)
Expand All @@ -155,7 +157,7 @@ class Meta:
'url', 'organizations_url', 'extras', 'sources_url', 'collections_url', 'website', 'last_login',
'logo_url', 'subscribed_orgs', 'is_superuser', 'is_staff', 'first_name', 'last_name', 'verified',
'verification_token', 'date_joined', 'auth_groups', 'status', 'deactivated_at',
'sources', 'collections', 'owned_orgs'
'sources', 'collections', 'owned_orgs', 'bookmarks'
)

def __init__(self, *args, **kwargs):
Expand Down

0 comments on commit 7b70153

Please sign in to comment.