Files
Cedar-Django/closedverse_main/serializers.py
T
some weird guy ef1396fe03 CVS merge
Yet even more code merged.
2023-08-02 02:04:18 -04:00

37 lines
1005 B
Python

import json
class CommunitySerializer():
"""
Serializes communities for use with JSON
"""
@staticmethod
def single(community):
"""
Return one dict for a community, meant to be used in community pages, etc
"""
return {
'id': community.id,
'unique_id': str(community.unique_id),
'name': community.name,
'icon': (community.icon() or None),
'banner': (community.banner or None),
'description': community.description,
'type': community.type,
'platform': community.platform,
'allowed_users': json.loads(community.allowed_users) if community.allowed_users else None,
'creator': community.creator_id
}
@staticmethod
def many(queryset):
"""
Return a community meant to be used in a bigger list, etc
"""
return [
{
'id': community.id,
'name': community.name,
'icon': (community.icon() or None),
'banner': (community.banner or None),
'type': community.type,
'platform': community.platform
} for community in queryset
]