Skip to content

Commit

Permalink
Merge pull request #6 from arthur-schnitzler/main
Browse files Browse the repository at this point in the history
WIP
  • Loading branch information
csae8092 authored Dec 15, 2023
2 parents e2d66a9 + 06f60c3 commit ab6a65d
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 510 deletions.
43 changes: 2 additions & 41 deletions apis_core/apis_entities/detail_views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from django.conf import settings
from django.contrib.auth.mixins import UserPassesTestMixin
from django.db.models import Q
from django.http import HttpResponse, Http404
from django.shortcuts import get_object_or_404
from django.template.loader import select_template
from django.views import View
from django_tables2 import RequestConfig
from django.urls import reverse
from django.shortcuts import redirect

from apis_core.apis_labels.models import Label
Expand All @@ -15,10 +13,8 @@
from apis_core.apis_relations.tables import (
get_generic_relations_table,
LabelTableBase,
) # , EntityDetailViewLabelTable
from apis_core.helper_functions.utils import access_for_all
)
from .models import TempEntityClass, BASE_URI
from .views import get_highlighted_texts


def get_object_from_pk_or_uri(request, pk):
Expand All @@ -45,13 +41,9 @@ def get_object_from_pk_or_uri(request, pk):
return instance


class GenericEntitiesDetailView(UserPassesTestMixin, View):
class GenericEntitiesDetailView(View):
# login_url = '/accounts/login/'

def test_func(self):
access = access_for_all(self, viewtype="detail")
return access

def get(self, request, *args, **kwargs):
entity = kwargs["entity"].lower()
pk = kwargs["pk"]
Expand Down Expand Up @@ -109,7 +101,6 @@ def get(self, request, *args, **kwargs):
)
)
object_lod = Uri.objects.filter(entity=instance)
object_texts, ann_proj_form = get_highlighted_texts(request, instance)
object_labels = Label.objects.filter(temp_entity=instance)
tb_label = LabelTableBase(data=object_labels, prefix=entity.title()[:2] + "L-")
tb_label_open = request.GET.get("PL-page", None)
Expand All @@ -121,26 +112,6 @@ def get(self, request, *args, **kwargs):
"apis_entities/detail_views/entity_detail_generic.html",
]
)
tei = getattr(settings, "APIS_TEI_TEXTS", [])
if tei:
tei = set(tei) & set([x.kind.name for x in instance.text.all()])
ceteicean_css = getattr(settings, "APIS_CETEICEAN_CSS", None)
ceteicean_js = getattr(settings, "APIS_CETEICEAN_JS", None)
openseadragon_js = getattr(settings, "APIS_OSD_JS", None)
openseadragon_img = getattr(settings, "APIS_OSD_IMG_PREFIX", None)
iiif_field = getattr(settings, "APIS_IIIF_WORK_KIND", None)
if iiif_field:
try:
if "{}".format(instance.kind) == "{}".format(iiif_field):
iiif = True
else:
iiif = False
except AttributeError:
iiif = False
else:
iiif = False
iiif_server = getattr(settings, "APIS_IIIF_SERVER", None)
iiif_info_json = instance.name
try:
no_merge_labels = [
x for x in object_labels if not x.label_type.name.startswith("Legacy")
Expand All @@ -153,16 +124,6 @@ def get(self, request, *args, **kwargs):
"right_card": side_bar,
"no_merge_labels": no_merge_labels,
"object_lables": object_labels,
"object_texts": object_texts,
"object_lod": object_lod,
"tei": tei,
"ceteicean_css": ceteicean_css,
"ceteicean_js": ceteicean_js,
"iiif": iiif,
"openseadragon_js": openseadragon_js,
"openseadragon_img": openseadragon_img,
"iiif_field": iiif_field,
"iiif_info_json": iiif_info_json,
"iiif_server": iiif_server,
}
return HttpResponse(template.render(request=request, context=context))

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{% extends "apis_entities/detail_views/entity_detail_generic.html" %}
{% block Titel %} {{ object.id }} {% endblock %}


{% block info-table %}
<table class="table table-bordered table-hover">
<table class="table">
<tr>
<th>
Name
Expand All @@ -12,18 +10,21 @@
{{ object.name }}, {{ object.first_name }}
</td>
</tr>
{% if no_merge_labels %}
<tr>
<th>
Alternative Names
Alternative Namen
</th>
<td>
{% for x in no_merge_labels %}
<li>
<li class="list-unstyled">
<small>{{ x.label_type }}: </small>{{ x.label }}
</li>
{% endfor %}

</td>
</tr>
{% endif %}
<tr>
<th>
ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
<script src="https://unpkg.com/[email protected]"></script>
{% load django_tables2 %}
{% load crispy_forms_tags %}
<style>

</style>
<style>
a {
color: var(--{{ entity_type }});
Expand Down
23 changes: 0 additions & 23 deletions apis_core/apis_labels/forms.py

This file was deleted.

38 changes: 0 additions & 38 deletions apis_core/apis_labels/templates/apis_labels/label_create.html

This file was deleted.

33 changes: 0 additions & 33 deletions apis_core/apis_labels/templates/apis_labels/labels_list.html

This file was deleted.

5 changes: 1 addition & 4 deletions apis_core/apis_labels/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@
app_name = "apis_labels"

urlpatterns = [
path("list/", views.LabelListView.as_view(), name="label_list"),
path("create/", views.label_create, name="label_create"),
path("edit/<int:pk>", views.label_edit, name="label_edit"),
path("delete/<int:pk>", views.LabelDelete.as_view(), name="label_delete"),
path("delete-from-tabel/<int:label_id>/", views.delete_label, name="label_delete"),
]
62 changes: 9 additions & 53 deletions apis_core/apis_labels/views.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,13 @@
from django.shortcuts import render, redirect, get_object_or_404
from django.urls import reverse_lazy
from django.views import generic
from django.views.generic.edit import DeleteView
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse

from .forms import LabelForm
from .models import Label


class LabelListView(generic.ListView):
model = Label
template_name = "apis_labels/labels_list.html"
context_object_name = "object_list"

def get_queryset(self):
return Label.objects.order_by("label")


def label_create(request):
if request.method == "POST":
form = LabelForm(request.POST)
if form.is_valid():
form.save()
return redirect("apis_labels:label_list")
else:
return render(request, "apis_labels/label_create.html", {"form": form})
else:
form = LabelForm()
return render(request, "apis_labels/label_create.html", {"form": form})


def label_edit(request, pk):
instance = get_object_or_404(Label, pk=pk)
if request.method == "POST":
form = LabelForm(request.POST, instance=instance)
if form.is_valid():
form.save()
return redirect("apis_labels:label_list")
else:
return render(
request,
"apis_labels/label_create.html",
{"form": form, "instance": instance},
)
else:
form = LabelForm(instance=instance)
return render(
request,
"apis_labels/label_create.html",
{"form": form, "instance": instance},
)
from .models import Label


class LabelDelete(DeleteView):
model = Label
template_name = "apis_templates/confirm_delete.html"
success_url = reverse_lazy("apis_labels:label_list")
@login_required
def delete_label(request, label_id):
instance = Label.objects.get(id=label_id)
label = f"{instance}"
instance.delete()
return HttpResponse(f"<small>gelöschtes Label: {label}</small> ")
Empty file.
6 changes: 3 additions & 3 deletions apis_core/apis_relations/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Meta:

# 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",
"class": "table table-hover table-condensed",
"id": related_entity_class_name_a.title()[:2]
+ related_entity_class_name_b.title()[:2]
+ "_conn",
Expand Down Expand Up @@ -338,7 +338,7 @@ class Meta:
sequence = ("delete", "uri")
# add class="paleblue" to <table> tag
attrs = {
"class": "table table-hover table-striped table-condensed",
"class": "table table-hover table-condensed",
"id": "PURI_conn",
}

Expand Down Expand Up @@ -372,7 +372,7 @@ class Meta:

# add class="paleblue" to <table> tag
attrs = {
"class": "table table-hover table-striped table-condensed",
"class": "table table-hover table-condensed",
"id": "PL_conn",
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
title="Verbindung löschen"
hx-get="/apis/relations/delete/{{ record.pk }}/"
hx-target="closest tr" hx-swap="outerHTML swap:1s"
hx-confirm="Sicher, weil was weg ist ist weg"
hx-confirm="Sicher? Weil was weg ist ist weg"
>
<i class="bi bi-trash"></i>
</button>
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
<a
class="btn"
hx-trigger="click"
hx-post="/apis/relations/ajax/get/"
hx-target="#editFormDiv_PersonLabel"
hx-vals='{
"FormName": "PersonLabelForm",
"SiteID": "{{ record.temp_entity.id }}",
"ObjectID": "{{ record.pk }}",
"entity_type": "{{ entity_type }}",
"ButtonText": "speichern"
}'>
<i class="bi bi bi-trash" title="Label: '{{ record }}' bearbeiten"> </i>
hx-post="/apis/labels/delete-from-tabel/{{ record.pk }}/"
hx-confirm="Sicher? Weil was weg ist ist weg"
hx-target="closest tr" hx-swap="outerHTML swap:1s"
>
<i class="bi bi bi-trash" title="Label: '{{ record }}' löschen"> </i>
</a>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"FormName": "PersonLabelForm",
"SiteID": "{{ record.temp_entity.id }}",
"ObjectID": "{{ record.pk }}",
"entity_type": "{{ entity_type }}",
"entity_type": "{{ record.temp_entity.get_child_class|lower }}",
"ButtonText": "speichern"
}'>
<i class="bi bi-pencil-square" title="Label: '{{ record }}' bearbeiten"> </i>
Expand Down
2 changes: 2 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<!DOCTYPE html>
<html lang="en" class="h-100" >
<meta charset="utf-8">
<title>{% block title %}PMB{% endblock %}</title>

<head>
{% include "partials/head.html" %}
Expand Down
2 changes: 0 additions & 2 deletions templates/partials/head.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{% load static %}
<meta charset="utf-8">
<title>{% block title %}PMB{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
{% block metaDescription %}
{% endblock %}
Expand Down

0 comments on commit ab6a65d

Please sign in to comment.