Coverage for src/django_resume/plugins/skills.py: 67%

1 import json

2

3 from django import forms

4

5 from .base import SimplePlugin, SimpleTemplates

6

7

8 class SkillsForm(forms.Form):

9 initial_badges = ["Some Skill", "Another Skill"]

10 badges = forms.JSONField(

11 label="Skills", max_length=1024, required=False, initial=initial_badges

12 )

13

14 def badges_as_json(self):

15 """

16 Return the initial badges which should already be a normal list of strings

17 or the initial_badged list for the first render of the form encoded as json.

18 """

19 existing_badges = self.initial.get("badges")

20 if existing_badges is not None:

21 return json.dumps(existing_badges)

22 return json.dumps(self.initial_badges)

23

24

25 class SkillsPlugin(SimplePlugin):

26 name: str = "skills"

27 verbose_name: str = "Skills"

28 templates = SimpleTemplates(

29 main="django_resume/skills/plain/content.html",

30 form="django_resume/skills/plain/form.html",

31 )

32 admin_form_class = inline_form_class = SkillsForm