-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from forza-mor-rotterdam/django-4.2
Django 4.2 update
- Loading branch information
Showing
21 changed files
with
389 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AuthorisatieConfig(AppConfig): | ||
name = "apps.authorisatie" | ||
verbose_name = "Authorisatie" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class BeheerConfig(AppConfig): | ||
name = "apps.beheer" | ||
verbose_name = "Beheer" |
68 changes: 68 additions & 0 deletions
68
app/apps/beheer/templates/django/forms/widgets/checkbox_select.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{% load file_exists from main_tags %} | ||
{% load l10n %} | ||
{% with id=widget.attrs.id %} | ||
<div class="form-row {{ classes.label }} {{ classes.value }} {{ classes.single_value }}"> | ||
{% if id and not widget.attrs.hideLabel %} | ||
<h3 class="label {% if widget.attrs.hasMoreInfo and widget.help_text %}has-more-info{% endif %}"> | ||
{{ widget.label }}{{ widget.attrs.hideLabel }} | ||
</h3> | ||
{% endif %} | ||
{% if widget.attrs.hasMoreInfo and widget.help_text %} | ||
<div class="foldout--info" data-controller="utils"> | ||
<h4 class="summary" | ||
data-action="click->utils#foldOut" | ||
aria-label="Meer info">{% include "icons/info-filled.svg" %}</h4> | ||
<p>{{ widget.help_text|safe }}</p> | ||
</div> | ||
{% endif %} | ||
{% if widget.attrs.showSelectAll %} | ||
<div class="container__buttons"> | ||
<button class="btn btn-textlink btn-inline" | ||
data-action="selectAll#selectAll" | ||
data-selectAll-filter-type-param="all">Selecteer alles</button> | ||
| | ||
<button class="btn btn-inline" data-action="selectAll#selectAll">Selecteer niets</button> | ||
</div> | ||
{% endif %} | ||
<div id="{{ id }}"> | ||
<ul class="{% if widget.attrs.classList %}{{ widget.attrs.classList }}{% else %}list--form-check-input{% endif %}"> | ||
{% for group, options, index in widget.optgroups %} | ||
{% if group %} | ||
<li> | ||
{{ group }} | ||
<ul {% if id %}id="{{ id }}_{{ index }}"{% endif %}> | ||
{% endif %} | ||
{% for option in options %} | ||
<li class="{% if widget.required and form.required_css_class %}{{ form.required_css_class }}{% endif %}"> | ||
<div class="form-check"> | ||
{% include "django/forms/widgets/input.html" with widget=option %} | ||
<label class="form-check-label" | ||
for="{{ option.attrs.id }}" | ||
{% if option.selected %}checked{% endif %} | ||
{% if widget.required %}required{% endif %} | ||
{% include "django/forms/widgets/attrs.html" %}> | ||
{% if widget.attrs.hasIcon %} | ||
{% with option.label|slugify as slugged_option_label %} | ||
{% with "icons/afdelingen/"|add:slugged_option_label|add:".svg" as icon_path %} | ||
{% if icon_path|file_exists %} | ||
{% include icon_path %} | ||
{% else %} | ||
{% include "icons/noimage.svg" %} | ||
{% endif %} | ||
{% endwith %} | ||
{% endwith %} | ||
{% endif %} | ||
{{ option.label }} | ||
</label> | ||
</div> | ||
</li> | ||
{% endfor %} | ||
{% if group %} | ||
</ul> | ||
</li> | ||
{% endif %} | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
</div> | ||
{% endwith %} |
26 changes: 26 additions & 0 deletions
26
app/apps/beheer/templates/django/forms/widgets/checkbox_select_old.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{% with id=widget.attrs.id %} | ||
<div {% if id %}id="{{ id }}"{% endif %}> | ||
<ul {% if widget.attrs.classList %}class="{{ widget.attrs.classList }}"{% endif %}> | ||
{% for group, options, index in widget.optgroups %} | ||
{% if group %} | ||
<li> | ||
{{ group }} | ||
<ul {% if id %}id="{{ id }}_{{ index }}"{% endif %}> | ||
{% endif %} | ||
{% for option in options %} | ||
<li> | ||
<div class="form-check"> | ||
{% include "django/forms/widgets/input.html" with widget=option %} | ||
<label {% if option.attrs.id %}for="{{ option.attrs.id }}"{% endif %} | ||
class="form-check-label">{{ option.label }}</label> | ||
</div> | ||
</li> | ||
{% endfor %} | ||
{% if group %} | ||
</ul> | ||
</li> | ||
{% endif %} | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
{% endwith %} |
30 changes: 30 additions & 0 deletions
30
app/apps/beheer/templates/django/forms/widgets/clearable_file_input.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<div data-controller="bijlagen"> | ||
<button type="button" | ||
class="btn btn-secondary btn-files" | ||
id="buttonFile_{{ field.auto_id }}" | ||
data-action="bijlagen#showFileInput"> | ||
<svg width="32" | ||
height="32" | ||
viewBox="0 0 32 32" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg"> | ||
<path fill-rule="evenodd" clip-rule="evenodd" d="M17 6H15V15H6V17H15V26H17V17H26V15H17V6Z" fill="#fff" /> | ||
</svg> | ||
<span> | ||
{% if field.field.widget.attrs.button_text %} | ||
{{ field.field.widget.attrs.button_text }} | ||
{% else %} | ||
Foto toevoegen | ||
{% endif %} | ||
</span> | ||
</button> | ||
{% if field.help_text %}<p class="help-block">{{ field.help_text|safe }}</p>{% endif %} | ||
{% for error in field.errors %} | ||
<span class="help-block invalid-text {{ form.error_css_class }}">{{ error }}</span> | ||
{% endfor %} | ||
<div class="file-upload multiple hidden" tabindex="1"> | ||
<div class="file-upload-mask">Sleep één of meer bestanden hier naartoe, of klik hier om bestanden te uploaden</div> | ||
{% include "django/forms/widgets/input.html" %} | ||
<div id="imagesPreview" class="preview"></div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<div> | ||
<button type="button" | ||
class="btn btn-secondary btn-files" | ||
id="buttonFile_{{ field.auto_id }}" | ||
data-action="bijlagen#showFileInput"> | ||
<svg width="32" | ||
height="32" | ||
viewBox="0 0 32 32" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg"> | ||
<path fill-rule="evenodd" clip-rule="evenodd" d="M17 6H15V15H6V17H15V26H17V17H26V15H17V6Z" fill="#fff" /> | ||
</svg> | ||
<span> | ||
{% if field.field.widget.attrs.button_text %} | ||
{{ field.field.widget.attrs.button_text }} | ||
{% else %} | ||
Foto toevoegen | ||
{% endif %} | ||
</span> | ||
</button> | ||
{% if field.help_text %}<p class="help-block">{{ field.help_text|safe }}</p>{% endif %} | ||
{% for error in field.errors %} | ||
<span class="help-block invalid-text {{ form.error_css_class }}">{{ error }}</span> | ||
{% endfor %} | ||
<div class="file-upload multiple hidden" tabindex="1"> | ||
<div class="file-upload-mask">Sleep één of meer bestanden hier naartoe, of klik hier om bestanden te uploaden</div> | ||
{% include "django/forms/widgets/input.html" %} | ||
<div id="imagesPreview" class="preview"></div> | ||
</div> | ||
</div> |
19 changes: 19 additions & 0 deletions
19
app/apps/beheer/templates/django/forms/widgets/multiple_input.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{% with id=widget.attrs.id %} | ||
<ul {% if id %}id="{{ id }}"{% endif %} | ||
{% if widget.attrs.class %}class="{{ widget.attrs.class }}"{% endif %}> | ||
{% for group, options, index in widget.optgroups %} | ||
{% if group %} | ||
<li> | ||
{{ group }} | ||
<ul {% if id %}id="{{ id }}_{{ index }}"{% endif %}> | ||
{% endif %} | ||
{% for option in options %} | ||
<li>{% include option.template_name with widget=option %}</li> | ||
{% endfor %} | ||
{% if group %} | ||
</ul> | ||
</li> | ||
{% endif %} | ||
{% endfor %} | ||
</ul> | ||
{% endwith %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
{% include "django/forms/widgets/input.html" %} | ||
<label class="form-check-label ms-1" | ||
{% if widget.attrs.id %}for="{{ widget.attrs.id }}"{% endif %}>{{ widget.label }}</label> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import json | ||
import logging | ||
import os | ||
|
||
import requests | ||
import urllib3 | ||
from django import template | ||
from django.conf import settings | ||
from django.contrib.gis.geos import Point | ||
from django.core.cache import cache | ||
from django.utils.html import strip_tags | ||
from requests import Request, Response | ||
|
||
register = template.Library() | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@register.filter | ||
def replace_comma_by_dot(value): | ||
return str(value).replace(",", ".") | ||
|
||
|
||
@register.filter | ||
def to_timestamp(value): | ||
try: | ||
return int(value.timestamp()) | ||
except Exception as e: | ||
logger.error(f"No datatime instance, value={value}: error={e}") | ||
|
||
|
||
@register.filter | ||
def json_encode(value): | ||
if isinstance(value, Point): | ||
return value.geojson | ||
return json.dumps(value) | ||
|
||
|
||
@register.filter | ||
def json_loads(value): | ||
try: | ||
return json.loads(value) | ||
except (json.JSONDecodeError, TypeError): | ||
return None | ||
|
||
|
||
@register.filter | ||
def replace_n(value): | ||
return value.replace("\\n", "<br/>").replace("?", "?<br/>") | ||
|
||
|
||
@register.simple_tag | ||
def vind_in_dict(op_zoek_dict, key): | ||
if not isinstance(op_zoek_dict, dict): | ||
return key | ||
result = op_zoek_dict.get(key, op_zoek_dict.get(str(key), key)) | ||
if isinstance(result, (list, tuple)): | ||
return result[0] | ||
return result | ||
|
||
|
||
@register.filter | ||
def adres_order_nummer(taak, taken_sorted): | ||
return taken_sorted.get(taak.id, taak.id) | ||
|
||
|
||
@register.filter | ||
def mor_core_url(initial_url, signed_data=None): | ||
return ( | ||
f"{settings.MOR_CORE_URL_PREFIX}{initial_url}?signed-data={signed_data}" | ||
if signed_data | ||
else f"{settings.MOR_CORE_URL_PREFIX}{initial_url}" | ||
) | ||
|
||
|
||
@register.filter | ||
def mor_core_protected_url(initial_url): | ||
return f"{settings.MOR_CORE_PROTECTED_URL_PREFIX}{initial_url}" | ||
|
||
|
||
@register.filter(name="python_any") | ||
def python_any(values): | ||
if values: | ||
return any(values) | ||
return values | ||
|
||
|
||
@register.filter | ||
def file_exists(file_path): | ||
return os.path.isfile( | ||
os.path.join(settings.BASE_DIR, "apps/main/templates/", file_path) | ||
) | ||
|
||
|
||
@register.filter("startswith") | ||
def startswith(text, starts): | ||
if isinstance(text, str): | ||
return text.startswith(starts) | ||
return False | ||
|
||
|
||
@register.filter("get_svg_path") | ||
def get_svg_path(url): | ||
method = "get" | ||
action: Request = getattr(requests, method) | ||
cache_timeout = 60 * 60 | ||
|
||
try: | ||
cache_key = url | ||
response = cache.get(url) | ||
if not response: | ||
response: Response = action( | ||
url=url, | ||
headers={ | ||
"user-agent": urllib3.util.SKIP_HEADER, | ||
}, | ||
) | ||
|
||
if int(response.status_code) == 200: | ||
cache.set(cache_key, response, cache_timeout) | ||
|
||
if response: | ||
return response.text | ||
else: | ||
return None | ||
except requests.exceptions.RequestException as e: | ||
print(f"Error: {e}") | ||
return None | ||
|
||
|
||
@register.filter("get_last_n_characters") | ||
def get_last_n_characters(string, n=3): | ||
last_n_characters = string[-n:] | ||
return last_n_characters | ||
|
||
|
||
@register.filter(name="strip_html") | ||
def strip_html(value): | ||
return strip_tags(value) |
Oops, something went wrong.