Skip to content

Commit

Permalink
hot fix for event related person filter; removed (hopefully) superflu…
Browse files Browse the repository at this point in the history
…os code for generic relation table
  • Loading branch information
csae8092 committed Nov 5, 2024
1 parent acf8580 commit d77e116
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 81 deletions.
2 changes: 1 addition & 1 deletion apis_core/apis_entities/list_view_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def related_person_filter(self, qs, name, value):
[
value.lookup_expr,
],
EventWorkRelation,
PersonEventRelation,
)
qs = qs.filter(
personevent_set__related_person__name__icontains=value.value,
Expand Down
80 changes: 0 additions & 80 deletions apis_core/apis_relations/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,84 +10,10 @@
generic_render_end_date_written,
generic_render_start_date_written,
)
from apis_core.apis_relations.models import AbstractRelation

empty_text_default = "There are currently no relations"


def get_generic_relation_listview_table(relation_name):
"""
Creates a table class according to the relation class given by the relation_name parameter.
Instantiates corresponding columns which also provide linking to the respectively related entities.
:param relation_name: str : The name of the relation class to be loaded
:return: a django-tables2 Table Class tailored for the respective relation class
"""

# create all variables which save the foreign key fields which are different for each relation class
relation_class = AbstractRelation.get_relation_class_of_name(relation_name)
related_entity_class_name_a = (
relation_class.get_related_entity_classa().__name__.lower()
)
related_entity_class_name_b = (
relation_class.get_related_entity_classb().__name__.lower()
)
related_entity_field_name_a = relation_class.get_related_entity_field_namea()
related_entity_field_name_b = relation_class.get_related_entity_field_nameb()

class GenericRelationListViewTable(tables.Table):
# reuse the logic for ordering and rendering *_date_written
# Important: The names of these class variables must correspond to the column field name,
# e.g. for start_date_written, the methods must be named order_start_date_written and render_start_date_written
order_start_date_written = generic_order_start_date_written
order_end_date_written = generic_order_end_date_written
render_start_date_written = generic_render_start_date_written
render_end_date_written = generic_render_end_date_written

class Meta:
model = relation_class

# the fields list also serves as the defining order of them, as to avoid duplicated definitions
fields = [
related_entity_field_name_a,
related_entity_field_name_b,
"relation_type",
"start_date_written",
"end_date_written",
]
# reuse the list for ordering
sequence = tuple(fields)

# This attrs dictionary I took over from the tables implementation before. No idea if and where it would be needed.
attrs = {"class": "table table-hover table-striped table-condensed"}

def __init__(self, *args, **kwargs):
# LinkColumn objects provied hyperlinking to the related entities
self.base_columns[related_entity_field_name_a] = tables.LinkColumn(
# which url to use:
"apis:apis_entities:generic_entities_detail_view",
args=[
# which entity sub-url to load from:
related_entity_class_name_a,
# which instance identifier to use:
A(related_entity_field_name_a + ".pk"),
],
)

# same as above
self.base_columns[related_entity_field_name_b] = tables.LinkColumn(
"apis:apis_entities:generic_entities_detail_view",
args=[
related_entity_class_name_b,
A(related_entity_field_name_b + ".pk"),
],
)

super().__init__(*args, **kwargs)

return GenericRelationListViewTable


def get_generic_relations_table(
relation_class, entity_instance, detail=None, disable_sort=False
):
Expand Down Expand Up @@ -136,12 +62,6 @@ class RelationTableBase(tables.Table):

# reuse the logic for ordering and rendering *_date_written
# Important: The names of these class variables must correspond to the column field name,
# e.g. for start_date_written, the methods must be named order_start_date_written and render_start_date_written
order_start_date_written = generic_order_start_date_written
order_end_date_written = generic_order_end_date_written
render_start_date_written = generic_render_start_date_written
render_end_date_written = generic_render_end_date_written

if disable_sort:
orderable = disable_sort

Expand Down

0 comments on commit d77e116

Please sign in to comment.