1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-27 10:53:02 +00:00
nk20/apps/note/forms.py

53 lines
1.8 KiB
Python
Raw Normal View History

2020-02-18 20:30:26 +00:00
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
2019-08-11 17:55:04 +00:00
2020-02-18 20:14:29 +00:00
from dal import autocomplete
2019-08-11 17:55:04 +00:00
from django import forms
2020-02-27 16:22:59 +00:00
from django.utils.translation import gettext_lazy as _
2020-02-18 20:14:29 +00:00
2020-03-07 21:28:59 +00:00
from .models import Alias
2020-03-13 09:34:47 +00:00
from .models import TransactionTemplate
2020-03-07 21:28:59 +00:00
2020-02-28 12:37:31 +00:00
class AliasForm(forms.ModelForm):
class Meta:
model = Alias
fields = ("name",)
2020-03-03 13:26:31 +00:00
2020-03-07 21:28:59 +00:00
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
2020-03-01 12:42:22 +00:00
self.fields["name"].label = False
2020-03-07 21:28:59 +00:00
self.fields["name"].widget.attrs = {"placeholder": _('New Alias')}
2020-03-03 13:26:31 +00:00
2020-03-04 15:34:12 +00:00
class ImageForm(forms.Form):
2020-03-07 21:28:59 +00:00
image = forms.ImageField(required=False,
2020-03-04 15:34:12 +00:00
label=_('select an image'),
help_text=_('Maximal size: 2MB'))
2020-03-05 22:32:01 +00:00
x = forms.FloatField(widget=forms.HiddenInput())
y = forms.FloatField(widget=forms.HiddenInput())
width = forms.FloatField(widget=forms.HiddenInput())
height = forms.FloatField(widget=forms.HiddenInput())
2020-03-03 13:26:31 +00:00
2020-03-07 21:28:59 +00:00
2019-08-11 17:55:04 +00:00
class TransactionTemplateForm(forms.ModelForm):
class Meta:
model = TransactionTemplate
2020-02-18 11:31:15 +00:00
fields = '__all__'
2020-02-08 19:23:17 +00:00
2020-02-08 20:40:32 +00:00
# Le champ de destination est remplacé par un champ d'auto-complétion.
# Quand des lettres sont tapées, une requête est envoyée sur l'API d'auto-complétion
# et récupère les aliases valides
# Pour force le type d'une note, il faut rajouter le paramètre :
# forward=(forward.Const('TYPE', 'note_type') où TYPE est dans {user, club, special}
2020-02-08 19:23:17 +00:00
widgets = {
2020-02-18 11:31:15 +00:00
'destination':
2020-03-07 21:28:59 +00:00
autocomplete.ModelSelect2(
url='note:note_autocomplete',
attrs={
'data-placeholder': 'Note ...',
'data-minimum-input-length': 1,
},
),
2020-02-08 19:23:17 +00:00
}