-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
2,548 additions
and
1,348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...e/apis_entities/migrations/0004_alter_event_options_alter_institution_options_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Generated by Django 5.1.1 on 2024-11-23 07:42 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
( | ||
"apis_entities", | ||
"0003_alter_event_options_alter_institution_options_and_more", | ||
), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name="event", | ||
options={ | ||
"ordering": ["-id"], | ||
"verbose_name": "Ereignis", | ||
"verbose_name_plural": "Ereignisse", | ||
}, | ||
), | ||
migrations.AlterModelOptions( | ||
name="institution", | ||
options={ | ||
"ordering": ["-id"], | ||
"verbose_name": "Institution", | ||
"verbose_name_plural": "Institutionen", | ||
}, | ||
), | ||
migrations.AlterModelOptions( | ||
name="person", | ||
options={ | ||
"ordering": ["-id"], | ||
"verbose_name": "Person", | ||
"verbose_name_plural": "Personen", | ||
}, | ||
), | ||
migrations.AlterModelOptions( | ||
name="place", | ||
options={ | ||
"ordering": ["-id"], | ||
"verbose_name": "Ort", | ||
"verbose_name_plural": "Orte", | ||
}, | ||
), | ||
migrations.AlterModelOptions( | ||
name="work", | ||
options={ | ||
"ordering": ["-id"], | ||
"verbose_name": "Werk", | ||
"verbose_name_plural": "Werke", | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.contrib import admin | ||
from network.models import Edge | ||
|
||
|
||
admin.site.register(Edge) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class NetworkConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "network" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import django_filters | ||
from django.core.exceptions import FieldDoesNotExist | ||
from django.db.models import CharField, Q | ||
import django_filters.widgets | ||
|
||
from network.models import Edge | ||
|
||
|
||
def safe_int_conversion(value): | ||
try: | ||
return int(value) | ||
except ValueError: | ||
pass | ||
|
||
|
||
class EdgeListFilter(django_filters.FilterSet): | ||
|
||
node = django_filters.CharFilter( | ||
field_name="source_label", | ||
method="nodes_icontains_filter", | ||
label="Quell- oder Zielknoten", | ||
help_text="Sucht im Label des Ziel, oder des Quellknotens", | ||
) | ||
node_id = django_filters.BaseInFilter( | ||
field_name="source_id", | ||
method="nodes_id_filter", | ||
label="IDs eines oder mehrerer Quell- oder Zielknoten", | ||
help_text="IDs eines oder mehrerer Quell- oder Zielknoten, z.B. '2121,10815'", | ||
widget=django_filters.widgets.CSVWidget(), | ||
) | ||
edge_label = django_filters.AllValuesMultipleFilter() | ||
|
||
class Meta: | ||
model = Edge | ||
fields = "__all__" | ||
|
||
def nodes_icontains_filter(self, queryset, name, value): | ||
return queryset.filter( | ||
Q(source_label__icontains=value) | Q(target_label__icontains=value) | ||
) | ||
|
||
def nodes_id_filter(self, queryset, name, value): | ||
sane_values = [safe_int_conversion(x) for x in value] | ||
return queryset.filter( | ||
Q(source_id__in=sane_values) | Q(target_id__in=sane_values) | ||
) | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
for field_name, filter_obj in self.filters.items(): | ||
try: | ||
model_field = self.Meta.model._meta.get_field(field_name) | ||
self.filters[field_name].label = model_field.verbose_name | ||
self.filters[field_name].help_text = model_field.help_text | ||
except FieldDoesNotExist: | ||
continue | ||
if isinstance(model_field, CharField) and not field_name == "edge_label": | ||
if ( | ||
model_field.choices | ||
): # Keep the default filter logic for choice fields | ||
continue | ||
else: | ||
self.filters[field_name] = django_filters.CharFilter( | ||
field_name=field_name, | ||
lookup_expr="icontains", | ||
help_text=model_field.help_text, | ||
label=model_field.verbose_name, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from crispy_forms.helper import FormHelper | ||
|
||
from crispy_forms.layout import Layout | ||
from crispy_forms.bootstrap import AccordionGroup | ||
from crispy_bootstrap5.bootstrap5 import BS5Accordion | ||
|
||
|
||
class EdgeFilterFormHelper(FormHelper): | ||
def __init__(self, *args, **kwargs): | ||
super(EdgeFilterFormHelper, self).__init__(*args, **kwargs) | ||
self.helper = FormHelper() | ||
self.form_class = "genericFilterForm" | ||
self.form_method = "GET" | ||
self.form_tag = False | ||
self.layout = Layout( | ||
"node", | ||
"node_id", | ||
BS5Accordion( | ||
AccordionGroup( | ||
"Quellknoten", | ||
"source_label", | ||
"source_kind", | ||
), | ||
AccordionGroup( | ||
"Zielknoten", | ||
"target_label", | ||
"target_kind", | ||
), | ||
AccordionGroup( | ||
"Beziehung", | ||
"edge_label", | ||
"edge_kind", | ||
"start_date", | ||
"end_date", | ||
), | ||
), | ||
) |
Oops, something went wrong.