Skip to content

Commit

Permalink
refactor(forms): make language field DRY
Browse files Browse the repository at this point in the history
Use separate class for language form field to
avoid redundancy.
  • Loading branch information
koeaw committed Aug 13, 2024
1 parent d77f295 commit 37a8afe
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions apis_ontology/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
from apis_core.generic.forms import GenericModelForm
from django import forms

from .models import Character, Expression, Work
from .models import Character, Expression, LanguageMixin, Work


logger = logging.getLogger(__name__)


class WorkForm(GenericModelForm):
class LanguageForm(forms.Form):
language = forms.MultipleChoiceField(
required=False,
choices=LanguageMixin.LanguagesIso6393.choices,
label=LanguageMixin._meta.get_field("language").verbose_name,
)


class WorkForm(GenericModelForm, LanguageForm):
temporal_order = forms.MultipleChoiceField(
required=False,
choices=Work.TemporalOrder.choices,
Expand Down Expand Up @@ -60,24 +68,14 @@ class WorkForm(GenericModelForm):
choices=Work.NarrativeVoice.choices,
label=Work._meta.get_field("narrative_voice").verbose_name,
)
language = forms.MultipleChoiceField(
required=False,
choices=Expression.LanguagesIso6393.choices,
label=Expression._meta.get_field("language").verbose_name,
)


class ExpressionForm(GenericModelForm):
class ExpressionForm(GenericModelForm, LanguageForm):
new_edition_type = forms.MultipleChoiceField(
required=False,
choices=Expression.EditionTypes.choices,
label=Expression._meta.get_field("new_edition_type").verbose_name,
)
language = forms.MultipleChoiceField(
required=False,
choices=Expression.LanguagesIso6393.choices,
label=Expression._meta.get_field("language").verbose_name,
)


class CharacterForm(GenericModelForm):
Expand Down

0 comments on commit 37a8afe

Please sign in to comment.