diff --git a/apis_core/api_routers.py b/apis_core/api_routers.py index 5668641..8c5e82f 100644 --- a/apis_core/api_routers.py +++ b/apis_core/api_routers.py @@ -27,10 +27,10 @@ def deep_get(dictionary, keys, default=None): ) -def create_query_parameters(entity): - print(entity) - for f in entity._meta.fields: - print(f.name, f.__class__.__name__) +# def create_query_parameters(entity): +# print(entity) +# for f in entity._meta.fields: +# print(f.name, f.__class__.__name__) class CustomPagination(pagination.LimitOffsetPagination): diff --git a/apis_core/apis_entities/custom_authentication.py b/apis_core/apis_entities/custom_authentication.py deleted file mode 100644 index 37cb527..0000000 --- a/apis_core/apis_entities/custom_authentication.py +++ /dev/null @@ -1,19 +0,0 @@ -from rest_framework.authentication import TokenAuthentication - - -class TokenAuthSupportQueryString(TokenAuthentication): - """ - Extend the TokenAuthentication class to support querystring authentication - in the form of "http://www.example.com/?auth_token=" - """ - - def authenticate(self, request): - # Check if 'token_auth' is in the request query params. - # Give precedence to 'Authorization' header. - if ( - "api_key" in request.query_params - and "HTTP_AUTHORIZATION" not in request.META - ): - return self.authenticate_credentials(request.query_params.get("api_key")) - else: - return super(TokenAuthSupportQueryString, self).authenticate(request) diff --git a/apis_core/apis_entities/tables.py b/apis_core/apis_entities/tables.py deleted file mode 100644 index b81de18..0000000 --- a/apis_core/apis_entities/tables.py +++ /dev/null @@ -1,117 +0,0 @@ -import django_tables2 as tables -from django.utils.safestring import mark_safe -from django_tables2.utils import A -from django.conf import settings - -from apis_core.apis_entities.models import AbstractEntity -from apis_core.apis_entities.models import Person -from apis_core.apis_metainfo.tables import ( - generic_order_start_date_written, - generic_order_end_date_written, - generic_render_start_date_written, - generic_render_end_date_written, -) - - -input_form = """ - | - -""" - - -class PersonTable(tables.Table): - id = tables.LinkColumn() - - class Meta: - model = Person - sequence = ("id",) - attrs = {"class": "table table-responsive table-hover"} - - -class MergeColumn(tables.Column): - """renders a column with to checkbox - used to select objects for merging""" - - def __init__(self, *args, **kwargs): - super(MergeColumn, self).__init__(*args, **kwargs) - - def render(self, value): - return mark_safe(input_form.format(value, value)) - - -def get_entities_table(entity, edit_v, default_cols): - - if default_cols is None: - default_cols = [ - "name", - ] - - class GenericEntitiesTable(tables.Table): - def render_name(self, record, value): - if value == "": - return "(No name provided)" - else: - return value - - # 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 edit_v: - name = tables.LinkColumn( - "apis:apis_entities:generic_entities_edit_view", - args=[entity.lower(), A("pk")], - empty_values=[], - ) - else: - name = tables.LinkColumn( - "apis:apis_entities:generic_entities_detail_view", - args=[entity.lower(), A("pk")], - empty_values=[], - ) - export_formats = [ - "csv", - "json", - "xls", - "xlsx", - ] - if "merge" in default_cols: - merge = MergeColumn(verbose_name="keep | remove", accessor="pk") - if "id" in default_cols: - id = tables.LinkColumn() - - class Meta: - model = AbstractEntity.get_entity_class_of_name(entity_name=entity) - - fields = default_cols - attrs = {"class": "table table-hover table-striped table-condensed"} - - # quick ensurance if column is indeed a field of this entity - for col in default_cols: - if not hasattr(model, col): - raise Exception( - f"Could not find field in entity: {entity}\n" - f"of column (probably defined in 'table_fields' settings): {col}\n" - ) - - def __init__(self, *args, **kwargs): - if "apis_ampel" in settings.INSTALLED_APPS: - from apis_ampel.helper_functions import is_ampel_active - - # as_instance = AmpelSettings.objects.get(content_type=ContentType.objects.get(model=entity)) - if is_ampel_active(entity): - self.base_columns["ampel"] = tables.TemplateColumn( - template_name="ampel/ampel_template_column.html", - verbose_name="Ampel", - ) # todo: make the verbose name configurable? - - #'
', verbose_name="Ampel" - - # template_name = "ampel/ampel_template_column.html", verbose_name="Ampel" #todo: make the verbose name configurable? - - super().__init__(*args, **kwargs) - - return GenericEntitiesTable diff --git a/apis_core/apis_entities/templates/apis_entities/apis_create_entities.html b/apis_core/apis_entities/templates/apis_entities/apis_create_entities.html deleted file mode 100644 index 6009bbd..0000000 --- a/apis_core/apis_entities/templates/apis_entities/apis_create_entities.html +++ /dev/null @@ -1,9 +0,0 @@ -{% load django_tables2 crispy_forms_tags %} -
-
-

Import new {{ entity|title }} from GND

-
-
- {% crispy entity_create_stanbol entity_create_stanbol.helper %} -
-
diff --git a/apis_core/apis_entities/templates/apis_entities/compare_base.html b/apis_core/apis_entities/templates/apis_entities/compare_base.html deleted file mode 100644 index 544dc29..0000000 --- a/apis_core/apis_entities/templates/apis_entities/compare_base.html +++ /dev/null @@ -1,16 +0,0 @@ - - -{% include "reversion-compare/action_list_partial.html" %} -{% if request.GET.version_id1 %} - {% include "reversion-compare/compare_partial.html" %} - {% include "reversion-compare/compare_links_partial.html" %} -{% endif %} \ No newline at end of file diff --git a/apis_core/apis_entities/templates/apis_entities/entity_create_generic.html b/apis_core/apis_entities/templates/apis_entities/entity_create_generic.html deleted file mode 100644 index a625374..0000000 --- a/apis_core/apis_entities/templates/apis_entities/entity_create_generic.html +++ /dev/null @@ -1,388 +0,0 @@ -{% extends "webpage/base.html" %} -{% load static %} -{% block scriptHeader %} -{{block.super}} -{% if highlighter_active %} - - - {% endif %} - {% if apis_bibsonomy %} -{% include 'apis_bibsonomy/apis_bibsonomy_include.html' %} - {% endif %} -{% endblock %} -{% block Titel %}Create a {{entity_type|title}}{% endblock %} -{% load guardian_tags %} -{% load static %} - -{% block content %} -{% load django_tables2 %} -{% if instance %} -
-
-
-

- {{ entity_type }}s - - {{ instance }} - - - - - - {% if "apis_ampel" in APPS and show_ampel %} - {% include "ampel/ampel_inline_template.html" with instance=instance %} - {% endif %} -

-
-
-
-
- {% endif %} - {% load crispy_forms_tags %} -
-
- {% if instance %} -

- Edit the Entity -

- {% else %} -

- create new object type: {{ entity_type|title }} -

- {% endif %} -
-
-
- {% if apis_bibsonomy %} - - {% endif %} -
- - {% crispy form %} - - -
-
- {% block texts %} - {% crispy form_text %} - {% endblock %} -
-
- {% block linkedOpenData %} - {% if object_lod %} -
- -
-
-

{% for lod in object_lod %}{% if forloop.last %}{{ lod.uri }}{% else %}{{ lod.uri }}
{% endif %}{% endfor %}

-
-
-
- {% endif %} - {% endblock %} - {% block editbuttons %} - {% if instance %} - {% if "change" in permissions %} - - {% endif %} - {% if instance %} - - {% endif %} - {% if "delete" in permissions %} - Delete - {% endif %} - - Create new {{entity_type|title}} - {% else %} - {% if "create" in permissions %} - - {% endif %} - {% endif %} - - {% endblock editbuttons %} -
-
-
- {% if instance %} -
-
- {% endif %} - {% if instance %} -
-
-
-

the Entity is related to

-
-
-
- {% block additional_accordion %} - {% endblock additional_accordion %} - {% for obj in right_card %} -
- -
-
- {% render_table obj.1 %} -
-
-
- {% endfor %} -
-
-
-
- {% endif %} - {% if instance %} -
-
- {% endif %} - - - -{% if object_texts %} - {% if user.is_superuser %} - {% if form_ann_agreement %} -
-
-
- {% crispy form_ann_agreement form_ann_agreement.helper %} -
-
-
-
- {% endif %} - {% endif %} -
-
- {% if ann_proj_form %} -
-{% crispy ann_proj_form ann_proj_form.helper %} -
-{% endif %} -{% for txt in object_texts %} - -
-
-
{{txt.text|safe}}
- -
-
-
-{% endfor %} -
-
-
-{% endif %} -{% load crispy_forms_tags %} -{% endblock %} -{% block scripts %} -{{block.super}} -{% if instance %} - - - - - - - - - -{% endblock %} diff --git a/apis_core/apis_entities/templates/apis_entities/entity_edit_generic.html b/apis_core/apis_entities/templates/apis_entities/entity_edit_generic.html new file mode 100644 index 0000000..22f764c --- /dev/null +++ b/apis_core/apis_entities/templates/apis_entities/entity_edit_generic.html @@ -0,0 +1,84 @@ +{% extends "base.html" %} +{% load static %} +{% block titel %}Create a {{ entity_type|title }}{% endblock %} + +{% block content %} + +{% load django_tables2 %} +{% load crispy_forms_tags %} + + +
+

+ + {{ entity_type }}s + + {{ instance }} +

+

+ + + + + + +

+
+
+

+ Edit the Entity +

+
+ {% crispy form %} + + Delete +
+
+
+

Edit the Relations

+ {% for obj in right_card %} +
+

{{ obj.0 }}

+
+ {% render_table obj.1 %} +
+
+ +
+ {% endfor %} +
+
+ +{% endblock %} diff --git a/apis_core/apis_entities/templates/apis_entities/event_create_generic.html b/apis_core/apis_entities/templates/apis_entities/event_create_generic.html deleted file mode 100644 index e02c93b..0000000 --- a/apis_core/apis_entities/templates/apis_entities/event_create_generic.html +++ /dev/null @@ -1,21 +0,0 @@ -{% extends "apis_entities/entity_create_generic.html" %} -{% block additional_accordion %} -
- - -
-
- {% load crispy_forms_tags %} - {% crispy form_merge_with form_merge_with.helper %} -
-
-
-
-{% endblock %} - diff --git a/apis_core/apis_entities/templates/apis_entities/event_list_generic.html b/apis_core/apis_entities/templates/apis_entities/event_list_generic.html deleted file mode 100644 index f9f0325..0000000 --- a/apis_core/apis_entities/templates/apis_entities/event_list_generic.html +++ /dev/null @@ -1,8 +0,0 @@ -{% extends "apis_entities/generic_list.html" %} -{% block Titel %}See all Events{% endblock %} -{% block list_title %}All Events{% endblock %} -{% block create_button %} -
- create new Event -
-{% endblock %} \ No newline at end of file diff --git a/apis_core/apis_entities/templates/apis_entities/generic_list.html b/apis_core/apis_entities/templates/apis_entities/generic_list.html deleted file mode 100644 index 11d48ce..0000000 --- a/apis_core/apis_entities/templates/apis_entities/generic_list.html +++ /dev/null @@ -1,182 +0,0 @@ -{% extends "base.html" %} -{% load i18n %} -{% block title %} See all {{entity|title}}s {% endblock %} -{% block content %} - -
-
-
-
-
-
-

hallo {{entity}}

- {% load django_tables2 crispy_forms_tags %} - -
- {% crispy filter.form filter.form.helper %} - -
- {% block create_button %} - {% if user.is_authenticated %} -
-
-

create new {{ entity }}

-
-
- {% crispy entity_create_stanbol entity_create_stanbol.helper %} - create new {{entity}} -
-
- {% endif %} - {% endblock %} -
-
-
- -
-
-
- {% with table.paginator.count as total %} - Total results: {{ total }} - {% endwith %} - {% block table %} - - {% block table.thead %} - {% if table.show_header %} - - - {% for column in table.columns %} - {% if column.orderable %} - {{ column.header }} - {% else %} - {{ column.header }} - {% endif %} - {% endfor %} - - - {% endif %} - {% endblock table.thead %} - {% block table.tbody %} - - {% for row in table.page.object_list|default:table.rows %} {# support pagination #} - {% block table.tbody.row %} - - {% for column, cell in row.items %} - {% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %} - {% endfor %} - - {% endblock table.tbody.row %} - {% empty %} - {% if table.empty_text %} - {% block table.tbody.empty_text %} - {{ table.empty_text }} - {% endblock table.tbody.empty_text %} - {% endif %} - {% endfor %} - - {% endblock table.tbody %} - {% block table.tfoot %} - {% if table.has_footer %} - - - {% for column in table.columns %} - {{ column.footer }} - {% endfor %} - - - {% endif %} - {% endblock table.tfoot %} - - {% endblock table %} - - {% block pagination.allpages %} -
- {% with table.page.object_list|length as count %} -

Page total: {{ count }}

- {% endwith %} -
-
    - {% if table.paginator.page_range|length > 10 %} - {% if table.page.has_previous %} - {% block pagination.previous.goto %} - - {% endblock pagination.previous.goto %} - {% endif %} - {% if table.page.has_previous or table.page.has_next %} - {% block pagination.cardinality %} - {% blocktrans with table.page.number as current and table.paginator.num_pages as total %} -

    Page {{ current }} of {{ total }}

    - {% endblocktrans %} - {% endblock pagination.cardinality %} - {% endif %} - {% if table.page.has_next %} - {% block pagination.next.goto %} - - {% endblock pagination.next.goto %} - {% endif %} -
-
- - -
- {% else %} - {% if table.page.has_previous %} - {% block pagination.previous %} - - {% endblock pagination.previous %} - {% endif %} - {% for p in table.paginator.page_range %} - {% if p == table.page.number %} -
  • - {{ p }} -
  • - {% else %} -
  • - {{ p }} -
  • - {% endif %} - {% endfor %} - {% if table.page.has_next %} - {% block pagination.next %} - - {% endblock pagination.next %} - {% endif %} - - - {% endif %} - {% endblock pagination.allpages %} -
    - {% for format in table.export_formats %} - - download .{{ format }} - - {% endfor %} -
    -
    -
    -
    -
    -
    - -{% endblock %} diff --git a/apis_core/apis_entities/templates/apis_entities/institution_create.html b/apis_core/apis_entities/templates/apis_entities/institution_create.html deleted file mode 100644 index b15cedd..0000000 --- a/apis_core/apis_entities/templates/apis_entities/institution_create.html +++ /dev/null @@ -1,397 +0,0 @@ -{% extends "webpage/base.html" %} - -{% block Titel %}Create a Institution{% endblock %} -{% block scriptHeader %} -{% include 'autocomplete_light/static.html' %} -{% endblock %} -{% block content %} -{% load crispy_forms_tags %} -
    - -
    -
    -
    -

    {{ instance }}

    -
    -
    -
    -
    - -
    -
    - - {% if form_text %} - - {% crispy form_text %} - - {% endif %} - -
    -
    -
    - - - {% csrf_token %} - {% crispy form %} - - {% for form1 in formset %} -
    - {% crispy form1 %} -
    - {% endfor %} - {{ formset.management_form }} - -
    - {% if object_revisions %} -

    -
    - -
    -
    - - {% for rev in object_revisions %} - - {% endfor %} -
    {{ rev.revision.date_created }}{{ rev.revision.user }}
    -
    -
    -
    - {% endif %} -
    - - -
    - - -
    - - -
    -
    -
    -

    related to

    -
    -
    -
    -
    - -
    -
    - - - {% for x in object_place %} - - - - - - - {% endfor %} - -
    {{ x.start_date_written }} - {{ x.end_date_written }} - - {{ x.relation_type }} - {{ x.related_place }} - -
    - -
    -
    -
    -
    - -
    -
    - - - {% for x in object_person %} - - - - - - - {% endfor %} - {% for x in object_personB %} - - - - - - - {% endfor %} -
    - {{ x.start_date_written }} - {{ x.end_date_written }} - {{ x.relation_type }}{{ x.related_person }}
    {{ x.start_date }}{{ x.relation_type.name_reverse }}{{ x.related_persona }} reverse
    - - -
    -
    -
    -
    - -
    -
    - - - {% for x in object_institutionA %} - - - - - - - {% endfor %} - {% for x in object_institutionB %} - - - - - - - {% endfor %} -
    - {{ x.start_date_written }} - {{ x.end_date_written }} - {{ x.relation_type }}{{ x.related_institutionB }}
    {{ x.start_date_written }} - {% if x.end_date_written %} - {{ x.end_date_written }} - {% endif %} - {{ x.relation_type.name_reverse }}{{ x.related_institutionA }}
    - - -
    -
    -
    -
    - -
    -
    - - {% for x in object_labels %} - - - - - - - {% endfor %} -
    {{ x.label }} - {{ x.isocode_639_3 }} - {{ x.label_type }}
    -
    -
    -
    -
    - -
    -
    - {% if object_event %} - - - {% for x in object_event %} - - - - - {% endfor %} - -
    {{ x.relation_type }}{{ x.related_event }}
    - {% endif %} - -
    -
    -
    -
    -
    -
    -
    -
    -{% endblock %} -{% block scripts %} -{{block.super}} - - - - - - - - - - - - -{% if instance %} - -{% endif %} -{% endblock %} - \ No newline at end of file diff --git a/apis_core/apis_entities/templates/apis_entities/institution_create_generic.html b/apis_core/apis_entities/templates/apis_entities/institution_create_generic.html deleted file mode 100644 index 2530963..0000000 --- a/apis_core/apis_entities/templates/apis_entities/institution_create_generic.html +++ /dev/null @@ -1,85 +0,0 @@ -{% extends "apis_entities/entity_create_generic.html" %} -{% load guardian_tags %} -{% block Titel %}Create an Institution{% endblock %} - -{% block additional_accordion %} -
    - - -
    -
    - {% load crispy_forms_tags %} - {% crispy form_merge_with form_merge_with.helper %} -
    -
    -
    -
    -{% endblock %} -{% block scripts %} -{{ block.super }} - -{% if instance %} - {% get_obj_perms request.user for instance as "instance_perms" %} -{% if "change_institution" in instance_perms %} - - -{% else %} - -{% endif %} -{% endif %} -{% endblock %} -{% block editbuttons %} - {% if instance %} - {% get_obj_perms request.user for instance as "instance_perms" %} - {% if "delete_institution" in instance_perms %} - Delete - {% endif %} - {% if "change_institution" in instance_perms %} - - {% endif %} - {% else %} - {% if perms.apis_entities.add_institution %} - - {% endif %} - {% endif %} - {% if instance %} - - {% endif %} -{% endblock editbuttons %} diff --git a/apis_core/apis_entities/templates/apis_entities/person_create.html b/apis_core/apis_entities/templates/apis_entities/person_create.html deleted file mode 100644 index e3b102c..0000000 --- a/apis_core/apis_entities/templates/apis_entities/person_create.html +++ /dev/null @@ -1,376 +0,0 @@ -{% extends "webpage/base.html" %} - -{% block Titel %}Create a Person{% endblock %} -{% block scriptHeader %} -{% include 'autocomplete_light/static.html' %} -{% endblock %} -{% block content %} -{% load crispy_forms_tags %} -{% load django_tables2 %} -{% render_table tb_institution %} -
    -
    -
    -
    -

    {{ instance }}

    -
    -
    -
    -
    - -
    -
    - - {% crispy form_text %} - -
    -
    -
    - {% crispy form %} - {% if instance %} - delete - {% endif %} - {% for form1 in formset %} -
    - {% crispy form1 %} -
    - {% endfor %} - {{ formset.management_form }} - -
    - {% if object_revisions %} -

    -
    - -
    -
    - - {% for rev in object_revisions %} - - {% endfor %} -
    {{ rev.revision.date_created }}{{ rev.revision.user }}
    -
    -
    -
    - {% endif %} -
    -
    -
    -
    -
    -
    -

    related to

    -
    -
    -
    -
    - -
    -
    - - - {% for x in object_place %} - - - - - - - {% endfor %} - -
    {{ x.start_date_written }}{{ x.relation_type }} - {{ x.related_place }} - -
    - -
    -
    -
    -
    - -
    -
    - - - {% for x in object_personA %} - - - - - - - {% endfor %} - {% for x in object_personB %} - - - - - - - {% endfor %} -
    {{ x.start_date_written }}{{ x.relation_type }}{{ x.related_personb }}
    {{ x.start_date }}{{ x.relation_type.name_reverse }}{{ x.related_persona }} reverse
    - - -
    -
    -
    -
    - -
    -
    - - - {% for x in object_institution %} - - - - - - - {% endfor %} -
    {{ x.start_date_written }}{{ x.relation_type }}{{ x.related_institution }}
    - - {% render_table tb_institution %} - - {{tb_institution}} - - -
    -
    -
    -
    - -
    -
    - - {% for x in object_labels %} - - - - - - - {% endfor %} -
    {{ x.label }} - {{ x.isocode_639_3 }} - {{ x.label_type }}
    -
    -
    -
    -
    - -
    -
    - {% if object_event %} - - - {% for x in object_event %} - - - - - {% endfor %} - -
    {{ x.relation_type }}{{ x.related_event }}
    - {% endif %} - -
    -
    -
    -
    -
    -
    -
    -
    -{% endblock %} -{% block scripts %} -{{block.super}} - - - - - - - - - - - - -{% if instance %} - -{% endif %} -{% endblock %} \ No newline at end of file diff --git a/apis_core/apis_entities/templates/apis_entities/person_create_generic.html b/apis_core/apis_entities/templates/apis_entities/person_create_generic.html deleted file mode 100644 index ffcb2a6..0000000 --- a/apis_core/apis_entities/templates/apis_entities/person_create_generic.html +++ /dev/null @@ -1,23 +0,0 @@ -{% extends "apis_entities/entity_create_generic.html" %} -{% block additional_accordion %} -
    - - -
    -
    - {% load crispy_forms_tags %} - {% crispy form_merge_with form_merge_with.helper %} -
    -
    -
    -
    -{% endblock %} - - - diff --git a/apis_core/apis_entities/templates/apis_entities/person_create_new.html b/apis_core/apis_entities/templates/apis_entities/person_create_new.html deleted file mode 100644 index 7eafe20..0000000 --- a/apis_core/apis_entities/templates/apis_entities/person_create_new.html +++ /dev/null @@ -1,247 +0,0 @@ -{% extends "webpage/base.html" %} - -{% block Titel %}Create a Person{% endblock %} -{% block scriptHeader %} -{% include 'autocomplete_light/static.html' %} -{% endblock %} -{% block content %} -{% load crispy_forms_tags %} -{% load django_tables2 %} - -
    -
    -
    -
    -

    {{ instance }}

    -
    -
    -
    -
    - -
    -
    - - {% crispy form_text %} - -
    -
    -
    - {% crispy form %} - {% if instance %} - delete - {% endif %} - {% for form1 in formset %} -
    - {% crispy form1 %} -
    - {% endfor %} - {{ formset.management_form }} - -
    - {% if object_revisions %} -

    -
    - -
    -
    - - {% for rev in object_revisions %} - - {% endfor %} -
    {{ rev.revision.date_created }}{{ rev.revision.user }}
    -
    -
    -
    - {% endif %} -
    -
    -
    -
    -
    -
    -

    related to

    -
    -
    -
    - {% for obj in right_card %} -
    - -
    -
    - - {% render_table obj.1 %} - -
    -
    -
    - {% endfor %} -
    - - -
    -
    -
    -
    -
    -{% endblock %} -{% block scripts %} -{{block.super}} - - - - - - - - - - - - -{% if instance %} - -{% endif %} -{% endblock %} \ No newline at end of file diff --git a/apis_core/apis_entities/templates/apis_entities/place_create.html b/apis_core/apis_entities/templates/apis_entities/place_create.html deleted file mode 100644 index fdeb7a8..0000000 --- a/apis_core/apis_entities/templates/apis_entities/place_create.html +++ /dev/null @@ -1,281 +0,0 @@ -{% extends "webpage/base.html" %} - -{% block Titel %}Create/Modify a Place{% endblock %} -{% block scriptHeader %} -{% include 'autocomplete_light/static.html' %} -{% endblock %} -{% block content %} -{% load crispy_forms_tags %} -
    -
    -
    -
    -
    -

    {{ instance }}

    -
    -
    -
    - -
    -
    - {% if form_text %} - - {% crispy form_text %} - - {% endif %} - -
    -
    -
    - - {% csrf_token %} - {% crispy form %} - {% if instance %} - delete - {% endif %} - - -
    -
    -
    -
    - -
    -
    -
    -

    related to

    -
    -
    -
    -
    - - -
    -
    -
    -
    -
    -
    -
    -
    -
    - - -
    -
    - {% if object_place %} - - - {% for x in object_place %} - - - - - - {% endfor %} - -
    {{ x.start_date_written }}{{ x.relation_type }}{% if x.related_placea.pk == instance.pk %}{{x.related_placeb}}{% else %}{{x.related_placea}}{% endif %}
    - {% endif %} -
    -
    -
    -
    -
    -
    - - -
    -
    - {% if object_person %} - - - {% for x in object_person %} - - - - - - {% endfor %} - -
    {{ x.relation_type.name_reverse }}{{ x.related_person }} reverse
    - {% endif %} - -
    -
    -
    -
    - -
    -
    - - -
    -
    - {% if object_institution %} - - - {% for x in object_institution %} - - - - - {% endfor %} - -
    {{ x.relation_type }}{{ x.related_institution }}
    - {% endif %} -
    -
    -
    -
    -
    -
    - - -
    -
    - {% if object_event %} - - - - {% for x in object_event %} - - - - - {% endfor %} - -
    {{ x.relation_type }}{{ x.related_event }}
    - {% endif %} -
    -
    -
    -
    - -
    -
    - - -
    -
    - {% if uri %} -

    - distinct Uri: {{ uri.0.uri }} - {% endif %} - {% if uri_candidates %} - ambigue Uris: {% for uri in uri_candidates %}{{ uri.uri }}, {% endfor %} - {% endif %} -

    -
    -
    -
    -
    -
    - -{% endblock %} -{% block scripts %} -{{block.super}} - - - - -{% endblock %} \ No newline at end of file diff --git a/apis_core/apis_entities/templates/apis_entities/place_create_generic.html b/apis_core/apis_entities/templates/apis_entities/place_create_generic.html deleted file mode 100644 index 874a9d7..0000000 --- a/apis_core/apis_entities/templates/apis_entities/place_create_generic.html +++ /dev/null @@ -1,196 +0,0 @@ -{% extends "apis_entities/entity_create_generic.html" %} -{% load guardian_tags %} -{% load static %} -{% block title %}Create/Edit a Place{% endblock %} -{% block scriptHeader %} -{{block.super}} - - - - - -{% endblock scriptHeader %} -{% block additional_accordion %} -{% load crispy_forms_tags %} - -
    - - -
    -
    - {% load crispy_forms_tags %} - {% crispy form_merge_with form_merge_with.helper %} -
    -
    -
    -
    - -
    -
    -
    - - - - -
    -
    -
    -

    - Use sequences of search terms (delimiter: ,) to limit the search to certain administrative divisions. E.g. "Österreich,Oberösterreich,Steyr". Use square brackets to set the min score difference to slice results. "Wien" will only show the capital of Austria, "Wien[30]" shows also a town in India. -

    -
    -
    -
    - -
    -{% endblock %} - -{% block scripts %} -{{block.super}} - - - -{% if instance %} -{% if "change_place" in instance_perms %} - - -{% else %} - -{% endif %} -{% endif %} -{% endblock %} -{% block editbuttons %} - {% if instance %} - {% get_obj_perms request.user for instance as "instance_perms" %} - {% if "delete_place" in instance_perms %} - Delete - {% endif %} - {% if "change_place" in instance_perms %} - - {% endif %} - {% else %} - {% if perms.apis_entities.add_place %} - - {% endif %} - - {% endif %} - {% if instance %} - - {% endif %} -{% endblock editbuttons %} diff --git a/apis_core/apis_entities/templates/apis_entities/work_create_generic.html b/apis_core/apis_entities/templates/apis_entities/work_create_generic.html deleted file mode 100644 index e02c93b..0000000 --- a/apis_core/apis_entities/templates/apis_entities/work_create_generic.html +++ /dev/null @@ -1,21 +0,0 @@ -{% extends "apis_entities/entity_create_generic.html" %} -{% block additional_accordion %} -
    - - -
    -
    - {% load crispy_forms_tags %} - {% crispy form_merge_with form_merge_with.helper %} -
    -
    -
    -
    -{% endblock %} - diff --git a/apis_core/apis_entities/templates/apis_entities/work_list_generic.html b/apis_core/apis_entities/templates/apis_entities/work_list_generic.html deleted file mode 100644 index 5d93983..0000000 --- a/apis_core/apis_entities/templates/apis_entities/work_list_generic.html +++ /dev/null @@ -1,8 +0,0 @@ -{% extends "apis_entities/generic_list.html" %} -{% block Titel %}See all Works{% endblock %} -{% block list_title %}All Works{% endblock %} -{% block create_button %} - -{% endblock %} \ No newline at end of file diff --git a/apis_core/apis_entities/urls.py b/apis_core/apis_entities/urls.py index 776a5a5..5eb45a7 100644 --- a/apis_core/apis_entities/urls.py +++ b/apis_core/apis_entities/urls.py @@ -13,6 +13,7 @@ from .list_view_institution import InstitutionListView from .list_view_event import EventListView + app_name = "apis_entities" urlpatterns = [ @@ -61,11 +62,6 @@ EventListView.as_view(), name="event_list_view", ), - path( - "entity//list/", - views.GenericListViewNew.as_view(), - name="generic_entities_list", - ), path( "autocomplete/createstanbol//", GenericEntitiesCreateStanbolView.as_view(), diff --git a/apis_core/apis_entities/views.py b/apis_core/apis_entities/views.py index 059ef6b..9d3b28f 100644 --- a/apis_core/apis_entities/views.py +++ b/apis_core/apis_entities/views.py @@ -3,36 +3,25 @@ from django.conf import settings from django.contrib.auth.decorators import login_required, user_passes_test -from django.contrib.auth.mixins import UserPassesTestMixin -from django.contrib.contenttypes.models import ContentType from django.http import HttpResponse from django.http import HttpResponseRedirect from django.shortcuts import render, redirect, get_object_or_404 from django.urls import reverse from django.urls import reverse_lazy -from django_tables2 import RequestConfig -from django_tables2 import SingleTableView -from django_tables2.export.views import ExportMixin from apis_core.apis_metainfo.models import Uri, UriCandidate, Text from apis_core.apis_relations.models import AbstractRelation from apis_core.helper_functions.RDFParser import RDFParser from apis_core.helper_functions.stanbolQueries import retrieve_obj from apis_core.helper_functions.utils import ( - access_for_all, access_for_all_function, - ENTITIES_DEFAULT_COLS, ) -from browsing.browsing_utils import GenericListView -from .filters import get_list_filter_of_entity from .forms import ( - GenericFilterFormHelper, NetworkVizFilterForm, PersonResolveUriForm, - GenericEntitiesStanbolForm, ) from .models import Place -from .tables import get_entities_table + ########################################################################### ############################################################################ @@ -94,147 +83,6 @@ def get_highlighted_texts(request, instance): return object_texts, False -############################################################################ -############################################################################ -# -# GenericViews -# -############################################################################ -############################################################################ - - -class GenericListViewNew(UserPassesTestMixin, ExportMixin, SingleTableView): - formhelper_class = GenericFilterFormHelper - context_filter_name = "filter" - paginate_by = 25 - template_name = "browsing/generic_list.html" - - def get_model(self): - model = ContentType.objects.get( - app_label__startswith="apis_", model=self.entity.lower() - ).model_class() - return model - - def test_func(self): - access = access_for_all(self, viewtype="list") - if access: - self.request = set_session_variables(self.request) - return access - - def get_queryset(self, **kwargs): - self.entity = self.kwargs.get("entity") - qs = ( - ContentType.objects.get( - app_label__startswith="apis_", model=self.entity.lower() - ) - .model_class() - .objects.all() - ) - self.filter = get_list_filter_of_entity(self.entity.title())( - self.request.GET, queryset=qs - ) - self.filter.form.helper = self.formhelper_class() - return self.filter.qs - - def get_table(self, **kwargs): - session = getattr(self.request, "session", False) - entity = self.kwargs.get("entity") - selected_cols = self.request.GET.getlist("columns") - if session: - edit_v = self.request.session.get("edit_views", False) - else: - edit_v = False - if "table_fields" in settings.APIS_ENTITIES[entity.title()]: - default_cols = settings.APIS_ENTITIES[entity.title()]["table_fields"] - else: - default_cols = ["id", "name"] - default_cols = default_cols + selected_cols - self.table_class = get_entities_table( - self.entity.title(), edit_v, default_cols=default_cols - ) - table = super(GenericListViewNew, self).get_table() - RequestConfig( - self.request, paginate={"page": 1, "per_page": self.paginate_by} - ).configure(table) - return table - - def get_context_data(self, **kwargs): - model = self.get_model() - context = super(GenericListViewNew, self).get_context_data() - context[self.context_filter_name] = self.filter - context["entity"] = self.entity - print(f"#############{self.entity}") - context["app_name"] = "apis_entities" - entity = self.entity.title() - context["entity_create_stanbol"] = GenericEntitiesStanbolForm(self.entity) - context["docstring"] = "{}".format(model.__doc__) - if model._meta.verbose_name_plural: - context["class_name"] = "{}".format(model._meta.verbose_name.title()) - else: - if model.__name__.endswith("s"): - context["class_name"] = "{}".format(model.__name__) - else: - context["class_name"] = "{}s".format(model.__name__) - context["create_view_link"] = None - context["enable_merge"] = False - try: - togg_cols = settings.APIS_ENTITIES[entity.title()]["additional_cols"] - except KeyError: - togg_cols = [] - context["togglable_colums"] = { - x: x for x in [togg_cols + ENTITIES_DEFAULT_COLS][0] - } - return context - - def render_to_response(self, context, **kwargs): - download = self.request.GET.get("sep", None) - if download and "browsing" in settings.INSTALLED_APPS: - import datetime - import time - import pandas as pd - - sep = self.request.GET.get("sep", ",") - timestamp = datetime.datetime.fromtimestamp(time.time()).strftime( - "%Y-%m-%d-%H-%M-%S" - ) - filename = "export_{}".format(timestamp) - response = HttpResponse(content_type="text/csv") - if context["conf_items"]: - conf_items = context["conf_items"] - try: - df = pd.DataFrame( - list( - self.get_queryset().values_list(*[x[0] for x in conf_items]) - ), - columns=[x[1] for x in conf_items], - ) - except AssertionError: - response[ - "Content-Disposition" - ] = 'attachment; filename="{}.csv"'.format(filename) - return response - else: - response[ - "Content-Disposition" - ] = 'attachment; filename="{}.csv"'.format(filename) - return response - if sep == "comma": - df.to_csv(response, sep=",", index=False) - elif sep == "semicolon": - df.to_csv(response, sep=";", index=False) - elif sep == "tab": - df.to_csv(response, sep="\t", index=False) - else: - df.to_csv(response, sep=",", index=False) - response["Content-Disposition"] = 'attachment; filename="{}.csv"'.format( - filename - ) - return response - else: - response = super(GenericListViewNew, self).render_to_response(context) - return response - - ############################################################################ ############################################################################ # diff --git a/apis_core/apis_entities/views2.py b/apis_core/apis_entities/views2.py index af710b3..95fc53f 100644 --- a/apis_core/apis_entities/views2.py +++ b/apis_core/apis_entities/views2.py @@ -14,12 +14,9 @@ from apis_core.apis_entities.models import AbstractEntity from apis_core.apis_labels.models import Label -from apis_core.apis_metainfo.models import Uri from apis_core.apis_relations.models import AbstractRelation from apis_core.apis_relations.tables import get_generic_relations_table, LabelTableEdit from .forms import get_entities_form, FullTextForm, GenericEntitiesStanbolForm -from .views import get_highlighted_texts -from .views import set_session_variables @method_decorator(login_required, name="dispatch") @@ -29,7 +26,6 @@ def get(self, request, *args, **kwargs): pk = kwargs["pk"] entity_model = AbstractEntity.get_entity_class_of_name(entity) instance = get_object_or_404(entity_model, pk=pk) - request = set_session_variables(request) relations = AbstractRelation.get_relation_classes_of_entity_name( entity_name=entity ) @@ -69,11 +65,6 @@ def get(self, request, *args, **kwargs): ) form = get_entities_form(entity.title()) form = form(instance=instance) - form_text = FullTextForm(entity=entity.title(), instance=instance) - form_ann_agreement = False - apis_bibsonomy = False - 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 = LabelTableEdit(data=object_labels, prefix=entity.title()[:2] + "L-") tb_label_open = request.GET.get("PL-page", None) @@ -81,24 +72,17 @@ def get(self, request, *args, **kwargs): RequestConfig(request, paginate={"per_page": 10}).configure(tb_label) template = select_template( [ - "apis_entities/{}_create_generic.html".format(entity), - "apis_entities/entity_create_generic.html", + "apis_entities/entity_edit_generic.html", ] ) context = { "entity_type": entity, "form": form, - "form_text": form_text, "instance": instance, "right_card": side_bar, - "object_texts": object_texts, - "object_lod": object_lod, - "ann_proj_form": ann_proj_form, - "form_ann_agreement": form_ann_agreement, - "apis_bibsonomy": apis_bibsonomy, } - form_merge_with = GenericEntitiesStanbolForm(entity, ent_merge_pk=pk) - context["form_merge_with"] = form_merge_with + # form_merge_with = GenericEntitiesStanbolForm(entity, ent_merge_pk=pk) + # context["form_merge_with"] = form_merge_with return HttpResponse(template.render(request=request, context=context)) def post(self, request, *args, **kwargs): diff --git a/apis_core/apis_metainfo/models.py b/apis_core/apis_metainfo/models.py index 7c82ef6..6d4bda5 100644 --- a/apis_core/apis_metainfo/models.py +++ b/apis_core/apis_metainfo/models.py @@ -136,15 +136,9 @@ def get_child_entity(self): def get_listview_url(self): entity = self.__name__.lower() if entity == "institution" or len(entity) < 10: - return reverse( - "apis_core:apis_entities:generic_entities_list", - kwargs={"entity": entity}, - ) + return reverse(f"apis_core:apis_entities:{entity}_list_view") else: - return reverse( - "apis_core:apis_relations:generic_relations_list", - kwargs={"entity": entity}, - ) + return "/" @classmethod def get_createview_url(self): diff --git a/apis_core/apis_metainfo/templates/apis_metainfo/uri_detail.html b/apis_core/apis_metainfo/templates/apis_metainfo/uri_detail.html index 4be01cc..f7897c1 100644 --- a/apis_core/apis_metainfo/templates/apis_metainfo/uri_detail.html +++ b/apis_core/apis_metainfo/templates/apis_metainfo/uri_detail.html @@ -1,4 +1,4 @@ -{% extends "webpage/base.html" %} +{% extends "base.html" %} {% load static %} {% load django_tables2 %} {% block title %} {{ object }} {% endblock %} diff --git a/apis_core/apis_metainfo/testb_models.py.bak b/apis_core/apis_metainfo/testb_models.py.bak deleted file mode 100644 index 119cb14..0000000 --- a/apis_core/apis_metainfo/testb_models.py.bak +++ /dev/null @@ -1,50 +0,0 @@ -from django.test import TestCase - -from apis_highlighter.models import Annotation -from .models import Text, Source - - -class TextModelTestCase(TestCase): - text = 'Hallo wir sind heute in Wien. Wie geht es euch?' - source_name = 'testsource' - ann_start = 5 - ann_stop = 10 - - - @classmethod - def setUpTestData(cls): - # Set up data for the whole TestCase - cls.source = Source.objects.create(pubinfo=cls.source_name) - - def test_init(self): - Text() - - def test_add_to_text(self): - txt = Text.objects.create(text=self.text, source=self.source) - ann = Annotation.objects.create(start=self.ann_start, end=self.ann_stop, text=txt) - anno_orig = txt.text[ann.start:ann.end] - txt.text = txt.text[:self.ann_start-3]+ 'test....'+txt.text[self.ann_start-2:] - txt.save() - ann2 = Annotation.objects.get(pk=ann.pk) - anno_change = txt.text[ann2.start:ann2.end] - self.assertEqual(anno_orig, anno_change) - - def test_delete_text(self): - txt = Text.objects.create(text=self.text, source=self.source) - ann = Annotation.objects.create(start=self.ann_start, end=self.ann_stop, text=txt) - anno_orig = txt.text[ann.start:ann.end] - print('test2: '+txt.text) - txt.text = txt.text[:self.ann_start-4]+ txt.text[self.ann_start-2:] - txt.save() - ann2 = Annotation.objects.get(pk=ann.pk) - anno_change = txt.text[ann2.start:ann2.end] - self.assertEqual(anno_orig, anno_change) - - def test_anno_in_delete(self): - txt = Text.objects.create(text=self.text, source=self.source) - ann = Annotation.objects.create(start=self.ann_start, end=self.ann_stop, text=txt) - anno_orig = txt.text[ann.start:ann.end] - txt.text = txt.text[:self.ann_start - 2] + txt.text[self.ann_stop - 2:] - txt.save() - with self.assertRaises(Annotation.DoesNotExist): - Annotation.objects.get(pk=ann.pk) diff --git a/apis_core/apis_relations/forms2.py b/apis_core/apis_relations/forms2.py index 7f9d440..ba4e7dd 100644 --- a/apis_core/apis_relations/forms2.py +++ b/apis_core/apis_relations/forms2.py @@ -24,9 +24,6 @@ # from dal.autocomplete import ListSelect2 -if "apis_highlighter" in settings.INSTALLED_APPS: - from apis_highlighter.models import Annotation, AnnotationProject - def validate_target_autocomplete(value): try: @@ -34,7 +31,7 @@ def validate_target_autocomplete(value): except ValueError: if value.startswith("http"): test = False - sett = yaml.load(open(APIS_RDF_URI_SETTINGS, "r")) + sett = yaml.safe_load(open(APIS_RDF_URI_SETTINGS, "r")) regx = [x["regex"] for x in sett["mappings"]] regx.append("http.*oeaw\.ac\.at") for k, v in getattr(settings, "APIS_AC_INSTANCES", {}).items(): @@ -96,29 +93,8 @@ def save(self, site_instance, instance=None, commit=True): if not t1: t1 = RDFParser(cd["target"], self.rel_accessor[0]).get_or_create() setattr(x, self.rel_accessor[2], t1) - if self.highlighter: - an_proj = AnnotationProject.objects.get( - pk=int(self.request.session.get("annotation_project", 1)) - ) - x.published = an_proj.published if commit: x.save() - if self.highlighter: - if not commit: - x.save() - txt = Text.objects.get(pk=cd["HL_text_id"][5:]) - a = Annotation( - start=cd["HL_start"], - end=cd["HL_end"], - text=txt, - user_added=self.request.user, - annotation_project_id=int( - self.request.session.get("annotation_project", 1) - ), - ) - a.entity_link = x - a.save() - print("saved: {}".format(x)) return x def get_text_id(self): @@ -140,8 +116,8 @@ def get_html_table(self, entity_type, request, site_instance, form_match): ) prefix = prefix.group(1) + prefix.group(2) + "-" if form_match.group(1) == form_match.group(2): - dic_a = {"related_" + entity_type.lower() + "A": site_instance} - dic_b = {"related_" + entity_type.lower() + "B": site_instance} + dic_a = {"related_" + entity_type.lower() + "a": site_instance} + dic_b = {"related_" + entity_type.lower() + "b": site_instance} if "apis_highlighter" in settings.INSTALLED_APPS: objects = self.relation_form.objects.filter_ann_proj( request=request @@ -152,12 +128,7 @@ def get_html_table(self, entity_type, request, site_instance, form_match): table_html = table(data=objects, prefix=prefix) else: tab_query = {"related_" + entity_type.lower(): site_instance} - if "apis_highlighter" in settings.INSTALLED_APPS: - ttab = self.relation_form.objects.filter_ann_proj( - request=request - ).filter(**tab_query) - else: - ttab = self.relation_form.objects.filter(**tab_query) + ttab = self.relation_form.objects.filter(**tab_query) table_html = table(data=ttab, prefix=prefix) return table_html @@ -207,32 +178,31 @@ def __init__(self, siteID=None, highlighter=False, *args, **kwargs): if lst_src_target[0] == lst_src_target[1]: if instance and instance.id: if getattr( - instance, "related_{}A_id".format(lst_src_target[0].lower()) + instance, "related_{}a_id".format(lst_src_target[0].lower()) ) == int(siteID): self.rel_accessor = ( lst_src_target[1], True, - "related_{}B".format(lst_src_target[1].lower()), - "related_{}A".format(lst_src_target[0].lower()), + "related_{}b".format(lst_src_target[1].lower()), + "related_{}a".format(lst_src_target[0].lower()), ) else: self.rel_accessor = ( lst_src_target[1], False, - "related_{}A".format(lst_src_target[1].lower()), - "related_{}B".format(lst_src_target[0].lower()), + "related_{}a".format(lst_src_target[1].lower()), + "related_{}b".format(lst_src_target[0].lower()), ) else: self.rel_accessor = ( lst_src_target[1], True, - "related_{}B".format(lst_src_target[1].lower()), - "related_{}A".format(lst_src_target[0].lower()), + "related_{}b".format(lst_src_target[1].lower()), + "related_{}a".format(lst_src_target[0].lower()), ) self.fields["relation_type"] = autocomplete.Select2ListCreateChoiceField( label="Relation type", widget=ListSelect2( - # url='/vocabularies/autocomplete/{}{}relation/normal'.format(lst_src_target[0].lower(), lst_src_target[1].lower()), url=reverse( "apis:apis_vocabularies:generic_vocabularies_autocomplete", args=[ @@ -252,7 +222,6 @@ def __init__(self, siteID=None, highlighter=False, *args, **kwargs): self.fields["target"] = autocomplete.Select2ListCreateChoiceField( label=lst_src_target[1], widget=ListSelect2( - # url='/entities/autocomplete/{}'.format(lst_src_target[1].lower()), url=reverse( "apis:apis_entities:generic_entities_autocomplete", args=[lst_src_target[1].lower()], @@ -272,7 +241,6 @@ def __init__(self, siteID=None, highlighter=False, *args, **kwargs): self.fields["relation_type"] = autocomplete.Select2ListCreateChoiceField( label="Relation type", widget=ListSelect2( - # url='/vocabularies/autocomplete/{}{}relation/normal'.format(lst_src_target[0].lower(), lst_src_target[1].lower()), url=reverse( "apis:apis_vocabularies:generic_vocabularies_autocomplete", args=[ @@ -343,7 +311,7 @@ def __init__(self, siteID=None, highlighter=False, *args, **kwargs): help_text=help_text_target, ) else: - print("no hit rel_accessor") + pass if instance and instance.id: self.fields["target"].choices = [ ( @@ -379,8 +347,6 @@ def __init__(self, siteID=None, highlighter=False, *args, **kwargs): instance.relation_type.id, instance.relation_type.label_reverse, ) - if highlighter: - css_notes = "HL" self.helper.include_media = False self.helper.layout = Layout( @@ -401,12 +367,6 @@ def __init__(self, siteID=None, highlighter=False, *args, **kwargs): ), ) - if highlighter: - self.fields["HL_start"] = forms.IntegerField(widget=forms.HiddenInput) - self.fields["HL_end"] = forms.IntegerField(widget=forms.HiddenInput) - self.fields["HL_text_id"] = forms.CharField(widget=forms.HiddenInput) - self.helper.layout.extend(["HL_start", "HL_end", "HL_text_id"]) - if instance != None: if instance.start_date_written: diff --git a/apis_core/apis_relations/models.py b/apis_core/apis_relations/models.py index 4634e4e..2ebb053 100644 --- a/apis_core/apis_relations/models.py +++ b/apis_core/apis_relations/models.py @@ -282,7 +282,6 @@ def get_related_entity_instancea(self): :return: An entity instance related to the current relation instance """ - print(f"{self.get_related_entity_field_namea()}") return getattr(self, self.get_related_entity_field_namea()) def get_related_entity_instanceb(self): diff --git a/apis_core/apis_relations/rel_filters.py b/apis_core/apis_relations/rel_filters.py deleted file mode 100644 index f6b6984..0000000 --- a/apis_core/apis_relations/rel_filters.py +++ /dev/null @@ -1,259 +0,0 @@ -import django_filters -from dal import autocomplete -from django.conf import settings -from django.contrib.contenttypes.models import ContentType -from django.db.models import Q -from django.urls import reverse -import operator -from functools import reduce - -from .models import AbstractRelation - - -# TODO __sresch__ : Change this whole module according to the same logic as in apis_core/apis_entities/filters.py - - -def get_excluded_fields(model): - modelname = model.__name__ - base_list = getattr(settings, "APIS_RELATIONS_FILTER_EXCLUDE", []) - rel_model_conf = getattr(settings, "APIS_RELATIONS", {}) - if "exclude" in rel_model_conf.keys(): - if isinstance(rel_model_conf["exclude"], list): - base_list.extend(rel_model_conf["exclude"]) - if modelname in rel_model_conf.keys(): - if "exclude" in rel_model_conf[modelname].keys(): - if isinstance(rel_model_conf[modelname]["exclude"], list): - base_list.extend(rel_model_conf[modelname]["exclude"]) - return set(base_list) - - -def get_included_fields(model): - modelname = model.__name__ - rel_model_conf = getattr(settings, "APIS_RELATIONS", {}) - if modelname in rel_model_conf.keys(): - return rel_model_conf[modelname].get("include", False) - else: - return False - - -FIELD_TO_FILTER = { - "ForeignKey": "MultipleChoiceFilter", - "ManyToManyField": "MultipleChoiceFilter", - "TextField": "CharFilter", - "CharField": "CharFilter", - "DateField": "DateFromToRangeFilter", - "BooleanField": "BooleanFilter", -} - - -def get_field_dicts(model, include_parents=False): - fields = [ - { - "f_name": x.name, - "f_v_name": getattr(x, "verbose_name", None), - "f_help_text": getattr(x, "helptext", None), - "f_class_name": "{}".format(x.__class__.__name__), - "f_model": getattr(x, "related_model", None), - } - for x in model._meta.get_fields(include_parents=include_parents) - ] - return fields - - -def get_filters(model, exclude=False, include=False, include_parents=False): - filters = [] - field_dicts = get_field_dicts(model, include_parents=include_parents) - for x in field_dicts: - filters.append(x["f_name"]) - if x["f_model"]: - rel_fields = get_field_dicts(x["f_model"], include_parents) - for y in rel_fields: - if "apis_relations" in "{}".format(y["f_model"]): - pass - else: - rel_field_name = "{}__{}".format(x["f_name"], y["f_name"]) - filters.append(rel_field_name) - if include: - filters = [x for x in filters if x in include] - elif exclude: - for x in exclude: - if x.startswith("*") and not x.endswith("*"): - filters = [f for f in filters if not f.lower().endswith(x[1:].lower())] - elif x.startswith("*") and x.endswith("*"): - filters = [f for f in filters if not x[1:-1].lower() in f] - elif not x.startswith("*") and x.endswith("*"): - filters = [ - f for f in filters if not f.lower().startswith(x[:-1].lower()) - ] - else: - filters = [f for f in filters if not x.lower() == f.lower()] - return filters - - -def get_generic_relation_filter(entity): - class GenericListFilter(django_filters.FilterSet): - # search = django_filters.CharFilter(method='search_filter_method') - - def name_label_filter(self, queryset, name, value): - """ - Filter for including the alternative names in the names search.\ - The types of labels included in the query are - currently hardcoded in a list. - - :param queryset: queryset that the filters are applied on - :param name: name of the attribute to filter on (not used as label types are hardcoded) - :param value: value for the filter - :return: filtered queryset - """ - alternate_names = getattr( - settings, "APIS_ALTERNATE_NAMES", ["alternative name"] - ) - res = [] - orig_value = value - for n in ["name", "label__label"]: - value = orig_value - f = "{}__".format(n) - if value.startswith('"') and value.endswith('"'): - value = value[1:-1] - else: - f += "i" - if value.startswith("*") and value.endswith("*"): - f += "contains" - value = value[1:-1] - elif value.startswith("*"): - f += "endswith" - value = value[1:] - elif value.endswith("*"): - f += "startswith" - value = value[:-1] - else: - f += "exact" - if n == "label__label": - res.append( - Q(**{f: value, "label__label_type__name__in": alternate_names}) - ) - else: - res.append(Q(**{f: value})) - return queryset.filter(res[0] | res[1]).distinct() - - def wildcard_filter(self, queryset, name, value): - f = "{}__".format(name) - if value.startswith('"') and value.endswith('"'): - value = value[1:-1] - else: - f += "i" - if value.startswith("*") and value.endswith("*"): - f += "contains" - value = value[1:-1] - elif value.startswith("*"): - f += "endswith" - value = value[1:] - elif value.endswith("*"): - f += "startswith" - value = value[:-1] - else: - f += "exact" - return queryset.filter(**{f: value}) - - def search_filter_method(self, queryset, name, value): - cls = queryset.model.__name__ - sett_filters = getattr(settings, "APIS_RELATIONS", {}) - if cls.lower() in sett_filters.keys(): - filter_attr = sett_filters[cls.lower()].get("search", ["name"]) - query = reduce( - operator.or_, [Q(**{attr: value}) for attr in filter_attr] - ) - - class Meta: - model = AbstractRelation.get_relation_class_of_name(entity) - fields = get_filters( - model, - exclude=get_excluded_fields(model), - include=get_included_fields(model), - include_parents=True, - ) - - if "apis_ampel" in settings.INSTALLED_APPS: - from apis_ampel.models import AmpelTemp - - ampel = django_filters.ChoiceFilter( - choices=AmpelTemp.ampel_choices, - field_name="ampel__status", - label="Ampel", - null_label="default", - ) - - def __init__(self, *args, **kwargs): - attrs = { - "data-placeholder": "Type to get suggestions", - "data-minimum-input-length": getattr(settings, "APIS_MIN_CHAR", 3), - "data-html": True, - } - super(GenericListFilter, self).__init__(*args, **kwargs) - for x in self.filters.keys(): - if type(self.filters[x].field).__name__ == "ModelChoiceField": - current_model_name = str( - self.filters[x].queryset.model.__name__ - ).lower() - current_qs = self.filters[x].queryset - if ( - ContentType.objects.filter( - app_label="apis_entities", model=current_model_name - ).count() - > 0 - ): - self.filters[x] = django_filters.ModelMultipleChoiceFilter( - field_name=x, - queryset=current_qs, - widget=autocomplete.ModelSelect2Multiple( - url=reverse( - "apis:apis_entities:generic_network_entities_autocomplete", - kwargs={"entity": current_model_name}, - ), - ), - ) - elif ( - ContentType.objects.filter( - app_label="apis_vocabularies", model=current_model_name - ).count() - > 0 - ): - self.filters[x] = django_filters.ModelMultipleChoiceFilter( - field_name=x, - queryset=current_qs, - widget=autocomplete.ModelSelect2Multiple( - url=reverse( - "apis:apis_vocabularies:generic_vocabularies_autocomplete", - kwargs={ - "vocab": current_model_name, - "direct": "normal", - }, - ), - ), - ) - if type(self.filters[x].field).__name__ == "DateField": - self.filters[x] = django_filters.DateFromToRangeFilter( - field_name=x, - ) - if type(self.filters[x].field).__name__ == "CharField": - self.filters[x] = django_filters.CharFilter( - lookup_expr="icontains", - field_name=x, - ) - if type(self.filters[x].field).__name__ == "ModelMultipleChoiceField": - current_model_name = str( - self.filters[x].queryset.model.__name__ - ).lower() - current_qs = self.filters[x].queryset - self.filters[x] = django_filters.ModelMultipleChoiceFilter( - field_name=x, - queryset=current_qs, - widget=autocomplete.ModelSelect2Multiple( - url=reverse( - "apis:apis_entities:generic_network_entities_autocomplete", - kwargs={"entity": current_model_name}, - ), - ), - ) - - return GenericListFilter diff --git a/apis_core/apis_relations/rel_tables.py b/apis_core/apis_relations/rel_tables.py deleted file mode 100644 index e69de29..0000000 diff --git a/apis_core/apis_relations/rel_views.py b/apis_core/apis_relations/rel_views.py index c0953b4..e69de29 100644 --- a/apis_core/apis_relations/rel_views.py +++ b/apis_core/apis_relations/rel_views.py @@ -1,63 +0,0 @@ -from django.conf import settings -from django.views.generic.detail import DetailView -from django_tables2 import RequestConfig - -from apis_core.apis_entities.views import GenericListViewNew -from apis_core.apis_relations.models import AbstractRelation -from .rel_filters import get_generic_relation_filter -from .tables import get_generic_relation_listview_table - - -class GenericRelationView(GenericListViewNew): - - context_filter_name = "filter" - paginate_by = 25 - template_name = getattr( - settings, "APIS_LIST_VIEW_TEMPLATE", "apis_entities/generic_list.html" - ) - # login_url = '/accounts/login/' - - def get_queryset(self, **kwargs): - self.entity = self.kwargs.get("entity") - qs = AbstractRelation.get_relation_class_of_name(self.entity).objects.all() - self.filter = get_generic_relation_filter(self.entity.title())( - self.request.GET, queryset=qs - ) - self.filter.form.helper = self.formhelper_class() - if callable(getattr(self.filter.qs, "filter_for_user", None)): - return self.filter.qs.filter_for_user().distinct() - else: - return self.filter.qs.distinct() - - def get_table(self, **kwargs): - relation_name = self.kwargs["entity"].lower() - self.table_class = get_generic_relation_listview_table( - relation_name=relation_name - ) - table = super(GenericListViewNew, self).get_table() - RequestConfig( - self.request, paginate={"page": 1, "per_page": self.paginate_by} - ).configure(table) - return table - - -class GenericRelationDetailView(DetailView): - - template_name = getattr( - settings, - "APIS_RELATIONS_DETAIL_VIEW_TEMPLATE", - "apis_relations/relations_detail_generic.html", - ) - - def get_object(self): - entity = self.kwargs["entity"].lower() - instance = self.kwargs["pk"].lower() - entity_model = AbstractRelation.get_relation_class_of_name(entity) - instance = entity_model.objects.get(pk=instance) - return instance - - def get_context_data(self, **kwargs): - context = super(GenericRelationDetailView, self).get_context_data() - context["entity"] = self.kwargs["entity"].lower() - context["entity_type"] = context["entity"] - return context diff --git a/apis_core/apis_relations/tables.py b/apis_core/apis_relations/tables.py index 15f7bfb..574d915 100644 --- a/apis_core/apis_relations/tables.py +++ b/apis_core/apis_relations/tables.py @@ -1,5 +1,4 @@ import django_tables2 as tables -from django.conf import settings from django.db.models import Case, When from django_tables2.utils import A @@ -103,6 +102,7 @@ def get_generic_relations_table(relation_class, entity_instance, detail=None): # create all variables which save the foreign key fields which are different for each relation class entity_class_name = entity_instance.__class__.__name__.lower() + related_entity_class_name_a = ( relation_class.get_related_entity_classa().__name__.lower() ) @@ -288,7 +288,7 @@ class Meta(RelationTableBase.Meta): """ # This fields list also defines the order of the elements. - fields = ["delete"] + RelationTableBase.Meta.fields + ["edit"] + fields = RelationTableBase.Meta.fields + ["edit", "delete"] # again reuse the fields list for ordering sequence = tuple(fields) @@ -304,12 +304,20 @@ def __init__(self, *args, **kwargs): # delete button self.base_columns["delete"] = tables.TemplateColumn( - template_name="apis_relations/delete_button_generic_ajax_form.html" + template_name="apis_relations/delete_button_generic_ajax_form.html", + orderable=False, + verbose_name="Löschen", ) # edit button self.base_columns["edit"] = tables.TemplateColumn( - template_name="apis_relations/edit_button_generic_ajax_form.html" + template_name="apis_relations/edit_button_generic_ajax_form.html", + orderable=False, + verbose_name="Bearbeiten", + extra_context={ + "site_id": entity_instance.id, + "entity_type": entity_instance.__class__.__name__.lower(), + }, ) super().__init__(*args, **kwargs) @@ -366,24 +374,8 @@ class Meta: attrs = { "class": "table table-hover table-striped table-condensed", "id": "PL_conn", - "style": "table-layout: fixed;", } - def __init__(self, **kwargs): - self.base_columns["start_date_written"].attrs = { - "th": {"class": "d-none d-lg-table-cell"}, - "td": {"class": "d-none d-lg-table-cell"}, - } - self.base_columns["end_date_written"].attrs = { - "th": {"class": "d-none d-lg-table-cell"}, - "td": {"class": "d-none d-lg-table-cell"}, - } - self.base_columns["isocode_639_3"].attrs = { - "th": {"class": "d-none d-lg-table-cell"}, - "td": {"class": "d-none d-lg-table-cell"}, - } - super().__init__(**kwargs) - class LabelTableEdit(LabelTableBase): """ @@ -391,7 +383,14 @@ class LabelTableEdit(LabelTableBase): """ edit = tables.TemplateColumn( - template_name="apis_relations/edit_button_persLabel_ajax_form.html" + template_name="apis_relations/edit_button_label_form.html", + orderable=False, + verbose_name="Bearbeiten", + ) + delete = tables.TemplateColumn( + template_name="apis_relations/delete_button_label_form.html", + orderable=False, + verbose_name="Löschen", ) class Meta(LabelTableBase.Meta): diff --git a/apis_core/apis_relations/templates/apis_relations/_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/_ajax_form.html index 06f05d4..e87d723 100644 --- a/apis_core/apis_relations/templates/apis_relations/_ajax_form.html +++ b/apis_core/apis_relations/templates/apis_relations/_ajax_form.html @@ -1,11 +1,5 @@ - -
    -
    + {% load crispy_forms_tags %} {% crispy form form.helper %} -
    - -
    - +
    -
    \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/_ajax_form_generic.html b/apis_core/apis_relations/templates/apis_relations/_ajax_form_generic.html deleted file mode 100644 index 73711c2..0000000 --- a/apis_core/apis_relations/templates/apis_relations/_ajax_form_generic.html +++ /dev/null @@ -1,11 +0,0 @@ - -
    -
    - {% load crispy_forms_tags %} - {% crispy form form.helper %} -
    - -
    - -
    -
    \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/delete_button_Uri_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/delete_button_Uri_ajax_form.html deleted file mode 100644 index 296746e..0000000 --- a/apis_core/apis_relations/templates/apis_relations/delete_button_Uri_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/delete_button_eventWork_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/delete_button_eventWork_ajax_form.html deleted file mode 100644 index d61dd36..0000000 --- a/apis_core/apis_relations/templates/apis_relations/delete_button_eventWork_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/delete_button_generic_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/delete_button_generic_ajax_form.html index b677f35..66509b3 100644 --- a/apis_core/apis_relations/templates/apis_relations/delete_button_generic_ajax_form.html +++ b/apis_core/apis_relations/templates/apis_relations/delete_button_generic_ajax_form.html @@ -1,2 +1,10 @@ -{% load apis_helpers %} - + \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/delete_button_instEvent_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/delete_button_instEvent_ajax_form.html deleted file mode 100644 index df30d88..0000000 --- a/apis_core/apis_relations/templates/apis_relations/delete_button_instEvent_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/delete_button_instInst_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/delete_button_instInst_ajax_form.html deleted file mode 100644 index b5ea1f2..0000000 --- a/apis_core/apis_relations/templates/apis_relations/delete_button_instInst_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/delete_button_instPlace_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/delete_button_instPlace_ajax_form.html deleted file mode 100644 index a4a8c33..0000000 --- a/apis_core/apis_relations/templates/apis_relations/delete_button_instPlace_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/delete_button_instWork_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/delete_button_instWork_ajax_form.html deleted file mode 100644 index c15d8a5..0000000 --- a/apis_core/apis_relations/templates/apis_relations/delete_button_instWork_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/delete_button_label_form.html b/apis_core/apis_relations/templates/apis_relations/delete_button_label_form.html new file mode 100644 index 0000000..c512937 --- /dev/null +++ b/apis_core/apis_relations/templates/apis_relations/delete_button_label_form.html @@ -0,0 +1,14 @@ + + + \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/delete_button_persEvent_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/delete_button_persEvent_ajax_form.html deleted file mode 100644 index e8c04a5..0000000 --- a/apis_core/apis_relations/templates/apis_relations/delete_button_persEvent_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/delete_button_persInstitution_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/delete_button_persInstitution_ajax_form.html deleted file mode 100644 index 6495f7f..0000000 --- a/apis_core/apis_relations/templates/apis_relations/delete_button_persInstitution_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/delete_button_persPerson_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/delete_button_persPerson_ajax_form.html deleted file mode 100644 index 28b1fb4..0000000 --- a/apis_core/apis_relations/templates/apis_relations/delete_button_persPerson_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/delete_button_persPlace_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/delete_button_persPlace_ajax_form.html deleted file mode 100644 index ada5dec..0000000 --- a/apis_core/apis_relations/templates/apis_relations/delete_button_persPlace_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/delete_button_persWork_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/delete_button_persWork_ajax_form.html deleted file mode 100644 index 311a6dd..0000000 --- a/apis_core/apis_relations/templates/apis_relations/delete_button_persWork_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/delete_button_placeEvent_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/delete_button_placeEvent_ajax_form.html deleted file mode 100644 index a416e7c..0000000 --- a/apis_core/apis_relations/templates/apis_relations/delete_button_placeEvent_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/delete_button_placePlace_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/delete_button_placePlace_ajax_form.html deleted file mode 100644 index f8c6294..0000000 --- a/apis_core/apis_relations/templates/apis_relations/delete_button_placePlace_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/delete_button_placeWork_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/delete_button_placeWork_ajax_form.html deleted file mode 100644 index 89be463..0000000 --- a/apis_core/apis_relations/templates/apis_relations/delete_button_placeWork_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/delete_button_tables_default.html b/apis_core/apis_relations/templates/apis_relations/delete_button_tables_default.html deleted file mode 100644 index f192146..0000000 --- a/apis_core/apis_relations/templates/apis_relations/delete_button_tables_default.html +++ /dev/null @@ -1,3 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/edit_button_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/edit_button_ajax_form.html deleted file mode 100644 index 2dd9532..0000000 --- a/apis_core/apis_relations/templates/apis_relations/edit_button_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/edit_button_eventWork_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/edit_button_eventWork_ajax_form.html deleted file mode 100644 index 0bcb03b..0000000 --- a/apis_core/apis_relations/templates/apis_relations/edit_button_eventWork_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/edit_button_generic_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/edit_button_generic_ajax_form.html index ae576d2..eb09043 100644 --- a/apis_core/apis_relations/templates/apis_relations/edit_button_generic_ajax_form.html +++ b/apis_core/apis_relations/templates/apis_relations/edit_button_generic_ajax_form.html @@ -1,2 +1,15 @@ {% load apis_helpers %} - + + + diff --git a/apis_core/apis_relations/templates/apis_relations/edit_button_instEvent_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/edit_button_instEvent_ajax_form.html deleted file mode 100644 index caa65d2..0000000 --- a/apis_core/apis_relations/templates/apis_relations/edit_button_instEvent_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/edit_button_instInst_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/edit_button_instInst_ajax_form.html deleted file mode 100644 index 2f6f219..0000000 --- a/apis_core/apis_relations/templates/apis_relations/edit_button_instInst_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/edit_button_instPlace_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/edit_button_instPlace_ajax_form.html deleted file mode 100644 index 9ca80c6..0000000 --- a/apis_core/apis_relations/templates/apis_relations/edit_button_instPlace_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/edit_button_instWork_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/edit_button_instWork_ajax_form.html deleted file mode 100644 index 0fff1ed..0000000 --- a/apis_core/apis_relations/templates/apis_relations/edit_button_instWork_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/edit_button_label_form.html b/apis_core/apis_relations/templates/apis_relations/edit_button_label_form.html new file mode 100644 index 0000000..5c5638f --- /dev/null +++ b/apis_core/apis_relations/templates/apis_relations/edit_button_label_form.html @@ -0,0 +1,14 @@ + + + \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/edit_button_persEvent_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/edit_button_persEvent_ajax_form.html deleted file mode 100644 index b218458..0000000 --- a/apis_core/apis_relations/templates/apis_relations/edit_button_persEvent_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/edit_button_persInst_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/edit_button_persInst_ajax_form.html deleted file mode 100644 index 36b9130..0000000 --- a/apis_core/apis_relations/templates/apis_relations/edit_button_persInst_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/edit_button_persLabel_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/edit_button_persLabel_ajax_form.html deleted file mode 100644 index 14d9b9d..0000000 --- a/apis_core/apis_relations/templates/apis_relations/edit_button_persLabel_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/edit_button_persPers_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/edit_button_persPers_ajax_form.html deleted file mode 100644 index c4052c3..0000000 --- a/apis_core/apis_relations/templates/apis_relations/edit_button_persPers_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/edit_button_persPlace_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/edit_button_persPlace_ajax_form.html deleted file mode 100644 index fca4d80..0000000 --- a/apis_core/apis_relations/templates/apis_relations/edit_button_persPlace_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/edit_button_persWork_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/edit_button_persWork_ajax_form.html deleted file mode 100644 index d2ef6df..0000000 --- a/apis_core/apis_relations/templates/apis_relations/edit_button_persWork_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/edit_button_placeEvent_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/edit_button_placeEvent_ajax_form.html deleted file mode 100644 index eb599dd..0000000 --- a/apis_core/apis_relations/templates/apis_relations/edit_button_placeEvent_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/edit_button_placePlace_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/edit_button_placePlace_ajax_form.html deleted file mode 100644 index cff81c8..0000000 --- a/apis_core/apis_relations/templates/apis_relations/edit_button_placePlace_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/edit_button_placeWork_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/edit_button_placeWork_ajax_form.html deleted file mode 100644 index dfa8f2e..0000000 --- a/apis_core/apis_relations/templates/apis_relations/edit_button_placeWork_ajax_form.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/apis_core/apis_relations/templates/apis_relations/references_button_generic_ajax_form.html b/apis_core/apis_relations/templates/apis_relations/references_button_generic_ajax_form.html deleted file mode 100644 index 8a604da..0000000 --- a/apis_core/apis_relations/templates/apis_relations/references_button_generic_ajax_form.html +++ /dev/null @@ -1,2 +0,0 @@ -{% load apis_helpers %} - diff --git a/apis_core/apis_relations/urls.py b/apis_core/apis_relations/urls.py index c1b8a8c..af22561 100644 --- a/apis_core/apis_relations/urls.py +++ b/apis_core/apis_relations/urls.py @@ -1,11 +1,15 @@ from django.urls import path -from . import rel_views from . import views app_name = "apis_relations" urlpatterns = [ + path( + "delete//", + views.delete_relation_view, + name="delete_relation", + ), path("ajax/get/", views.get_form_ajax, name="get_form_ajax"), path( "ajax/save/////", @@ -13,13 +17,8 @@ name="save_ajax_form", ), path( - "/list/", - rel_views.GenericRelationView.as_view(), - name="generic_relations_list", - ), - path( - "//detail", - rel_views.GenericRelationDetailView.as_view(), - name="generic_relations_detail_view", + "ajax/save////", + views.save_ajax_form, + name="save_ajax_form", ), ] diff --git a/apis_core/apis_relations/views.py b/apis_core/apis_relations/views.py index 8e7bba0..4c72911 100644 --- a/apis_core/apis_relations/views.py +++ b/apis_core/apis_relations/views.py @@ -1,12 +1,12 @@ -import json import re import inspect -from django.conf import settings +from apis_core.apis_metainfo.models import TempEntityClass +from django.template import loader + from django.contrib.auth.decorators import login_required from django.contrib.contenttypes.models import ContentType from django.http import HttpResponse, Http404 -from django.template.loader import render_to_string from apis_core.apis_relations import forms as relation_form_module from apis_core.apis_entities.models import ( @@ -35,6 +35,7 @@ PlaceWork, EventWork, WorkWork, + EventEvent, ) # from .forms import PersonLabelForm, InstitutionLabelForm, PlaceLabelForm, EventLabelForm @@ -42,12 +43,6 @@ form_module_list = [relation_form_module] -if "apis_highlighter" in settings.INSTALLED_APPS: - from apis_highlighter.highlighter import highlight_text_new - from apis_highlighter import forms as highlighter_form_module - - form_module_list.append(highlighter_form_module) - def turn_form_modules_into_dict(form_module_list): """ @@ -83,6 +78,7 @@ def turn_form_modules_into_dict(form_module_list): # Model-classes must be registered together with their ModelForm-classes registered_forms = { "WorkWorkForm": [WorkWork, Work, Work], + "EventEventForm": [EventEvent, Event, Event], "PersonPlaceForm": [PersonPlace, Person, Place], "PersonPlaceHighlighterForm": [PersonPlace, Person, Place], "PersonPersonForm": [PersonPerson, Person, Person], @@ -120,9 +116,11 @@ def get_form_ajax(request): FormName = request.POST.get("FormName") SiteID = request.POST.get("SiteID") + print(SiteID) ButtonText = request.POST.get("ButtonText") ObjectID = request.POST.get("ObjectID") entity_type_str = request.POST.get("entity_type") + relation_name = FormName.replace("Form", "") form_match = re.match(r"([A-Z][a-z]+)([A-Z][a-z]+)(Highlighter)?Form", FormName) form_match2 = re.match(r"([A-Z][a-z]+)(Highlighter)?Form", FormName) if FormName and form_match: @@ -159,30 +157,23 @@ def get_form_ajax(request): form_dict["relation_form"] = "{}{}".format( form_match.group(1), form_match.group(2) ) - if form_match.group(3) == "Highlighter": - form_dict["highlighter"] = True form = GenericRelationForm(**form_dict) else: form_class = form_class_dict[FormName] form = form_class(**form_dict) - tab = FormName[:-4] - data = { - "tab": tab, - "form": render_to_string( - "apis_relations/_ajax_form.html", - { - "entity_type": entity_type_str, - "form": form, - "type1": FormName, - "url2": "save_ajax_" + FormName, - "button_text": ButtonText, - "ObjectID": ObjectID, - "SiteID": SiteID, - }, - ), + template = loader.get_template("apis_relations/_ajax_form.html") + form_context = { + "entity_type": entity_type_str, + "form": form, + "form_name": FormName, + "relation_name": relation_name, + "url2": "save_ajax_" + FormName, + "button_text": ButtonText, + "ObjectID": ObjectID, + "SiteID": SiteID, } - return HttpResponse(json.dumps(data), content_type="application/json") + return HttpResponse(template.render(form_context, request)) @login_required @@ -190,16 +181,9 @@ def save_ajax_form(request, entity_type, kind_form, SiteID, ObjectID=False): """Tests validity and saves AjaxForms, returns them when validity test fails""" if kind_form not in registered_forms.keys(): raise Http404 - - button_text = "create/modify" - - if not ObjectID: - instance_id = "" - else: - instance_id = ObjectID entity_type_str = entity_type entity_type = AbstractEntity.get_entity_class_of_name(entity_type) - + object_id = ObjectID form_match = re.match(r"([A-Z][a-z]+)([A-Z][a-z]+)?(Highlighter)?Form", kind_form) form_dict = {"data": request.POST, "entity_type": entity_type, "request": request} @@ -208,43 +192,24 @@ def save_ajax_form(request, entity_type, kind_form, SiteID, ObjectID=False): app_label="apis_relations", ) tab = re.match(r"(.*)Form", kind_form).group(1) - call_function = "EntityRelationForm_response" if test_form_relations.count() > 0: relation_form = test_form_relations[0].model_class() form_dict["relation_form"] = relation_form - if form_match.group(3) == "Highlighter": - form_dict["highlighter"] = True - tab = form_match.group(1) + form_match.group(2) - call_function = "HighlForm_response" form = GenericRelationForm(**form_dict) else: form_class = form_class_dict[kind_form] form = form_class(**form_dict) if form.is_valid(): site_instance = entity_type.objects.get(pk=SiteID) - set_ann_proj = request.session.get("annotation_project", 1) - entity_types_highlighter = request.session.get("entity_types_highlighter") - users_show = request.session.get("users_show_highlighter", None) - hl_text = None - if ObjectID: - instance = form.save(instance=ObjectID, site_instance=site_instance) + + if object_id: + form.save(instance=object_id, site_instance=site_instance) else: - instance = form.save(site_instance=site_instance) - right_card = True + form.save(site_instance=site_instance) if test_form_relations.count() > 0: table_html = form.get_html_table( entity_type_str, request, site_instance, form_match ) - if "Highlighter" in tab or form_match.group(3) == "Highlighter": - hl_text = { - "text": highlight_text_new( - form.get_text_id(), - users_show=users_show, - set_ann_proj=set_ann_proj, - types=entity_types_highlighter, - )[0].strip(), - "id": form.get_text_id(), - } if tab == "PersonLabel": table_html = LabelTableEdit( data=site_instance.label_set.all(), prefix="PL-" @@ -253,62 +218,18 @@ def save_ajax_form(request, entity_type, kind_form, SiteID, ObjectID=False): table_html = LabelTableEdit( data=site_instance.label_set.all(), prefix="IL-" ) - elif tab == "PersonResolveUri": - table_html = EntityUriTable( - Uri.objects.filter(entity=site_instance), prefix="PURI-" - ) - - elif ( - tab == "AddRelationHighlighterPerson" - or tab == "PlaceHighlighter" - or tab == "PersonHighlighter" - or tab == "SundayHighlighter" - ): - table_html = None - right_card = False - call_function = "PAddRelation_response" - instance = None - if instance: - instance2 = instance.get_web_object() - else: - instance2 = None if table_html: table_html2 = table_html.as_html(request) else: table_html2 = None - data = { - "test": True, - "tab": tab, - "call_function": call_function, - "instance": instance2, - "table_html": table_html2, - "text": hl_text, - "right_card": right_card, - } + return HttpResponse(table_html2) else: - if "Highlighter" in tab: - call_function = "HighlForm_response" - data = { - "test": False, - "call_function": call_function, - "DivID": "div_" + kind_form + instance_id, - "form": render_to_string( - "apis_relations/_ajax_form.html", - context={ - "entity_type": entity_type_str, - "form": form, - "type1": kind_form, - "url2": "save_ajax_" + kind_form, - "button_text": button_text, - "ObjectID": ObjectID, - "SiteID": SiteID, - }, - request=request, - ), - } + template = loader.get_template("apis_relations/_ajax_form.html") + return HttpResponse(template.render({"form": form}, request)) + - # except Exception as e: - # print('Error in save method') - # print(e) - # data = {'test': False, 'error': json.dumps(str(e))} - return HttpResponse(json.dumps(data), content_type="application/json") +@login_required +def delete_relation_view(request, relation_id): + instance = TempEntityClass.objects.get(id=relation_id) + instance.delete() + return HttpResponse(f"gelöschte Verbindung: {relation_id} ") diff --git a/apis_core/apis_tei/tei.py b/apis_core/apis_tei/tei.py index 9ac1c3a..f65c3f4 100644 --- a/apis_core/apis_tei/tei.py +++ b/apis_core/apis_tei/tei.py @@ -355,8 +355,6 @@ def build_annotated_texts_objects(self): ) this_entity_texts = {t for t in this_entity.text.all() if t.text} - print([text.id for text in this_entity_texts]) - # Then, check all the entity texts to see whether it's an annotated one; # otherwise, we'll need to include it here... for text in this_entity_texts: diff --git a/dumper/forms.py b/dumper/forms.py new file mode 100644 index 0000000..ca288d8 --- /dev/null +++ b/dumper/forms.py @@ -0,0 +1,13 @@ +from django import forms +from crispy_forms.helper import FormHelper +from crispy_forms.layout import Submit + + +class form_user_login(forms.Form): + username = forms.CharField(label="Username", widget=forms.TextInput) + password = forms.CharField(label="Password", widget=forms.PasswordInput) + + def __init__(self, *args, **kwargs): + super(form_user_login, self).__init__(*args, **kwargs) + self.helper = FormHelper() + self.helper.add_input(Submit("submit", "login")) diff --git a/dumper/templates/dumper/index.html b/dumper/templates/dumper/index.html index 997cb2a..287bb65 100644 --- a/dumper/templates/dumper/index.html +++ b/dumper/templates/dumper/index.html @@ -18,7 +18,7 @@

    Personen der Moderne Basis

    - +

    @@ -28,7 +28,7 @@

    {{ person_count }} Personen

    - +

    @@ -38,7 +38,7 @@

    {{ place_count }} Orte

    - +

    @@ -50,7 +50,7 @@

    {{ work_count }} Werke

    - +

    @@ -60,7 +60,7 @@

    {{ event_count }} Ereignisse

    - +

    diff --git a/dumper/templates/dumper/user_login.html b/dumper/templates/dumper/user_login.html new file mode 100644 index 0000000..bb2fca1 --- /dev/null +++ b/dumper/templates/dumper/user_login.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} +{% block content %} +
    +
    + {% if form.errors %} +

    Please correct the error{{ form.errors|pluralize }} below.

    + {% endif %} + {% load crispy_forms_tags %} + {% crispy form form.helper %} +
    +{% endblock %} \ No newline at end of file diff --git a/dumper/templates/dumper/user_logout.html b/dumper/templates/dumper/user_logout.html new file mode 100644 index 0000000..289527e --- /dev/null +++ b/dumper/templates/dumper/user_logout.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} +{% load static %} +{% block title %} Logout {% endblock %} +{% block content %} +
    +

    Baba und foi ned

    +

    Küss die Hand und auf Wiederschaun

    +
    +{% endblock content %} \ No newline at end of file diff --git a/dumper/urls.py b/dumper/urls.py index c4acacf..09436e4 100644 --- a/dumper/urls.py +++ b/dumper/urls.py @@ -1,12 +1,14 @@ from django.urls import path from django.conf import settings -from dumper.views import HomePageView +from dumper import views app_name = "dumper" urlpatterns = [ - path("", HomePageView.as_view(), name="home"), + path("", views.HomePageView.as_view(), name="home"), + path("login/", views.user_login, name="user_login"), + path("logout/", views.user_logout, name="user_logout"), ] if settings.DEBUG: diff --git a/dumper/views.py b/dumper/views.py index e1896a3..544a4b9 100644 --- a/dumper/views.py +++ b/dumper/views.py @@ -1,7 +1,12 @@ from django.views.generic.base import TemplateView +from django.http import HttpResponse, HttpResponseRedirect +from django.shortcuts import render +from django.contrib.auth import authenticate, login, logout from apis_core.apis_entities.models import Person, Place, Event, Work, Institution from apis_core.apis_metainfo.models import Uri +from .forms import form_user_login + class HomePageView(TemplateView): @@ -16,3 +21,23 @@ def get_context_data(self, *args, **kwargs): context["institution_count"] = Institution.objects.all().count() context["uri_count"] = Uri.objects.all().count() return context + + +def user_login(request): + if request.method == "POST": + form = form_user_login(request.POST) + if form.is_valid(): + cd = form.cleaned_data + user = authenticate(username=cd["username"], password=cd["password"]) + if user and user.is_active: + login(request, user) + return HttpResponseRedirect(request.GET.get("next", "/")) + return HttpResponse("user does not exist") + else: + form = form_user_login() + return render(request, "dumper/user_login.html", {"form": form}) + + +def user_logout(request): + logout(request) + return render(request, "dumper/user_logout.html") diff --git a/pmb/settings.py b/pmb/settings.py index acd9069..5755aaa 100644 --- a/pmb/settings.py +++ b/pmb/settings.py @@ -19,11 +19,12 @@ APIS_LIST_VIEWS_ALLOWED = True APIS_DETAIL_VIEWS_ALLOWED = True - +DJANGO_TABLES2_TEMPLATE = "django_tables2/bootstrap5.html" # Application definition INSTALLED_APPS = [ + "apis_override_select2js", "dal", "dal_select2", "django.contrib.admin", @@ -55,11 +56,14 @@ "django_extensions", ] +CSRF_USE_SESSIONS = True + + MIDDLEWARE = [ - "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.security.SecurityMiddleware", "django.middleware.common.CommonMiddleware", - "django.middleware.csrf.CsrfViewMiddleware", + # "django.middleware.csrf.CsrfViewMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", @@ -139,7 +143,7 @@ USE_L10N = True USE_TZ = True -USE_THOUSAND_SEPARATOR = True +USE_THOUSAND_SEPARATOR = False # Static files (CSS, JavaScript, Images) diff --git a/requirements.txt b/requirements.txt index 886571e..247c843 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +apis-override-select2js-0.1 acdh-django-browsing acdh-id-reconciler>=0.2,<1 acdh-tei-pyutils>=0.34,<1 @@ -16,3 +17,4 @@ psycopg2 pyocclient==0.6 PyYAML>=6.0.1,<7 rdflib +icecream \ No newline at end of file diff --git a/static/css/style.css b/static/css/style.css index dd839e3..69e833a 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -9,9 +9,13 @@ --uri: #e80d0d; } +.select2-container .select2-selection--single { + min-height: 2.2rem; +} a { - color: var(--pmb) + color: var(--pmb); + text-decoration: unset; } a:hover { diff --git a/templates/base.html b/templates/base.html index b11f30b..e74e034 100644 --- a/templates/base.html +++ b/templates/base.html @@ -15,9 +15,28 @@ - {% block scripts2 %} {% endblock scripts2 %} + +{% block scripts %} +{% endblock %} \ No newline at end of file diff --git a/templates/partials/navbar.html b/templates/partials/navbar.html index ec7faa9..7eb5d56 100644 --- a/templates/partials/navbar.html +++ b/templates/partials/navbar.html @@ -33,31 +33,31 @@ {% if user.is_authenticated %} - + {% else %} - + {% endif %}