Add the COF registration view

This commit is contained in:
Martin Pépin 2017-06-22 23:47:24 +01:00
parent 0f491ef396
commit 75bfe98006
6 changed files with 53 additions and 7 deletions

View file

@ -1,6 +1,7 @@
from django import forms
from django.forms.widgets import RadioSelect, CheckboxSelectMultiple
from django.forms.formsets import BaseFormSet, formset_factory
from django.utils.translation import ugettext_lazy as _
from bda.models import Spectacle
@ -165,6 +166,23 @@ class EventStatusFilterForm(forms.Form):
yield ("has_paid", None, value)
class COFProfileRegistrationForm(forms.ModelForm):
member = forms.BooleanField(
label=_("Membre du COF"),
required=False,
)
def save(self, **kwargs):
super().save()
self.instance.is_cof = True
class Meta:
model = CofProfile
fields = [
"type_cotiz", "mailing", "mailing_bda", "mailing_bda_revente",
]
STATUS_CHOICES = (('no', 'Non'),
('wait', 'Oui mais attente paiement'),
('paid', 'Oui payé'),)

View file

@ -6,7 +6,7 @@
{% for member in members %}
{% if forloop.counter < 5 %}
<li class="autocomplete-value">
<a href="{% url 'user-registration' member.username %}">
<a href="{% url 'cof:registration-form' member.username %}?user_type=normal">
{{ member|highlight_user:q }}
</a>
</li>
@ -22,7 +22,7 @@
{% for user in users %}
{% if forloop.counter < 5 %}
<li class="autocomplete-value">
<a href="{% url 'user-registration' user.username %}">
<a href="{% url 'cof:registration-form' user.username %}?user_type=normal">
{{ user|highlight_user:q }}
</a>
</li>
@ -38,7 +38,7 @@
{% for clipper in clippers %}
{% if forloop.counter < 5 %}
<li class="autocomplete-value">
<a href="{% url 'clipper-registration' clipper.clipper clipper.fullname %}">
<a href="{% url 'cof:registration-form' clipper.clipper %}?user_type=clipper&?fullname={{ clipper.fullname }}">
{{ clipper|highlight_clipper:q }}
</a>
</li>
@ -53,5 +53,5 @@
{% else %}
<li class="autocomplete-header">Pas dans la liste ?</li>
{% endif %}
<li><a href="{% url 'empty-registration' %}">Créer un compte</a></li>
<li><a href="{% url 'cof:registration-form' "" %}">Créer un compte</a></li>
</ul>

View file

@ -71,7 +71,7 @@
<h4>Général</h4>
<li><a href="{% url "admin:index" %}">Administration générale</a></li>
<li><a href="{% url "petits-cours-demandes-list" %}">Demandes de petits cours</a></li>
<li><a href="{% url "registration" %}">Inscription d'un nouveau membre</a></li>
<li><a href="{% url "cof:registration" %}">Inscription d'un nouveau membre</a></li>
</ul>
<ul>
<h4>Évènements & Sondages</h4>

View file

@ -6,6 +6,17 @@ from .decorators import buro_required
from . import views, petits_cours_views
app_name = "cof"
urlpatterns = [
# User registration
url(r'^registration$',
views.COFRegistrationView.as_view(),
name="registration"),
url(r'^registration/form/(?P<username>[\w-]*)$',
views.COFRegistrationView.as_view(form_only=True),
name="registration-form"),
]
export_patterns = [
url(r'^members$',
views.export_members,

View file

@ -5,20 +5,23 @@ import uuid
from datetime import timedelta
from icalendar import Calendar, Event as Vevent
import django.utils.six as six
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.contrib.sites.models import Site
from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404, render
from django.urls import reverse_lazy
from django.utils import timezone
import django.utils.six as six
from bda.models import Tirage, Spectacle
from gestion.views import RegistrationView
from .decorators import buro_required, cof_required
from .forms import (
EventStatusFilterForm, SurveyForm, SurveyStatusFilterForm, EventForm,
CalendarForm
CalendarForm, COFProfileRegistrationForm
)
from .models import (
Survey, SurveyAnswer, SurveyQuestion, SurveyQuestionAnswer, Event,
@ -43,6 +46,17 @@ def home(request):
return render(request, "home.html", data)
class COFRegistrationView(PermissionRequiredMixin, RegistrationView):
permission_required = "cof.buro"
form_class = COFProfileRegistrationForm
page_url = reverse_lazy("cof:registration")
def get_form_kwargs(self, **kwargs):
if self.user:
kwargs["instance"] = getattr(self.user.profile, "cof", None)
return kwargs
@login_required
def survey(request, survey_id):
survey = get_object_or_404(Survey, id=survey_id)

View file

@ -7,6 +7,7 @@ Fichier principal de configuration des urls du projet GestioCOF
import gestion.urls
import kfet.urls
import bda.urls
import cof.urls
from django.conf import settings
from django.conf.urls import include, url
@ -32,6 +33,8 @@ urlpatterns = [
url(r'^admin/logout/', gestion_views.logout),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', admin.site.urls),
# COF
url(r"^cof/", include(cof.urls)),
# Le BdA
url(r'^bda/', include(bda.urls)),
# Les exports