Skip to content

Commit

Permalink
feat(core): Add a icon serializer field.
Browse files Browse the repository at this point in the history
ref: #345 #346
  • Loading branch information
jon-nfc committed Oct 12, 2024
1 parent 370427b commit 6f01068
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/core/classes/icon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@



class Icon:

name: str

style:str


def __init__(self,
name: str = None,
style: str = None,
url: str = None
):

self.name = name

self.style = style

self.url = url

@property
def to_json(self):

return {
'name': self.name,
'style': self.style
}
36 changes: 36 additions & 0 deletions app/core/fields/icon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from rest_framework import serializers
from rest_framework.fields import empty

from core.classes.icon import Icon



class IconField(serializers.Field):

source = ''

label = ''

def __init__(self, *, read_only=True, write_only=False,
required=None, default=empty, initial=empty, source=None,
label=None, help_text=None, style=None,
error_messages=None, validators=None, allow_null=False):

super().__init__(read_only=read_only, write_only=write_only,
required=required, default=default, initial=initial, source=source,
label=label, help_text=help_text, style=style,
error_messages=error_messages, validators=validators, allow_null=allow_null)

def to_representation(self, icons: list([Icon])):

a_icons: list = []

for icon in icons:

a_icons += [ icon.to_json ]

return a_icons


def to_internal_value(self, data):
return Icon(data.icon,data.icon_style, data.url)

0 comments on commit 6f01068

Please sign in to comment.