mirror of
https://github.com/Mistake35/Cedar-Django.git
synced 2026-07-17 16:11:14 +10:00
37 lines
1014 B
Python
37 lines
1014 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
|
|
] |