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 import forms
from django.forms.widgets import RadioSelect, CheckboxSelectMultiple from django.forms.widgets import RadioSelect, CheckboxSelectMultiple
from django.forms.formsets import BaseFormSet, formset_factory from django.forms.formsets import BaseFormSet, formset_factory
from django.utils.translation import ugettext_lazy as _
from bda.models import Spectacle from bda.models import Spectacle
@ -165,6 +166,23 @@ class EventStatusFilterForm(forms.Form):
yield ("has_paid", None, value) 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'), STATUS_CHOICES = (('no', 'Non'),
('wait', 'Oui mais attente paiement'), ('wait', 'Oui mais attente paiement'),
('paid', 'Oui payé'),) ('paid', 'Oui payé'),)

View file

@ -6,7 +6,7 @@
{% for member in members %} {% for member in members %}
{% if forloop.counter < 5 %} {% if forloop.counter < 5 %}
<li class="autocomplete-value"> <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 }} {{ member|highlight_user:q }}
</a> </a>
</li> </li>
@ -22,7 +22,7 @@
{% for user in users %} {% for user in users %}
{% if forloop.counter < 5 %} {% if forloop.counter < 5 %}
<li class="autocomplete-value"> <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 }} {{ user|highlight_user:q }}
</a> </a>
</li> </li>
@ -38,7 +38,7 @@
{% for clipper in clippers %} {% for clipper in clippers %}
{% if forloop.counter < 5 %} {% if forloop.counter < 5 %}
<li class="autocomplete-value"> <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 }} {{ clipper|highlight_clipper:q }}
</a> </a>
</li> </li>
@ -53,5 +53,5 @@
{% else %} {% else %}
<li class="autocomplete-header">Pas dans la liste ?</li> <li class="autocomplete-header">Pas dans la liste ?</li>
{% endif %} {% 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> </ul>

View file

@ -71,7 +71,7 @@
<h4>Général</h4> <h4>Général</h4>
<li><a href="{% url "admin:index" %}">Administration générale</a></li> <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 "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>
<ul> <ul>
<h4>Évènements & Sondages</h4> <h4>Évènements & Sondages</h4>

View file

@ -6,6 +6,17 @@ from .decorators import buro_required
from . import views, petits_cours_views 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 = [ export_patterns = [
url(r'^members$', url(r'^members$',
views.export_members, views.export_members,

View file

@ -5,20 +5,23 @@ import uuid
from datetime import timedelta from datetime import timedelta
from icalendar import Calendar, Event as Vevent from icalendar import Calendar, Event as Vevent
import django.utils.six as six
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.http import Http404, HttpResponse from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render
from django.urls import reverse_lazy
from django.utils import timezone from django.utils import timezone
import django.utils.six as six
from bda.models import Tirage, Spectacle from bda.models import Tirage, Spectacle
from gestion.views import RegistrationView
from .decorators import buro_required, cof_required from .decorators import buro_required, cof_required
from .forms import ( from .forms import (
EventStatusFilterForm, SurveyForm, SurveyStatusFilterForm, EventForm, EventStatusFilterForm, SurveyForm, SurveyStatusFilterForm, EventForm,
CalendarForm CalendarForm, COFProfileRegistrationForm
) )
from .models import ( from .models import (
Survey, SurveyAnswer, SurveyQuestion, SurveyQuestionAnswer, Event, Survey, SurveyAnswer, SurveyQuestion, SurveyQuestionAnswer, Event,
@ -43,6 +46,17 @@ def home(request):
return render(request, "home.html", data) 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 @login_required
def survey(request, survey_id): def survey(request, survey_id):
survey = get_object_or_404(Survey, id=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 gestion.urls
import kfet.urls import kfet.urls
import bda.urls import bda.urls
import cof.urls
from django.conf import settings from django.conf import settings
from django.conf.urls import include, url from django.conf.urls import include, url
@ -32,6 +33,8 @@ urlpatterns = [
url(r'^admin/logout/', gestion_views.logout), url(r'^admin/logout/', gestion_views.logout),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')), url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
# COF
url(r"^cof/", include(cof.urls)),
# Le BdA # Le BdA
url(r'^bda/', include(bda.urls)), url(r'^bda/', include(bda.urls)),
# Les exports # Les exports