Skip to content
Snippets Groups Projects
forms.py 1.81 KiB
Newer Older
me5na7qbjqbrp's avatar
me5na7qbjqbrp committed
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later

from django import forms
from django.contrib.contenttypes.models import ContentType
ynerant's avatar
ynerant committed
from django.utils.translation import gettext_lazy as _
from note_kfet.inputs import AutocompleteModelSelect
from .models import TransactionTemplate, NoteClub
ynerant's avatar
ynerant committed

class ImageForm(forms.Form):
ynerant's avatar
ynerant committed
    image = forms.ImageField(required=False,
                             label=_('select an image'),
                             help_text=_('Maximal size: 2MB'))
    x = forms.FloatField(widget=forms.HiddenInput())
    y = forms.FloatField(widget=forms.HiddenInput())
    width = forms.FloatField(widget=forms.HiddenInput())
    height = forms.FloatField(widget=forms.HiddenInput())
ynerant's avatar
ynerant committed

class TransactionTemplateForm(forms.ModelForm):
    class Meta:
        model = TransactionTemplate
me5na7qbjqbrp's avatar
me5na7qbjqbrp committed
        fields = '__all__'
ynerant's avatar
ynerant committed

ynerant's avatar
ynerant committed
        # 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}
ynerant's avatar
ynerant committed
        widgets = {
me5na7qbjqbrp's avatar
me5na7qbjqbrp committed
            'destination':
                AutocompleteModelSelect(
                    NoteClub,
ynerant's avatar
ynerant committed
                    attrs={
                        'api_url': '/api/note/note/',
ynerant's avatar
ynerant committed
                        # We don't evaluate the content type at launch because the DB might be not initialized
                        'api_url_suffix':
                            lambda value: '&polymorphic_ctype=' + str(ContentType.objects.get_for_model(NoteClub).pk),
                        'placeholder': 'Note ...',
ynerant's avatar
ynerant committed
                    },
                ),
ynerant's avatar
ynerant committed
        }