Commit ed080b76 authored by Skia's avatar Skia

WIP: Club member form

parent d51ab088
......@@ -81,5 +81,8 @@ class Membership(models.Model):
" - "+str(_('past member')) if self.end_date is not None else ""
)
def get_absolute_url(self):
return reverse('club:club_members', kwargs={'club_id': self.club.id})
{% extends "core/base.jinja" %}
{% block content %}
<h2>Edit club</h2>
<h2>Club members</h2>
<ul>
{% for m in club.members.all() %}
<li>{{ m }}</li>
{% endfor %}
</ul>
<form action="{{ url('club:club_members', club_id=club.id) }}" method="post">
{% csrf_token %}
{{ form.as_p() }}
<p><input type="submit" value="Save!" /></p>
<p><input type="submit" value="Add" /></p>
</form>
{% endblock %}
......
from django import forms
from django.shortcuts import render
from django.views.generic import ListView, DetailView
from django.views.generic.edit import UpdateView
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
from django.views.generic.edit import UpdateView, CreateView
from django.forms import CheckboxSelectMultiple
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
from club.models import Club, Membership
class ClubListView(CanViewMixin, ListView):
......@@ -20,12 +23,33 @@ class ClubEditView(CanEditMixin, UpdateView):
fields = ['address']
template_name = 'club/club_edit.jinja'
class ClubMemberForm(forms.ModelForm):
error_css_class = 'error'
required_css_class = 'required'
class Meta:
model = Membership
fields = ['user', 'role']
def clean(self):
print(self.__dict__)
# TODO: see how to get access to request.user! We need some right validation somewhere!
return super(ClubMemberForm, self).clean()
class ClubEditMembersView(CanEditMixin, UpdateView):
model = Club
pk_url_kwarg = "club_id"
fields = ['user']
form_class = ClubMemberForm
template_name = 'club/club_members.jinja'
def get_form(self):
form = super(ClubEditMembersView, self).get_form()
if 'user' in form.data and form.data.get('user') != '': # Load an existing membership if possible
form.instance = Membership.objects.filter(club=self.object).filter(user=form.data.get('user')).filter(end_date=None).first()
if form.instance is None: # Instanciate a new membership
form.instance = Membership(club=self.object, user=self.request.user)
form.initial = {'user': self.request.user}
return form
class ClubEditPropView(CanEditPropMixin, UpdateView):
model = Club
pk_url_kwarg = "club_id"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment