Skip to content

Commit

Permalink
Merge pull request #404 from forza-mor-rotterdam/django-4.2
Browse files Browse the repository at this point in the history
Django 4.2
  • Loading branch information
mguikema authored Sep 24, 2024
2 parents e8fe8cc + 1b44c5f commit a78e9e6
Show file tree
Hide file tree
Showing 26 changed files with 337 additions and 59 deletions.
2 changes: 1 addition & 1 deletion app/apps/authenticatie/managers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib.auth.base_user import BaseUserManager
from django.contrib.auth.hashers import make_password
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class GebruikerManager(BaseUserManager):
Expand Down
2 changes: 2 additions & 0 deletions app/apps/authenticatie/signal_receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
if kwargs.get("raw"):
return
if not hasattr(instance, "profiel"):
Profiel.objects.create(gebruiker=instance)
try:
Expand Down
6 changes: 6 additions & 0 deletions app/apps/authorisatie/apps.py
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"
3 changes: 1 addition & 2 deletions app/apps/context/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from apps.context.constanten import FILTERS, KOLOMMEN
from apps.context.models import Context
from django import forms
from utils.forms import RadioSelect


class CheckboxSelectMultiplePaths(forms.CheckboxSelectMultiple):
Expand Down Expand Up @@ -50,7 +49,7 @@ def optgroups(self, name, value, attrs=None):

class ContextAanpassenForm(forms.ModelForm):
template = forms.ChoiceField(
widget=RadioSelect(
widget=forms.RadioSelect(
attrs={
"class": "list--form-radio-input",
}
Expand Down
7 changes: 5 additions & 2 deletions app/apps/context/templates/context/context_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ <h1>Rol aanmaken</h1>
{{ form.kolommen|render_rotterdam_formulier }}
<div class="form-row">
<h3 class="label">Onderwerpen</h3>
{{ form.standaard_filters }}
<div class="list--grouped">{{ form.standaard_filters }}</div>
</div>
<div class="form-row">
<h3 class="label">{{ form.taaktypes.label_tag }}</h3>
{{ form.taaktypes }}
</div>
{{ form.taaktypes|render_rotterdam_formulier }}
{{ form.template|render_rotterdam_formulier }}
</fieldset>
<div class="form-row container__button">
Expand Down
8 changes: 8 additions & 0 deletions app/apps/context/templatetags/main_tags.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
from datetime import datetime

from django import template
Expand Down Expand Up @@ -87,3 +88,10 @@ 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)
)
6 changes: 6 additions & 0 deletions app/apps/main/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class MainConfig(AppConfig):
name = "apps.main"
verbose_name = "Main"
47 changes: 34 additions & 13 deletions app/apps/main/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@
logger = logging.getLogger(__name__)


class MultipleFileInput(forms.ClearableFileInput):
allow_multiple_selected = True


class MultipleFileField(forms.FileField):
def __init__(self, *args, **kwargs):
kwargs.setdefault("widget", MultipleFileInput())
super().__init__(*args, **kwargs)

def clean(self, data, initial=None):
single_file_clean = super().clean
if isinstance(data, (list, tuple)):
result = [single_file_clean(d, initial) for d in data]
else:
result = [single_file_clean(data, initial)]
return result


class CheckboxSelectMultiple(forms.CheckboxSelectMultiple):
template_name = "widgets/checkbox_options_grouped.html"

Expand Down Expand Up @@ -273,13 +291,14 @@ class InformatieToevoegenForm(forms.Form):
max_length=5000,
)

bijlagen_extra = forms.FileField(
widget=forms.widgets.FileInput(
bijlagen_extra = MultipleFileField(
widget=MultipleFileInput(
attrs={
"accept": ".jpg, .jpeg, .png, .heic",
"data-action": "change->bijlagen#updateImageDisplay",
"data-bijlagen-target": "bijlagenExtra",
"multiple": "multiple",
"class": "file-upload-input",
# "multiple": "multiple",
}
),
label="Voeg één of meerdere foto's toe",
Expand All @@ -291,15 +310,15 @@ class TaakStartenForm(forms.Form):
afdeling = forms.ChoiceField(
label="Afdeling",
required=True,
widget=RadioSelect(
widget=forms.RadioSelect(
attrs={
"class": "form-check-input",
}
),
)

onderwerp_gerelateerd_taaktype = forms.ChoiceField(
widget=RadioSelect(
widget=forms.RadioSelect(
attrs={
"data-taakstartenformulier-target": "onderwerpGerelateerdTaaktypeField",
"class": "form-check-input",
Expand All @@ -310,7 +329,7 @@ class TaakStartenForm(forms.Form):
)

taaktype = forms.ChoiceField(
widget=RadioSelect(
widget=forms.RadioSelect(
attrs={
"data-taakstartenformulier-target": "taaktypeField",
"class": "form-check-input",
Expand Down Expand Up @@ -364,7 +383,7 @@ def __init__(self, *args, **kwargs):

class TaakAfrondenForm(forms.Form):
resolutie = forms.ChoiceField(
widget=RadioSelect(
widget=forms.RadioSelect(
attrs={
"class": "list--form-radio-input",
"data-action": "change->bijlagen#updateImageDisplay",
Expand All @@ -374,13 +393,14 @@ class TaakAfrondenForm(forms.Form):
choices=[[x[4], x[1]] for x in TAAK_BEHANDEL_OPTIES],
required=True,
)
bijlagen = forms.FileField(
widget=forms.widgets.FileInput(
bijlagen = MultipleFileField(
widget=MultipleFileInput(
attrs={
"accept": ".jpg, .jpeg, .png, .heic",
"data-action": "change->bijlagen#updateImageDisplay",
"data-bijlagen-target": "bijlagenAfronden",
"multiple": "multiple",
"class": "file-upload-input",
# "multiple": "multiple",
}
),
label="Foto's",
Expand Down Expand Up @@ -818,13 +838,14 @@ class MeldingAanmakenForm(forms.Form):
required=True,
)

bijlagen = forms.FileField(
widget=forms.widgets.FileInput(
bijlagen = MultipleFileField(
widget=MultipleFileInput(
attrs={
"accept": ".jpg, .jpeg, .png, .heic",
"data-action": "change->bijlagen#updateImageDisplay",
"data-bijlagen-target": "bijlagenNieuw",
"multiple": "multiple",
"class": "file-upload-input",
# "multiple": "multiple",
}
),
label="Foto's",
Expand Down
68 changes: 68 additions & 0 deletions app/apps/main/templates/django/forms/widgets/checkbox_select.html
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 %}
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 %}
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>
30 changes: 30 additions & 0 deletions app/apps/main/templates/django/forms/widgets/file.html
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 app/apps/main/templates/django/forms/widgets/multiple_input.html
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 %}
Loading

0 comments on commit a78e9e6

Please sign in to comment.