Skip to content

Commit

Permalink
finished with relation views
Browse files Browse the repository at this point in the history
  • Loading branch information
csae8092 committed Oct 11, 2024
1 parent 02dac94 commit 4116ab7
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
35 changes: 34 additions & 1 deletion apis_core/apis_relations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,39 @@ def get_copy_url(self):


class WorkWork(AbstractRelation):
@classmethod
def get_icon(self):
return "bi bi-book apis-work"

@classmethod
def get_second_icon(self):
return "bi bi-book apis-work"

@classmethod
def get_color(self):
return "#ff8600"

@classmethod
def get_listview_url(self):
return None
return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}")

@classmethod
def get_createview_url(self):
return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}_create")

def get_object_list_view(self):
list_url = self.get_listview_url()
main_id = self.get_related_entity_instancea().id
return f"{list_url}?source={main_id}&sort=-updated"

def get_edit_url(self):
return reverse_lazy(
f"apis:apis_relations:{self.__class__.__name__.lower()}_edit",
kwargs={"pk": self.id},
)

def get_copy_url(self):
return reverse_lazy(
"apis:apis_relations:copy_relation",
kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()},
)
16 changes: 16 additions & 0 deletions apis_core/apis_relations/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from . import institution_event_relation_views
from . import event_event_relation_views
from . import event_work_relation_views
from . import work_work_relation_views
from .views import copy_relation


Expand All @@ -26,6 +27,21 @@
copy_relation,
name="copy_relation",
),
path(
"work-work/",
work_work_relation_views.WorkWorkListView.as_view(),
name="workwork",
),
path(
"work-work/create/",
work_work_relation_views.WorkWorkCreate.as_view(),
name="workwork_create",
),
path(
"work-work/edit/<int:pk>",
work_work_relation_views.WorkWorkUpdate.as_view(),
name="workwork_edit",
),
path(
"event-work/",
event_work_relation_views.EventWorkListView.as_view(),
Expand Down
59 changes: 59 additions & 0 deletions apis_core/apis_relations/work_work_relation_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator

from browsing.browsing_utils import GenericListView, BaseCreateView, BaseUpdateView

from apis_core.apis_vocabularies.models import WorkWorkRelation
from apis_core.apis_relations.models import WorkWork
from apis_core.apis_relations.config import FIELDS_TO_EXCLUDE
from apis_core.apis_relations.utils import (
generate_relation_form,
generate_relation_filter_formhelper,
generate_relation_filter,
generate_relation_table,
)


class WorkWorkCreate(BaseCreateView):

model = WorkWork
form_class = generate_relation_form(WorkWork)

def get_success_url(self):
return self.object.get_object_list_view()

@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(WorkWorkCreate, self).dispatch(*args, **kwargs)


class WorkWorkUpdate(BaseUpdateView):

model = WorkWork
form_class = generate_relation_form(WorkWork)

def get_success_url(self):
return self.object.get_object_list_view()

@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(WorkWorkUpdate, self).dispatch(*args, **kwargs)


class WorkWorkListView(GenericListView):
model = WorkWork
filter_class = generate_relation_filter(WorkWork, WorkWorkRelation)
formhelper_class = generate_relation_filter_formhelper()
table_class = generate_relation_table(WorkWork)
init_columns = [
"start_date_written",
"end_date_written",
"source",
"relation_type",
"target",
"crud",
]
verbose_name = "Werke und Werke"
exclude_columns = FIELDS_TO_EXCLUDE
enable_merge = False
template_name = "apis_relations/list_view.html"
6 changes: 6 additions & 0 deletions templates/partials/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@
Ereignisse und Werke
<i class="bi bi-book apis-work"></i>
</a>
<li><hr class="dropdown-divider"></li>
<a class="dropdown-item" href="{% url 'apis:apis_relations:workwork' %}">
<i class="bi bi-book apis-work"></i>
Werke und Werke
<i class="bi bi-book apis-work"></i>
</a>
</ul>
</li>
{% if user.is_authenticated %}
Expand Down

0 comments on commit 4116ab7

Please sign in to comment.