1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-06-20 17:41:55 +02:00

Open and validate activities

This commit is contained in:
Yohann D'ANELLO
2020-03-27 22:48:20 +01:00
parent d6e202a26f
commit 8c1d902c30
6 changed files with 121 additions and 18 deletions

View File

@ -4,7 +4,7 @@
from django import forms
from django.contrib.contenttypes.models import ContentType
from member.models import Club
from note.models import NoteUser
from note.models import NoteUser, Note
from note_kfet.inputs import DateTimePickerInput, AutocompleteModelSelect
from .models import Activity, Guest
@ -13,12 +13,19 @@ from .models import Activity, Guest
class ActivityForm(forms.ModelForm):
class Meta:
model = Activity
fields = '__all__'
exclude = ('valid', 'open', )
widgets = {
"organizer": AutocompleteModelSelect(
model=Club,
attrs={"api_url": "/api/members/club/"},
),
"note": AutocompleteModelSelect(
model=Note,
attrs={
"api_url": "/api/note/note/",
'placeholder': 'Note de l\'événement sur laquelle envoyer les crédits d\'invitation ...'
},
),
"attendees_club": AutocompleteModelSelect(
model=Club,
attrs={"api_url": "/api/members/club/"},
@ -39,7 +46,7 @@ class GuestForm(forms.ModelForm):
'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),
lambda: '&polymorphic_ctype=' + str(ContentType.objects.get_for_model(NoteUser).pk),
'placeholder': 'Note ...',
},
),

View File

@ -3,7 +3,7 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from note.models import NoteUser
from note.models import NoteUser, Transaction
class ActivityType(models.Model):
@ -44,34 +44,59 @@ class Activity(models.Model):
verbose_name=_('name'),
max_length=255,
)
description = models.TextField(
verbose_name=_('description'),
)
activity_type = models.ForeignKey(
ActivityType,
on_delete=models.PROTECT,
related_name='+',
verbose_name=_('type'),
)
organizer = models.ForeignKey(
'member.Club',
on_delete=models.PROTECT,
related_name='+',
verbose_name=_('organizer'),
)
note = models.ForeignKey(
'note.Note',
on_delete=models.PROTECT,
related_name='+',
null=True,
blank=True,
verbose_name=_('note'),
)
attendees_club = models.ForeignKey(
'member.Club',
on_delete=models.PROTECT,
related_name='+',
verbose_name=_('attendees club'),
)
date_start = models.DateTimeField(
verbose_name=_('start date'),
)
date_end = models.DateTimeField(
verbose_name=_('end date'),
)
valid = models.BooleanField(
default=False,
verbose_name=_('valid'),
)
open = models.BooleanField(
default=False,
verbose_name=_('open'),
)
class Meta:
verbose_name = _("activity")
verbose_name_plural = _("activities")
@ -122,13 +147,17 @@ class Guest(models.Model):
null=True,
)
entry_transaction = models.ForeignKey(
'note.Transaction',
on_delete=models.PROTECT,
blank=True,
null=True,
)
class Meta:
verbose_name = _("guest")
verbose_name_plural = _("guests")
class GuestTransaction(Transaction):
guest = models.OneToOneField(
Guest,
on_delete=models.PROTECT,
)
@property
def type(self):
return _('Invitation')

View File

@ -37,7 +37,7 @@ class TransactionTemplateForm(forms.ModelForm):
'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(NoteClub).pk),
lambda: '&polymorphic_ctype=' + str(ContentType.objects.get_for_model(NoteClub).pk),
'placeholder': 'Note ...',
},
),

View File

@ -48,9 +48,7 @@ def not_empty_model_change_list(model_name):
return session.get("not_empty_model_change_list_" + model_name) == 1
def has_perm(t, obj, field=None):
print(t)
perm = "." + t + ("__" + field if field else "_")
def has_perm(perm, obj):
return PermissionBackend().has_perm(get_current_authenticated_user(), perm, obj)