The first steps or whatever

balls
This commit is contained in:
some weird guy
2023-02-08 18:33:16 -08:00
parent ce4cb37a41
commit ecd8d3b1b7
214 changed files with 22899 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
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
]