Invite people

This commit is contained in:
Yohann D'ANELLO 2020-03-27 18:02:22 +01:00
parent 4f4bbf6d0e
commit ceb5690838
9 changed files with 125 additions and 15 deletions

View File

@ -2,10 +2,13 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from django import forms from django import forms
from activity.models import Activity from django.contrib.contenttypes.models import ContentType
from member.models import Club from member.models import Club
from note.models import NoteUser
from note_kfet.inputs import DateTimePickerInput, AutocompleteModelSelect from note_kfet.inputs import DateTimePickerInput, AutocompleteModelSelect
from .models import Activity, Guest
class ActivityForm(forms.ModelForm): class ActivityForm(forms.ModelForm):
class Meta: class Meta:
@ -23,3 +26,28 @@ class ActivityForm(forms.ModelForm):
"date_start": DateTimePickerInput(), "date_start": DateTimePickerInput(),
"date_end": 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 ...',
},
),
}

View File

@ -1,9 +1,9 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from django.conf import settings
from django.db import models from django.db import models
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from note.models import NoteUser
class ActivityType(models.Model): class ActivityType(models.Model):
@ -77,6 +77,18 @@ class Activity(models.Model):
verbose_name_plural = _("activities") verbose_name_plural = _("activities")
class Entry(models.Model):
time = models.DateTimeField(
verbose_name=_("entry time"),
)
note = models.ForeignKey(
NoteUser,
on_delete=models.PROTECT,
verbose_name=_("note"),
)
class Guest(models.Model): class Guest(models.Model):
""" """
People who are not current members of any clubs, and are invited by someone who is a current member. People who are not current members of any clubs, and are invited by someone who is a current member.
@ -86,17 +98,30 @@ class Guest(models.Model):
on_delete=models.PROTECT, on_delete=models.PROTECT,
related_name='+', related_name='+',
) )
name = models.CharField(
last_name = models.CharField(
max_length=255, max_length=255,
verbose_name=_("last name"),
) )
first_name = models.CharField(
max_length=255,
verbose_name=_("first name"),
)
inviter = models.ForeignKey( inviter = models.ForeignKey(
settings.AUTH_USER_MODEL, NoteUser,
on_delete=models.PROTECT, on_delete=models.PROTECT,
related_name='+', related_name='+',
verbose_name=_("inviter"),
) )
entry = models.DateTimeField(
entry = models.OneToOneField(
Entry,
on_delete=models.PROTECT,
null=True, null=True,
) )
entry_transaction = models.ForeignKey( entry_transaction = models.ForeignKey(
'note.Transaction', 'note.Transaction',
on_delete=models.PROTECT, on_delete=models.PROTECT,

40
apps/activity/tables.py Normal file
View File

@ -0,0 +1,40 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django.utils.translation import gettext_lazy as _
from django_tables2 import tables, A
from .models import Activity, Guest
class ActivityTable(tables.Table):
name = tables.columns.LinkColumn('activity:activity_detail',
args=[A('pk'), ],)
invite = tables.columns.LinkColumn('activity:activity_invite',
args=[A('pk'), ],
verbose_name=_("Invite"),
text=_("Invite"),)
class Meta:
attrs = {
'class': 'table table-condensed table-striped table-hover'
}
model = Activity
template_name = 'django_tables2/bootstrap4.html'
fields = ('name', 'activity_type', 'organizer', 'attendees_club', 'date_start', 'date_end', 'invite', )
class GuestTable(tables.Table):
class Meta:
attrs = {
'class': 'table table-condensed table-striped table-hover'
}
model = Guest
template_name = 'django_tables2/bootstrap4.html'
fields = ('name', 'inviter', )
row_attrs = {
'class': 'table-row',
'id': lambda record: "row-" + str(record.pk),
'data-href': lambda record: record.pk
}

View File

@ -10,6 +10,7 @@ app_name = 'activity'
urlpatterns = [ urlpatterns = [
path('', views.ActivityListView.as_view(), name='activity_list'), path('', views.ActivityListView.as_view(), name='activity_list'),
path('<int:pk>/', views.ActivityDetailView.as_view(), name='activity_detail'), path('<int:pk>/', views.ActivityDetailView.as_view(), name='activity_detail'),
path('<int:activity_pk>/invite/', views.ActivityInviteView.as_view(), name='activity_invite'),
path('<int:pk>/entry/', views.ActivityEntryView.as_view(), name='activity_entry'), path('<int:pk>/entry/', views.ActivityEntryView.as_view(), name='activity_entry'),
path('<int:pk>/update/', views.ActivityUpdateView.as_view(), name='activity_update'), path('<int:pk>/update/', views.ActivityUpdateView.as_view(), name='activity_update'),
path('new/', views.ActivityCreateView.as_view(), name='activity_create'), path('new/', views.ActivityCreateView.as_view(), name='activity_create'),

View File

@ -7,8 +7,9 @@ from django.views.generic import CreateView, DetailView, UpdateView, TemplateVie
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django_tables2.views import SingleTableView from django_tables2.views import SingleTableView
from .forms import ActivityForm from .forms import ActivityForm, GuestForm
from .models import Activity from .models import Activity, Guest
from .tables import ActivityTable
class ActivityCreateView(LoginRequiredMixin, CreateView): class ActivityCreateView(LoginRequiredMixin, CreateView):
@ -19,6 +20,7 @@ class ActivityCreateView(LoginRequiredMixin, CreateView):
class ActivityListView(LoginRequiredMixin, SingleTableView): class ActivityListView(LoginRequiredMixin, SingleTableView):
model = Activity model = Activity
table_class = ActivityTable
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs) ctx = super().get_context_data(**kwargs)
@ -38,5 +40,12 @@ class ActivityUpdateView(LoginRequiredMixin, UpdateView):
success_url = reverse_lazy('activity:activity_list') success_url = reverse_lazy('activity:activity_list')
class ActivityInviteView(LoginRequiredMixin, CreateView):
model = Guest
form_class = GuestForm
success_url = reverse_lazy('activity:activity_list')
template_name = "activity/activity_invite.html"
class ActivityEntryView(LoginRequiredMixin, TemplateView): class ActivityEntryView(LoginRequiredMixin, TemplateView):
pass pass

View File

@ -7,7 +7,6 @@ from crispy_forms.layout import Layout
from django import forms from django import forms
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from django.contrib.auth.models import User from django.contrib.auth.models import User
from note_kfet.inputs import AutocompleteModelSelect from note_kfet.inputs import AutocompleteModelSelect
from permission.models import PermissionMask from permission.models import PermissionMask

View File

@ -4,7 +4,6 @@
from django.urls import path from django.urls import path
from . import views from . import views
from .models import Note
app_name = 'note' app_name = 'note'
urlpatterns = [ urlpatterns = [

View File

@ -40,12 +40,6 @@ class AutocompleteModelSelect(Select):
return str(self.model.objects.get(pk=int(value))) return str(self.model.objects.get(pk=int(value)))
return "" return ""
def value_from_datadict(self, data, files, name):
val = super().value_from_datadict(data, files, name)
print(data)
print(self.attrs)
return val
""" """
The remaining of this file comes from the project `django-bootstrap-datepicker-plus` available on Github: The remaining of this file comes from the project `django-bootstrap-datepicker-plus` available on Github:

View File

@ -0,0 +1,15 @@
{% extends "base.html" %}
{% load render_table from django_tables2 %}
{% load i18n crispy_forms_tags %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form|crispy }}
<button class="btn btn-primary" type="submit">{% trans "Submit" %}</button>
</form>
{% endblock %}
{% block extrajavascript %}
<script type="text/javascript">
</script>
{% endblock %}