Skip to content

Commit

Permalink
implements dependent dropdown for yearbook and their articles (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
csae8092 authored Jul 8, 2024
1 parent 749a40c commit 15db117
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 17 deletions.
21 changes: 13 additions & 8 deletions archiv/dal_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
path(
"person-autocomplete", dal_views.PersonAC.as_view(), name="person-autocomplete"
),
path(
"tag-autocomplete",
dal_views.TagAC.as_view(create_field="tag", validate_create=True),
name="tag-autocomplete",
),
path(
"tag-filter-autocomplete",
dal_views.TagAC.as_view(),
name="tag-no-filter-autocomplete",
),
path(
"yearbook-autocomplete",
dal_views.YearBookAC.as_view(),
Expand All @@ -35,13 +45,8 @@
name="monograph-autocomplete",
),
path(
"tag-autocomplete",
dal_views.TagAC.as_view(create_field="tag", validate_create=True),
name="tag-autocomplete",
),
path(
"tag-filter-autocomplete",
dal_views.TagAC.as_view(),
name="tag-no-filter-autocomplete",
"chapter-autocomplete",
dal_views.ChapterAC.as_view(),
name="chapter-autocomplete",
),
]
13 changes: 11 additions & 2 deletions archiv/dal_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ def get_queryset(self):
return qs


class ChapterAC(autocomplete.Select2QuerySetView):
def get_queryset(self):
qs = YearBook.objects.all()
constraint = self.forwarded.get("year_book_title", None)
if constraint:
qs = qs.filter(part_of=constraint[0])
if self.q:
qs = qs.filter(Q(title__icontains=self.q) | Q(id__icontains=self.q))
return qs


class CourtAC(autocomplete.Select2QuerySetView):
def get_result_label(self, item):
return f"{item.name} ({item.name_english}) {item.abbreviation}"
Expand Down Expand Up @@ -86,8 +97,6 @@ class PersonAC(autocomplete.Select2QuerySetView):
def get_queryset(self):
qs = Person.objects.all()
constraint = self.forwarded.get("partial_legal_system", None)
print("############")
print(constraint)
if constraint:
qs = qs.filter(legal_system__in=[int(x) for x in constraint])
if self.q:
Expand Down
21 changes: 16 additions & 5 deletions archiv/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,21 @@ class CourtDecissionListFilter(django_filters.FilterSet):
help_text=FT_HELPTEXT,
)
year_book_title = django_filters.ModelMultipleChoiceFilter(
field_name="year_book_title__part_of",
queryset=YearBook.objects.all(),
help_text=CourtDecission._meta.get_field("year_book_title").help_text,
label=CourtDecission._meta.get_field("year_book_title").verbose_name,
label="Yearbook",
help_text="List all cases discussed in the selected yearbook",
widget=autocomplete.Select2Multiple(
url="archiv-ac:yearbook-autocomplete",
url="archiv-ac:monograph-autocomplete",
),
)
year_book_chapter = django_filters.ModelMultipleChoiceFilter(
field_name="year_book_title",
queryset=YearBook.objects.all(),
label="Article",
help_text="Lists all cases discussed in the selected article.",
widget=autocomplete.Select2Multiple(
url="archiv-ac:chapter-autocomplete", forward=["year_book_title"]
),
)
tag = django_filters.ModelMultipleChoiceFilter(
Expand Down Expand Up @@ -176,14 +186,14 @@ class CourtDecissionListFilter(django_filters.FilterSet):
queryset=KeyWord.objects.all(),
help_text=CourtDecission._meta.get_field("keyword").help_text,
label=CourtDecission._meta.get_field("keyword").verbose_name,
widget=autocomplete.Select2Multiple(
widget=autocomplete.ModelSelect2Multiple(
url="archiv-ac:keyword-autocomplete", attrs={"data-html": True}
),
)
author = django_filters.ModelMultipleChoiceFilter(
queryset=Person.objects.all(),
help_text=CourtDecission._meta.get_field("author").help_text,
label=CourtDecission._meta.get_field("author").verbose_name,
help_text="Lists all cases related to articles written by the selected author.",
widget=autocomplete.Select2Multiple(
url="archiv-ac:person-autocomplete", forward=["partial_legal_system"]
),
Expand Down Expand Up @@ -258,6 +268,7 @@ class Meta:
"tag",
"author",
"year_book_title",
"year_book_chapter",
]


Expand Down
1 change: 1 addition & 0 deletions archiv/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def __init__(self, *args, **kwargs):
"id",
"ecli",
"year_book_title",
"year_book_chapter",
"author",
css_id="extended",
),
Expand Down
2 changes: 1 addition & 1 deletion archiv/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ class KeyWord(models.Model):
linked_to_cases = models.BooleanField(
default=True,
verbose_name="can be linked to cases",
help_text="can be linked to cases"
help_text="can be linked to cases",
)

class Meta:
Expand Down
4 changes: 3 additions & 1 deletion webpage/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def get_context_data(self, **kwargs):
if r.status_code == 200:
context["imprint_body"] = "{}".format(r.text)
else:
context["imprint_body"] = """
context[
"imprint_body"
] = """
On of our services is currently not available.\
Please try it later or write an email to\
[email protected]; if you are service provide,\
Expand Down

0 comments on commit 15db117

Please sign in to comment.