1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-26 10:27:07 +00:00
nk20/apps/activity/forms.py
Yohann D'ANELLO ceb5690838 Invite people
2020-03-27 18:02:22 +01:00

54 lines
1.7 KiB
Python

# 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
from member.models import Club
from note.models import NoteUser
from note_kfet.inputs import DateTimePickerInput, AutocompleteModelSelect
from .models import Activity, Guest
class ActivityForm(forms.ModelForm):
class Meta:
model = Activity
fields = '__all__'
widgets = {
"organizer": AutocompleteModelSelect(
model=Club,
attrs={"api_url": "/api/members/club/"},
),
"attendees_club": AutocompleteModelSelect(
model=Club,
attrs={"api_url": "/api/members/club/"},
),
"date_start": DateTimePickerInput(),
"date_end": DateTimePickerInput(),
}
class GuestForm(forms.ModelForm):
def clean(self, **kwargs):
cleaned_data = super().clean()
self.instance.activity = cleaned_data["activity"] = Activity.objects.get(pk=1)
return cleaned_data
class Meta:
model = Guest
fields = ('last_name', 'first_name', 'inviter', )
widgets = {
"inviter": AutocompleteModelSelect(
NoteUser,
attrs={
'api_url': '/api/note/note/',
# 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(NoteUser).pk),
'placeholder': 'Note ...',
},
),
}