2020-02-18 21:30:26 +01:00
|
|
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2019-08-11 19:55:04 +02:00
|
|
|
|
|
|
|
from django import forms
|
2020-03-27 16:19:33 +01:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2020-02-27 17:22:59 +01:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2020-03-30 00:42:32 +02:00
|
|
|
from note_kfet.inputs import Autocomplete
|
2020-02-18 21:14:29 +01:00
|
|
|
|
2020-03-27 16:19:33 +01:00
|
|
|
from .models import TransactionTemplate, NoteClub
|
2020-03-07 22:28:59 +01:00
|
|
|
|
2020-02-28 13:37:31 +01:00
|
|
|
|
2020-03-04 16:34:12 +01:00
|
|
|
class ImageForm(forms.Form):
|
2020-03-07 22:28:59 +01:00
|
|
|
image = forms.ImageField(required=False,
|
2020-03-04 16:34:12 +01:00
|
|
|
label=_('select an image'),
|
|
|
|
help_text=_('Maximal size: 2MB'))
|
2020-03-05 23:32:01 +01: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 14:26:31 +01:00
|
|
|
|
2020-03-07 22:28:59 +01:00
|
|
|
|
2019-08-11 19:55:04 +02:00
|
|
|
class TransactionTemplateForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = TransactionTemplate
|
2020-02-18 12:31:15 +01:00
|
|
|
fields = '__all__'
|
2020-02-08 20:23:17 +01:00
|
|
|
|
2020-02-08 21:40:32 +01: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
|
2020-02-08 23:24:49 +01:00
|
|
|
# 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 20:23:17 +01:00
|
|
|
widgets = {
|
2020-02-18 12:31:15 +01:00
|
|
|
'destination':
|
2020-03-30 00:42:32 +02:00
|
|
|
Autocomplete(
|
2020-03-27 16:19:33 +01:00
|
|
|
NoteClub,
|
2020-03-07 22:28:59 +01:00
|
|
|
attrs={
|
2020-03-27 16:19:33 +01:00
|
|
|
'api_url': '/api/note/note/',
|
2020-03-27 16:32:46 +01:00
|
|
|
# We don't evaluate the content type at launch because the DB might be not initialized
|
|
|
|
'api_url_suffix':
|
2020-03-27 22:48:20 +01:00
|
|
|
lambda: '&polymorphic_ctype=' + str(ContentType.objects.get_for_model(NoteClub).pk),
|
2020-03-27 16:19:33 +01:00
|
|
|
'placeholder': 'Note ...',
|
2020-03-07 22:28:59 +01:00
|
|
|
},
|
|
|
|
),
|
2020-02-08 20:23:17 +01:00
|
|
|
}
|