Skip to content

Commit

Permalink
fix(form): move some texts outside of form, other attributes to details
Browse files Browse the repository at this point in the history
Closes: #116
  • Loading branch information
b1rger committed Feb 12, 2024
1 parent a0fde72 commit 443e33d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions apis_ontology/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
from crispy_forms.layout import Layout, HTML
from apis_core.generic.forms import GenericModelForm

TEXTTYPE_CHOICES_MAIN = ["ÖBL Haupttext", "ÖBL Werkverzeichnis"]


class LegacyStuffMixinForm(GenericModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

text_details = Layout(HTML("<details><summary>Texts</summary>"))
more_details = Layout(HTML("<details><summary>More details</summary>"))
for ttypenr, ttype in Text.TEXTTYPE_CHOICES:
self.fields[ttype] = CharField(required=False, widget=Textarea)
if instance := kwargs.get("instance"):
Expand All @@ -17,11 +19,13 @@ def __init__(self, *args, **kwargs):
self.fields[ttype].initial = text.text
except Text.DoesNotExist:
pass
text_details.append(ttype)
text_details.append(HTML("</details>"))
if ttype not in TEXTTYPE_CHOICES_MAIN:
more_details.append(ttype)
more_details.extend(["notes", "status", "review", "published"])
more_details.append(HTML("</details>"))

all_other_fields = [f for f in self.fields if f not in text_details]
self.helper.layout = Layout(*all_other_fields, text_details)
all_other_fields = [f for f in self.fields if f not in more_details]
self.helper.layout = Layout(*all_other_fields, more_details)

def save(self, *args, **kwargs):
obj = super().save(*args, **kwargs)
Expand Down

0 comments on commit 443e33d

Please sign in to comment.