Skip to content

Commit

Permalink
chore: more work on getting detail view working
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-nfc committed Oct 4, 2024
1 parent 0ebef6b commit 847ae34
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 34 deletions.
24 changes: 4 additions & 20 deletions app/api/v2/serializers/itam/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,7 @@
# from api.v2.serializers.itim.service import BaseSerializer as ServiceBaseSerializer

from itam.models.device import Device


class Badge:

icon = 'x'

colour = 'x'

url = 'y'

def __init__(self, icon = 'x', colour = 'y', url = 'z'):

self.icon = icon

self.colour = colour

self.url = url
from core.classes.badge import Badge


class BadgeField(serializers.Field):
Expand All @@ -52,9 +36,9 @@ def __init__(self, *, read_only=True, write_only=False,
def to_representation(self, value):
return {
'icon': value.icon,
'colour': value.colour,
'action_id': self.root.instance.action,
'text': self.root.instance.get_action_display(),
'icon_style': value.icon_style,
'text': value.text,
'text_style': value.text_style,
'url': value.url,
}

Expand Down
14 changes: 8 additions & 6 deletions app/api/v2/serializers/itam/device_software.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ def get_url(self, obj):
}


def tester(self):
action_badge = BadgeField(default=Badge('a','b','_self'), label='Action')

return {
'a': 'a',
'b':'b'
}
action = BadgeField(default=Badge('a','b','_self'), label='Action', source='self')
# def tester(self):

# return {
# 'a': 'a',
# 'b':'b'
# }

class Meta:

Expand All @@ -77,6 +78,7 @@ class Meta:
'software',
'category',
'action',
'action_badge',
'version',
'installedversion',
'installed',
Expand Down
10 changes: 4 additions & 6 deletions app/api/v2/views/itam/device_software.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ def get_serializer_class(self):

if (
self.action == 'list'
or self.action == 'retrieve'
# or self.action == 'retrieve'
):

self.serializer_class = ViewSerializer
return ViewSerializer

else:
return ModelSerializer

self.serializer_class = ModelSerializer

return self.serializer_class
# return self.serializer_class


def get_serializer_context(self):
Expand Down
3 changes: 2 additions & 1 deletion app/api/v2/views/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def determine_metadata(self, request, view):

if view.suffix == 'Instance':

metadata['layout'] = view.queryset.model.page_layout
if hasattr(view.queryset.model, 'page_layout'):
metadata['layout'] = view.queryset.model.page_layout

metadata['actions']['PUT'] = self.field_choices(metadata['actions']['PUT'])

Expand Down
33 changes: 33 additions & 0 deletions app/core/classes/badge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@



class Badge:

icon: str

icon_style:str

text: str

text_style:str

url:str


def __init__(self,
icon: str = None,
icon_style: str = None,
text: str = None,
text_style: str = None,
url: str = None
):

self.icon = icon

self.icon_style = icon_style

self.text = text

self.text_style = text_style

self.url = url
23 changes: 22 additions & 1 deletion app/itam/models/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,34 @@ class Actions(models.TextChoices):
"nbsp",
"software",
"category",
"action",
"action_badge",
"version",
"installedversion",
"installed",
"nbsp"
]


@property
def action_badge(self):

from core.classes.badge import Badge

text:str = 'Add'

if self.action:

text = self.get_action_display()

return Badge(
icon= f'action_{text.lower()}',
icon_style = f'badge-icon-action-{text.lower()}',
text = text,
text_style = f'badge-text-action-{text.lower()}',
url = '_self',
)


@property
def category(self):

Expand Down

0 comments on commit 847ae34

Please sign in to comment.