Skip to content

Commit

Permalink
App Toolbox: Integration LaTeX-Projekt (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdmhrogut authored Oct 2, 2023
1 parent 38acc4f commit 6dfb690
Show file tree
Hide file tree
Showing 33 changed files with 1,154 additions and 32 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"enableMapLocate": true,
"featureGeometry": true,
"fetchGeoJsonFeatureCollection": true,
"fetchPdf": true,
"filterApplication": true,
"filterReset": true,
"getFeatureCenter": true,
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ db.sqlite3

# Datenwerft.HRO
datenwerft/secrets.py
datenmanagement/migrations
hilfe/build
/static
/uploads
Expand Down
2 changes: 1 addition & 1 deletion .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"rules": {
"property-no-vendor-prefix": null
}
}
}
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,3 @@ Affirmer's express Statement of Purpose.

For more information, please see
<http://creativecommons.org/publicdomain/zero/1.0/>

9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Web-Anwendung zur einfachen Erfassung von Geodaten, die auf [*Django*](https://w
* [*GDAL*](https://gdal.org/)
* [*PostgreSQL*](https://www.postgresql.org/) mit der Erweiterung [*PostGIS*](https://postgis.net/)
* [*npm*](https://www.npmjs.com/)
* für App _Toolbox_ siehe [hier](toolbox/README.md)

## Installation

Expand All @@ -30,7 +31,7 @@ Web-Anwendung zur einfachen Erfassung von Geodaten, die auf [*Django*](https://w

5. leere *PostgreSQL*-Datenbank für die Anwendungsadministration anlegen
6. leere *PostgreSQL*-Datenbank mit der Erweiterung *PostGIS* für die App *BEMAS* anlegen
6. leere *PostgreSQL*-Datenbank mit der Erweiterung *PostGIS* für die App *Datenmanagement* anlegen
7. leere *PostgreSQL*-Datenbank mit der Erweiterung *PostGIS* für die App *Datenmanagement* anlegen

## Konfiguration

Expand Down Expand Up @@ -118,6 +119,10 @@ Für die App *BEMAS* kann optional ein Cronjob eingerichtet werden, der folgende

Dieser Befehl führt dazu, dass alle Personen gelöscht werden, die nicht als Ansprechpartner:innen mit Organisationen verknüpft sind, nicht als Betreiber:innen mit Verursachern verknüpft sind und die als Beschwerdeführer:innen nur noch mit Beschwerden verknüpft sind, die seit `BEMAS_STATUS_CHANGE_DEADLINE_DAYS` (siehe `secrets.template`) abgeschlossen sind.

## PDF-Export mit eigenen Templates

Für den Export von PDF-Dateien mit eigenen Templates aus der App *Datenmanagement* mittels der App *Toolbox* siehe [hier](toolbox/README.md).

## Entwicklung

### Grundsätzliches
Expand Down Expand Up @@ -228,4 +233,4 @@ Bei Commits und Pull-Requests in der Branch `master` werden folgende *GitHub*-Ac

1. *CodeQL:* CodeQL-Analyse gemäß `.github/workflows/codeql.yml`
2. *Linting:* Linting gemäß `.github/workflows/linting.yml`
3. *Tests:* Tests gemäß `.github/workflows/tests.yml`
3. *Tests:* Tests gemäß `.github/workflows/tests.yml`
28 changes: 28 additions & 0 deletions datenmanagement/static/datenmanagement/js/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,34 @@ function formatData(data, brReplacement) {
return data.trim(); // remove any remaining whitespaces from both sides
}

/**
* @function
* @name fetchPdf
*
* fetches PDF file
*
* @param {string} url - URL
* @param {string} csrfToken - CSRF token
* @param {string} host - host
*/
function fetchPdf(url, csrfToken, host){
const response = fetch(
url, {
method: 'POST',
headers: {
contentType: 'application/json',
'X-CSRFToken': csrfToken
},
redirect: 'follow',
origin: host,
referrerPolicy: 'no-referrer',
body: JSON.stringify(window.renderParams)
}
);
response.then(response => response.blob())
.then(myblob => window.open(URL.createObjectURL(myblob)));
}

/**
* @function
* @name initDataTable
Expand Down
53 changes: 52 additions & 1 deletion datenmanagement/templates/datenmanagement/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ <h4 class="mt-3">
<a class="btn btn-warning" role="button" href="{{ url_back }}"><i class="fas fa-backward"></i> zurück</a>
</div>
{% if objects_count > 0 %}
{% if suitables|length > 0 %}
<div class="mt-1">
<label hidden for="template-selector" class="form-label">mit Vorlage</label>
<select name="template-selector" id="template-selector" class="form-select align-middle w-auto d-inline">
{% for suit in suitables %}
<option value={{ suit.id }}>{{ suit.template.name }}</option>
{% endfor %}
</select>
<button type="button" class="btn btn-secondary" id="template-button">exportieren</button>
<label for="onlyactive">inaktive auch exportieren: </label><input type="checkbox" class="form-checkbox-input ms-1" id="onlyactive">
</div>
{% endif %}
<div class="d-grid mt-5{% if not actions %} mb-3{% endif %} gap-2 mx-auto">
{% if subset_id %}
<div class="alert alert-danger alert-dismissible fade show" role="alert">
Expand Down Expand Up @@ -75,6 +87,7 @@ <h4 class="mt-3">
window.dataUrl = '{{ url_model_tabledata }}';
{% endif %}
window.languageUrl = '{% static 'datatables/datatables.german.lang' %}';
window.checkAllTarget = true;
</script>
<script>
/**
Expand Down Expand Up @@ -126,9 +139,46 @@ <h4 class="mt-3">
'Bei der Übernahme der aktuellen Filtermenge auf die Karte ist ein Serverfehler aufgetreten.'
);
});

// fetch PDF file on clicking the "OK" button in the PDF export confirmation modal...
$('#confirm-export-modal-ok').on('click', () => fetchPdf(
'{% url "toolbox:renderpdf" %}', '{{ csrf_token }}', '{{ request.get_host }}'
));

// fetch PDF file on clicking the PDF export button...
$('#template-button').on('click', function() {
let checkedBoxes = $('.action-checkbox').filter(':checked');
let tplSelector = $('#template-selector');
let desiredTplId = tplSelector.value;
window.renderParams= {
'pks': [],
'templateid': desiredTplId,
'datenthema': '{{ model_name }}',
'onlyactive': !$('#onlyactive').prop('checked'),
};
if (checkedBoxes.length > 0) {
for (let i = 0; i < checkedBoxes.length; i++)
window.renderParams.pks.push(checkedBoxes[i].value);
fetchPdf(
'{% url "toolbox:renderpdf" %}', '{{ csrf_token }}', '{{ request.get_host }}'
);
}
else {
$('#confirm-export-modal').modal('toggle');
}
});

// select or unselect all rows (= records)
$('#check-all').on('click', function() {
let target = window.checkAllTarget;
$('.action-checkbox').each(function() {
$(this).prop('checked', target);
});
window.checkAllTarget = !target;
});
});

// as soon as a row (= record) has been selected or deselected...
// as soon as a row (= record) has been selected or unselected...
$('body').on('change', '.action-checkbox', function() {
let actionCheckboxes = $('.action-checkbox').filter(':checked');
// adjust information texts accordingly
Expand Down Expand Up @@ -157,5 +207,6 @@ <h4 class="mt-3">
</div>
{% endif %}
{% include "modal-error.html" %}
{% include "modal-confirm-export.html" with objcount=objects_count %}
{% endif %}
{% endblock %}
5 changes: 5 additions & 0 deletions datenmanagement/views/views_list_map.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import date, datetime, timezone
from decimal import Decimal
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.core.serializers import serialize
from django.urls import reverse
from django.utils.html import escape
Expand All @@ -13,6 +14,7 @@
from zoneinfo import ZoneInfo

from datenmanagement.utils import get_data, get_thumb_url, localize_number
from toolbox.models import SuitableFor
from toolbox.utils import optimize_datatable_filter
from .functions import add_basic_model_context_elements, add_user_agent_context_elements, \
get_model_objects
Expand Down Expand Up @@ -277,6 +279,9 @@ def get_context_data(self, **kwargs):
else:
context['objects_count'] = get_model_objects(self.model, None, True)
context['url_back'] = reverse('datenmanagement:' + model_name + '_start')
content_type = ContentType.objects.get_for_model(self.model)
suitable_templates = SuitableFor.objects.filter(datenthema=content_type)
context['suitables'] = suitable_templates
return context


Expand Down
17 changes: 17 additions & 0 deletions datenwerft/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,23 @@
}


# Toolbox app:
# PDF export

PDF_ESCAPE = [
('&', r'\&'),
(chr(8211), '--')
]
PDF_JINJASTRINGS = {
'block_start': r'\JINJA{',
'block_end': '}',
'variable_start': r'\VAR{',
'variable_end': '}',
'comment_start': r'\JCMNT{',
'comment_end': '}'
}


# configuration file with additional parameters
# which must not fall under Git version control

Expand Down
17 changes: 17 additions & 0 deletions datenwerft/templates/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "navbar.html" %}
{% load static %}

{% block title %}{{ error_code }} | {% endblock %}

{% block content %}
<div class="mt-4 text-center">
<img class="mx-auto col-{% if request.user_agent.is_mobile %}4{% else %}1{% endif %} me-2 main-logo" src="{% static 'img/logo.svg' %}" alt="Logo">
<img class="mx-auto col-{% if request.user_agent.is_mobile %}4{% else %}1{% endif %} ms-2 main-logo" src="{% static 'img/rostock.svg' %}" alt="Rostock">
</div>
<div class="d-grid mt-4 mx-auto">
<h2 class="text-center"><strong>{{ error_code }} – <em>{{ error_text }}</em></strong></h2>
</div>
<div class="d-grid mt-4 mx-auto">
<h5 class="text-center">{{ error_message }}</h5>
</div>
{% endblock %}
28 changes: 14 additions & 14 deletions datenwerft/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ <h5 class="card-title">Metadatenpflege</h5>
</div>
</div>
{% else %}
<div class="mt-4 text-center">
<img class="mx-auto col-{% if request.user_agent.is_mobile %}4{% else %}1{% endif %} me-2 main-logo" src="{% static 'img/logo.svg' %}" alt="Logo">
<img class="mx-auto col-{% if request.user_agent.is_mobile %}4{% else %}1{% endif %} ms-2 main-logo" src="{% static 'img/rostock.svg' %}" alt="Rostock">
</div>
<div class="d-grid mt-4 mx-auto">
<h2 class="text-center">
Willkommen bei <em><strong>Datenwerft.HRO,</strong></em><br>
der Web-Anwendung zur Datenerfassung<br>
der Hanse- und Universitätsstadt Rostock!
</h2>
</div>
<div class="d-grid col-{% if request.user_agent.is_mobile %}8{% else %}3{% endif %} mt-4 mx-auto">
<a class="btn btn-lg btn-primary" role="button" href="{% url 'accounts:login' %}"><i class="fas fa-right-to-bracket"></i> Anmeldung</a>
</div>
<div class="mt-4 text-center">
<img class="mx-auto col-{% if request.user_agent.is_mobile %}4{% else %}1{% endif %} me-2 main-logo" src="{% static 'img/logo.svg' %}" alt="Logo">
<img class="mx-auto col-{% if request.user_agent.is_mobile %}4{% else %}1{% endif %} ms-2 main-logo" src="{% static 'img/rostock.svg' %}" alt="Rostock">
</div>
<div class="d-grid mt-4 mx-auto">
<h2 class="text-center">
Willkommen bei <em><strong>Datenwerft.HRO,</strong></em><br>
der Web-Anwendung zur Datenerfassung<br>
der Hanse- und Universitätsstadt Rostock!
</h2>
</div>
<div class="d-grid col-{% if request.user_agent.is_mobile %}8{% else %}3{% endif %} mt-4 mx-auto">
<a class="btn btn-lg btn-primary" role="button" href="{% url 'accounts:login' %}"><i class="fas fa-right-to-bracket"></i> Anmeldung</a>
</div>
{% endif %}
{% endblock %}
19 changes: 19 additions & 0 deletions datenwerft/templates/modal-confirm-export.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div id="confirm-export-modal" class="modal" tabindex="-1"> <!-- aria-labelledby?-->
<div class="modal-dialog">
<div class="modal-content">
<div id="confirm-export-modal-header" class="modal-header">
<h5 id="confirmexport-modal-title" class="modal-title">alle Datensätze exportieren?</h5>
</div>
<div id="confirm-export-modal-body" class="modal-body">
<div class="text-center">
<p>Sie haben keinen Eintrag ausgewählt. Es werden also alle vorhandenen Datensätze dieses Datenthemas exportiert. Dies kann lange dauern und ungewollt große Dokumente erzeugen.</p>
<p><strong>{{ objcount }} Datensätze werden exportiert.</strong></p>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="confirm-export-modal-ok" data-bs-dismiss="modal">Export durchführen</button>
<button type="button" class="btn btn-warning" id="confirm-export-modal-cancel" data-bs-dismiss="modal">abbrechen</button>
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion datenwerft/templates/modal-error.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="modal-dialog">
<div class="modal-content">
<div id="error-modal-header" class="modal-header">
<h5 id="error-modal-title" class="modal-title"></h5>
<h5 id="error-modal-title" class="modal-title"></h5>
</div>
<div id="error-modal-body" class="modal-body"></div>
<div class="modal-footer">
Expand Down
2 changes: 1 addition & 1 deletion datenwerft/templates/modal-loading.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="modal-dialog">
<div class="modal-content">
<div id="loading-modal-header" class="modal-header">
<h5 id="loading-modal-title" class="modal-title"></h5>
<h5 id="loading-modal-title" class="modal-title"></h5>
</div>
<div id="loading-modal-body" class="modal-body">
<span id="loading-modal-body-text"></span>
Expand Down
13 changes: 12 additions & 1 deletion datenwerft/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@
from datenmanagement import urls as datenmanagement_urls
from bemas import urls as bemas_urls

from .views import IndexView
from .views import IndexView, error_400, error_403, error_404, error_405, error_410, \
error_500, error_501, error_502, error_503

handler400 = error_400
handler403 = error_403
handler404 = error_404
handler405 = error_405
handler410 = error_410
handler500 = error_500
handler501 = error_501
handler502 = error_502
handler503 = error_503

api_urlpatterns = []
api_urlpatterns += accounts_urls.api_urlpatterns
Expand Down
Loading

0 comments on commit 6dfb690

Please sign in to comment.