mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
Format club
This commit is contained in:
parent
544ff630a5
commit
73b2c9d4c5
@ -29,4 +29,3 @@ from club.models import Club, Membership
|
|||||||
|
|
||||||
admin.site.register(Club)
|
admin.site.register(Club)
|
||||||
admin.site.register(Membership)
|
admin.site.register(Membership)
|
||||||
|
|
||||||
|
@ -27,12 +27,13 @@ from django.core import validators
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import IntegrityError, transaction
|
from django.db import transaction
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from core.models import User, MetaGroup, Group, SithFile
|
from core.models import User, MetaGroup, Group, SithFile
|
||||||
|
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
class Club(models.Model):
|
class Club(models.Model):
|
||||||
@ -43,17 +44,17 @@ class Club(models.Model):
|
|||||||
name = models.CharField(_('name'), max_length=64)
|
name = models.CharField(_('name'), max_length=64)
|
||||||
parent = models.ForeignKey('Club', related_name='children', null=True, blank=True)
|
parent = models.ForeignKey('Club', related_name='children', null=True, blank=True)
|
||||||
unix_name = models.CharField(_('unix name'), max_length=30, unique=True,
|
unix_name = models.CharField(_('unix name'), max_length=30, unique=True,
|
||||||
validators=[
|
validators=[
|
||||||
validators.RegexValidator(
|
validators.RegexValidator(
|
||||||
r'^[a-z0-9][a-z0-9._-]*[a-z0-9]$',
|
r'^[a-z0-9][a-z0-9._-]*[a-z0-9]$',
|
||||||
_('Enter a valid unix name. This value may contain only '
|
_('Enter a valid unix name. This value may contain only '
|
||||||
'letters, numbers ./-/_ characters.')
|
'letters, numbers ./-/_ characters.')
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
error_messages={
|
error_messages={
|
||||||
'unique': _("A club with that unix name already exists."),
|
'unique': _("A club with that unix name already exists."),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
address = models.CharField(_('address'), max_length=254)
|
address = models.CharField(_('address'), max_length=254)
|
||||||
# email = models.EmailField(_('email address'), unique=True) # This should, and will be generated automatically
|
# email = models.EmailField(_('email address'), unique=True) # This should, and will be generated automatically
|
||||||
owner_group = models.ForeignKey(Group, related_name="owned_club",
|
owner_group = models.ForeignKey(Group, related_name="owned_club",
|
||||||
@ -61,7 +62,7 @@ class Club(models.Model):
|
|||||||
edit_groups = models.ManyToManyField(Group, related_name="editable_club", blank=True)
|
edit_groups = models.ManyToManyField(Group, related_name="editable_club", blank=True)
|
||||||
view_groups = models.ManyToManyField(Group, related_name="viewable_club", blank=True)
|
view_groups = models.ManyToManyField(Group, related_name="viewable_club", blank=True)
|
||||||
home = models.OneToOneField(SithFile, related_name='home_of_club', verbose_name=_("home"), null=True, blank=True,
|
home = models.OneToOneField(SithFile, related_name='home_of_club', verbose_name=_("home"), null=True, blank=True,
|
||||||
on_delete=models.SET_NULL)
|
on_delete=models.SET_NULL)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['name', 'unix_name']
|
ordering = ['name', 'unix_name']
|
||||||
@ -109,9 +110,9 @@ class Club(models.Model):
|
|||||||
self._change_unixname(self.unix_name)
|
self._change_unixname(self.unix_name)
|
||||||
super(Club, self).save(*args, **kwargs)
|
super(Club, self).save(*args, **kwargs)
|
||||||
if creation:
|
if creation:
|
||||||
board = MetaGroup(name=self.unix_name+settings.SITH_BOARD_SUFFIX)
|
board = MetaGroup(name=self.unix_name + settings.SITH_BOARD_SUFFIX)
|
||||||
board.save()
|
board.save()
|
||||||
member = MetaGroup(name=self.unix_name+settings.SITH_MEMBER_SUFFIX)
|
member = MetaGroup(name=self.unix_name + settings.SITH_MEMBER_SUFFIX)
|
||||||
member.save()
|
member.save()
|
||||||
subscribers = Group.objects.filter(name=settings.SITH_MAIN_MEMBERS_GROUP).first()
|
subscribers = Group.objects.filter(name=settings.SITH_MAIN_MEMBERS_GROUP).first()
|
||||||
self.make_home()
|
self.make_home()
|
||||||
@ -153,6 +154,7 @@ class Club(models.Model):
|
|||||||
return sub.is_subscribed
|
return sub.is_subscribed
|
||||||
|
|
||||||
_memberships = {}
|
_memberships = {}
|
||||||
|
|
||||||
def get_membership_for(self, user):
|
def get_membership_for(self, user):
|
||||||
"""
|
"""
|
||||||
Returns the current membership the given user
|
Returns the current membership the given user
|
||||||
@ -168,6 +170,7 @@ class Club(models.Model):
|
|||||||
Club._memberships[self.id][user.id] = m
|
Club._memberships[self.id][user.id] = m
|
||||||
return m
|
return m
|
||||||
|
|
||||||
|
|
||||||
class Membership(models.Model):
|
class Membership(models.Model):
|
||||||
"""
|
"""
|
||||||
The Membership class makes the connection between User and Clubs
|
The Membership class makes the connection between User and Clubs
|
||||||
@ -184,7 +187,7 @@ class Membership(models.Model):
|
|||||||
start_date = models.DateField(_('start date'), default=timezone.now)
|
start_date = models.DateField(_('start date'), default=timezone.now)
|
||||||
end_date = models.DateField(_('end date'), null=True, blank=True)
|
end_date = models.DateField(_('end date'), null=True, blank=True)
|
||||||
role = models.IntegerField(_('role'), choices=sorted(settings.SITH_CLUB_ROLES.items()),
|
role = models.IntegerField(_('role'), choices=sorted(settings.SITH_CLUB_ROLES.items()),
|
||||||
default=sorted(settings.SITH_CLUB_ROLES.items())[0][0])
|
default=sorted(settings.SITH_CLUB_ROLES.items())[0][0])
|
||||||
description = models.CharField(_('description'), max_length=128, null=False, blank=True)
|
description = models.CharField(_('description'), max_length=128, null=False, blank=True)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
@ -195,9 +198,9 @@ class Membership(models.Model):
|
|||||||
raise ValidationError(_('User is already member of that club'))
|
raise ValidationError(_('User is already member of that club'))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.club.name+' - '+self.user.username+' - '+str(settings.SITH_CLUB_ROLES[self.role])+str(
|
return self.club.name + ' - ' + self.user.username + ' - ' + str(settings.SITH_CLUB_ROLES[self.role]) + str(
|
||||||
" - "+str(_('past member')) if self.end_date is not None else ""
|
" - " + str(_('past member')) if self.end_date is not None else ""
|
||||||
)
|
)
|
||||||
|
|
||||||
def is_owned_by(self, user):
|
def is_owned_by(self, user):
|
||||||
"""
|
"""
|
||||||
@ -216,4 +219,3 @@ class Membership(models.Model):
|
|||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('club:club_members', kwargs={'club_id': self.club.id})
|
return reverse('club:club_members', kwargs={'club_id': self.club.id})
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ from club.models import Club
|
|||||||
|
|
||||||
# Create your tests here.
|
# Create your tests here.
|
||||||
|
|
||||||
|
|
||||||
class ClubTest(TestCase):
|
class ClubTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
call_command("populate")
|
call_command("populate")
|
||||||
@ -41,34 +42,34 @@ class ClubTest(TestCase):
|
|||||||
|
|
||||||
def test_create_add_user_to_club_from_root_ok(self):
|
def test_create_add_user_to_club_from_root_ok(self):
|
||||||
self.client.login(username='root', password='plop')
|
self.client.login(username='root', password='plop')
|
||||||
self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {
|
self.client.post(reverse("club:club_members", kwargs={"club_id": self.bdf.id}), {
|
||||||
"user": self.skia.id,
|
"user": self.skia.id,
|
||||||
"start_date": "12/06/2016",
|
"start_date": "12/06/2016",
|
||||||
"role": 3})
|
"role": 3})
|
||||||
response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id}))
|
response = self.client.get(reverse("club:club_members", kwargs={"club_id": self.bdf.id}))
|
||||||
self.assertTrue(response.status_code == 200)
|
self.assertTrue(response.status_code == 200)
|
||||||
self.assertTrue("S' Kia</a></td>\\n <td>Responsable info</td>" in str(response.content))
|
self.assertTrue("S' Kia</a></td>\\n <td>Responsable info</td>" in str(response.content))
|
||||||
|
|
||||||
def test_create_add_user_to_club_from_root_fail_not_subscriber(self):
|
def test_create_add_user_to_club_from_root_fail_not_subscriber(self):
|
||||||
self.client.login(username='root', password='plop')
|
self.client.login(username='root', password='plop')
|
||||||
response = self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {
|
response = self.client.post(reverse("club:club_members", kwargs={"club_id": self.bdf.id}), {
|
||||||
"user": self.guy.id,
|
"user": self.guy.id,
|
||||||
"start_date": "12/06/2016",
|
"start_date": "12/06/2016",
|
||||||
"role": 3})
|
"role": 3})
|
||||||
self.assertTrue(response.status_code == 200)
|
self.assertTrue(response.status_code == 200)
|
||||||
self.assertTrue('<ul class="errorlist nonfield"><li>' in str(response.content))
|
self.assertTrue('<ul class="errorlist nonfield"><li>' in str(response.content))
|
||||||
response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id}))
|
response = self.client.get(reverse("club:club_members", kwargs={"club_id": self.bdf.id}))
|
||||||
self.assertFalse("Guy Carlier</a></td>\\n <td>Responsable info</td>" in str(response.content))
|
self.assertFalse("Guy Carlier</a></td>\\n <td>Responsable info</td>" in str(response.content))
|
||||||
|
|
||||||
def test_create_add_user_to_club_from_root_fail_already_in_club(self):
|
def test_create_add_user_to_club_from_root_fail_already_in_club(self):
|
||||||
self.client.login(username='root', password='plop')
|
self.client.login(username='root', password='plop')
|
||||||
self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {
|
self.client.post(reverse("club:club_members", kwargs={"club_id": self.bdf.id}), {
|
||||||
"user": self.skia.id,
|
"user": self.skia.id,
|
||||||
"start_date": "12/06/2016",
|
"start_date": "12/06/2016",
|
||||||
"role": 3})
|
"role": 3})
|
||||||
response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id}))
|
response = self.client.get(reverse("club:club_members", kwargs={"club_id": self.bdf.id}))
|
||||||
self.assertTrue("S' Kia</a></td>\\n <td>Responsable info</td>" in str(response.content))
|
self.assertTrue("S' Kia</a></td>\\n <td>Responsable info</td>" in str(response.content))
|
||||||
response = self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {
|
response = self.client.post(reverse("club:club_members", kwargs={"club_id": self.bdf.id}), {
|
||||||
"user": self.skia.id,
|
"user": self.skia.id,
|
||||||
"start_date": "12/06/2016",
|
"start_date": "12/06/2016",
|
||||||
"role": 4})
|
"role": 4})
|
||||||
@ -77,30 +78,29 @@ class ClubTest(TestCase):
|
|||||||
|
|
||||||
def test_create_add_user_to_club_from_skia_ok(self):
|
def test_create_add_user_to_club_from_skia_ok(self):
|
||||||
self.client.login(username='root', password='plop')
|
self.client.login(username='root', password='plop')
|
||||||
self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {
|
self.client.post(reverse("club:club_members", kwargs={"club_id": self.bdf.id}), {
|
||||||
"user": self.skia.id,
|
"user": self.skia.id,
|
||||||
"start_date": "12/06/2016",
|
"start_date": "12/06/2016",
|
||||||
"role": 10})
|
"role": 10})
|
||||||
self.client.login(username='skia', password='plop')
|
self.client.login(username='skia', password='plop')
|
||||||
self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {
|
self.client.post(reverse("club:club_members", kwargs={"club_id": self.bdf.id}), {
|
||||||
"user": self.rbatsbak.id,
|
"user": self.rbatsbak.id,
|
||||||
"start_date": "12/06/2016",
|
"start_date": "12/06/2016",
|
||||||
"role": 9})
|
"role": 9})
|
||||||
response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id}))
|
response = self.client.get(reverse("club:club_members", kwargs={"club_id": self.bdf.id}))
|
||||||
self.assertTrue(response.status_code == 200)
|
self.assertTrue(response.status_code == 200)
|
||||||
self.assertTrue("""Richard Batsbak</a></td>\\n <td>Vice-Pr\\xc3\\xa9sident</td>""" in str(response.content))
|
self.assertTrue("""Richard Batsbak</a></td>\\n <td>Vice-Pr\\xc3\\xa9sident</td>""" in str(response.content))
|
||||||
|
|
||||||
def test_create_add_user_to_club_from_richard_fail(self):
|
def test_create_add_user_to_club_from_richard_fail(self):
|
||||||
self.client.login(username='root', password='plop')
|
self.client.login(username='root', password='plop')
|
||||||
self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {
|
self.client.post(reverse("club:club_members", kwargs={"club_id": self.bdf.id}), {
|
||||||
"user": self.rbatsbak.id,
|
"user": self.rbatsbak.id,
|
||||||
"start_date": "12/06/2016",
|
"start_date": "12/06/2016",
|
||||||
"role": 3})
|
"role": 3})
|
||||||
self.client.login(username='rbatsbak', password='plop')
|
self.client.login(username='rbatsbak', password='plop')
|
||||||
response = self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {
|
response = self.client.post(reverse("club:club_members", kwargs={"club_id": self.bdf.id}), {
|
||||||
"user": self.skia.id,
|
"user": self.skia.id,
|
||||||
"start_date": "12/06/2016",
|
"start_date": "12/06/2016",
|
||||||
"role": 10})
|
"role": 10})
|
||||||
self.assertTrue(response.status_code == 200)
|
self.assertTrue(response.status_code == 200)
|
||||||
self.assertTrue("<li>Vous n'avez pas la permission de faire cela</li>" in str(response.content))
|
self.assertTrue("<li>Vous n'avez pas la permission de faire cela</li>" in str(response.content))
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
from django.conf.urls import url, include
|
from django.conf.urls import url
|
||||||
|
|
||||||
from club.views import *
|
from club.views import *
|
||||||
|
|
||||||
@ -40,4 +40,3 @@ urlpatterns = [
|
|||||||
url(r'^(?P<club_id>[0-9]+)/tools$', ClubToolsView.as_view(), name='tools'),
|
url(r'^(?P<club_id>[0-9]+)/tools$', ClubToolsView.as_view(), name='tools'),
|
||||||
url(r'^membership/(?P<membership_id>[0-9]+)/set_old$', MembershipSetOldView.as_view(), name='membership_set_old'),
|
url(r'^membership/(?P<membership_id>[0-9]+)/set_old$', MembershipSetOldView.as_view(), name='membership_set_old'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
106
club/views.py
106
club/views.py
@ -23,27 +23,21 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.shortcuts import render
|
|
||||||
from django.views.generic import ListView, DetailView, TemplateView
|
from django.views.generic import ListView, DetailView, TemplateView
|
||||||
from django.views.generic.edit import UpdateView, CreateView
|
from django.views.generic.edit import UpdateView, CreateView
|
||||||
from django.forms import CheckboxSelectMultiple
|
|
||||||
from django.core.exceptions import ValidationError
|
|
||||||
from django.http import HttpResponseRedirect, HttpResponse
|
from django.http import HttpResponseRedirect, HttpResponse
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.utils.translation import ugettext as _t
|
from django.utils.translation import ugettext as _t
|
||||||
from django.conf import settings
|
|
||||||
from ajax_select.fields import AutoCompleteSelectField
|
from ajax_select.fields import AutoCompleteSelectField
|
||||||
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin
|
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin
|
||||||
from core.views.forms import SelectDate, SelectSingle, SelectDateTime
|
from core.views.forms import SelectDate, SelectDateTime
|
||||||
from club.models import Club, Membership
|
from club.models import Club, Membership
|
||||||
from core.models import User
|
from sith.settings import SITH_MAXIMUM_FREE_ROLE
|
||||||
from sith.settings import SITH_MAXIMUM_FREE_ROLE, SITH_MAIN_BOARD_GROUP
|
from counter.models import Selling, Counter
|
||||||
from counter.models import Product, Selling, Counter
|
|
||||||
|
|
||||||
class ClubTabsMixin(TabedViewMixin):
|
class ClubTabsMixin(TabedViewMixin):
|
||||||
def get_tabs_title(self):
|
def get_tabs_title(self):
|
||||||
@ -52,45 +46,46 @@ class ClubTabsMixin(TabedViewMixin):
|
|||||||
def get_list_of_tabs(self):
|
def get_list_of_tabs(self):
|
||||||
tab_list = []
|
tab_list = []
|
||||||
tab_list.append({
|
tab_list.append({
|
||||||
'url': reverse('club:club_view', kwargs={'club_id': self.object.id}),
|
'url': reverse('club:club_view', kwargs={'club_id': self.object.id}),
|
||||||
'slug': 'infos',
|
'slug': 'infos',
|
||||||
'name': _("Infos"),
|
'name': _("Infos"),
|
||||||
})
|
})
|
||||||
if self.request.user.can_view(self.object):
|
if self.request.user.can_view(self.object):
|
||||||
tab_list.append({
|
tab_list.append({
|
||||||
'url': reverse('club:club_members', kwargs={'club_id': self.object.id}),
|
'url': reverse('club:club_members', kwargs={'club_id': self.object.id}),
|
||||||
'slug': 'members',
|
'slug': 'members',
|
||||||
'name': _("Members"),
|
'name': _("Members"),
|
||||||
})
|
})
|
||||||
tab_list.append({
|
tab_list.append({
|
||||||
'url': reverse('club:club_old_members', kwargs={'club_id': self.object.id}),
|
'url': reverse('club:club_old_members', kwargs={'club_id': self.object.id}),
|
||||||
'slug': 'elderlies',
|
'slug': 'elderlies',
|
||||||
'name': _("Old members"),
|
'name': _("Old members"),
|
||||||
})
|
})
|
||||||
if self.request.user.can_edit(self.object):
|
if self.request.user.can_edit(self.object):
|
||||||
tab_list.append({
|
tab_list.append({
|
||||||
'url': reverse('club:tools', kwargs={'club_id': self.object.id}),
|
'url': reverse('club:tools', kwargs={'club_id': self.object.id}),
|
||||||
'slug': 'tools',
|
'slug': 'tools',
|
||||||
'name': _("Tools"),
|
'name': _("Tools"),
|
||||||
})
|
})
|
||||||
tab_list.append({
|
tab_list.append({
|
||||||
'url': reverse('club:club_edit', kwargs={'club_id': self.object.id}),
|
'url': reverse('club:club_edit', kwargs={'club_id': self.object.id}),
|
||||||
'slug': 'edit',
|
'slug': 'edit',
|
||||||
'name': _("Edit"),
|
'name': _("Edit"),
|
||||||
})
|
})
|
||||||
tab_list.append({
|
tab_list.append({
|
||||||
'url': reverse('club:club_sellings', kwargs={'club_id': self.object.id}),
|
'url': reverse('club:club_sellings', kwargs={'club_id': self.object.id}),
|
||||||
'slug': 'sellings',
|
'slug': 'sellings',
|
||||||
'name': _("Sellings"),
|
'name': _("Sellings"),
|
||||||
})
|
})
|
||||||
if self.request.user.is_owner(self.object):
|
if self.request.user.is_owner(self.object):
|
||||||
tab_list.append({
|
tab_list.append({
|
||||||
'url': reverse('club:club_prop', kwargs={'club_id': self.object.id}),
|
'url': reverse('club:club_prop', kwargs={'club_id': self.object.id}),
|
||||||
'slug': 'props',
|
'slug': 'props',
|
||||||
'name': _("Props"),
|
'name': _("Props"),
|
||||||
})
|
})
|
||||||
return tab_list
|
return tab_list
|
||||||
|
|
||||||
|
|
||||||
class ClubListView(ListView):
|
class ClubListView(ListView):
|
||||||
"""
|
"""
|
||||||
List the Clubs
|
List the Clubs
|
||||||
@ -98,6 +93,7 @@ class ClubListView(ListView):
|
|||||||
model = Club
|
model = Club
|
||||||
template_name = 'club/club_list.jinja'
|
template_name = 'club/club_list.jinja'
|
||||||
|
|
||||||
|
|
||||||
class ClubView(ClubTabsMixin, DetailView):
|
class ClubView(ClubTabsMixin, DetailView):
|
||||||
"""
|
"""
|
||||||
Front page of a Club
|
Front page of a Club
|
||||||
@ -107,6 +103,7 @@ class ClubView(ClubTabsMixin, DetailView):
|
|||||||
template_name = 'club/club_detail.jinja'
|
template_name = 'club/club_detail.jinja'
|
||||||
current_tab = "infos"
|
current_tab = "infos"
|
||||||
|
|
||||||
|
|
||||||
class ClubToolsView(ClubTabsMixin, CanEditMixin, DetailView):
|
class ClubToolsView(ClubTabsMixin, CanEditMixin, DetailView):
|
||||||
"""
|
"""
|
||||||
Tools page of a Club
|
Tools page of a Club
|
||||||
@ -116,27 +113,30 @@ class ClubToolsView(ClubTabsMixin, CanEditMixin, DetailView):
|
|||||||
template_name = 'club/club_tools.jinja'
|
template_name = 'club/club_tools.jinja'
|
||||||
current_tab = "tools"
|
current_tab = "tools"
|
||||||
|
|
||||||
|
|
||||||
class ClubMemberForm(forms.ModelForm):
|
class ClubMemberForm(forms.ModelForm):
|
||||||
"""
|
"""
|
||||||
Form handling the members of a club
|
Form handling the members of a club
|
||||||
"""
|
"""
|
||||||
error_css_class = 'error'
|
error_css_class = 'error'
|
||||||
required_css_class = 'required'
|
required_css_class = 'required'
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Membership
|
model = Membership
|
||||||
fields = ['user', 'role', 'start_date', 'description']
|
fields = ['user', 'role', 'start_date', 'description']
|
||||||
widgets = {
|
widgets = {
|
||||||
'start_date': SelectDate
|
'start_date': SelectDate
|
||||||
}
|
}
|
||||||
user = AutoCompleteSelectField('users', required=True, label=_("Select user"), help_text=None)
|
user = AutoCompleteSelectField('users', required=True, label=_("Select user"), help_text=None)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Overloaded to return the club, and not to a Membership object that has no view
|
Overloaded to return the club, and not to a Membership object that has no view
|
||||||
"""
|
"""
|
||||||
ret = super(ClubMemberForm, self).save(*args, **kwargs)
|
super(ClubMemberForm, self).save(*args, **kwargs)
|
||||||
return self.instance.club
|
return self.instance.club
|
||||||
|
|
||||||
|
|
||||||
class ClubMembersView(ClubTabsMixin, CanViewMixin, UpdateView):
|
class ClubMembersView(ClubTabsMixin, CanViewMixin, UpdateView):
|
||||||
"""
|
"""
|
||||||
View of a club's members
|
View of a club's members
|
||||||
@ -153,9 +153,9 @@ class ClubMembersView(ClubTabsMixin, CanViewMixin, UpdateView):
|
|||||||
That's why the save method of ClubMemberForm is overridden.
|
That's why the save method of ClubMemberForm is overridden.
|
||||||
"""
|
"""
|
||||||
form = super(ClubMembersView, self).get_form()
|
form = super(ClubMembersView, self).get_form()
|
||||||
if 'user' in form.data and form.data.get('user') != '': # Load an existing membership if possible
|
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()
|
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
|
if form.instance is None: # Instanciate a new membership
|
||||||
form.instance = Membership(club=self.object, user=self.request.user)
|
form.instance = Membership(club=self.object, user=self.request.user)
|
||||||
if not self.request.user.is_root:
|
if not self.request.user.is_root:
|
||||||
form.fields.pop('start_date', None)
|
form.fields.pop('start_date', None)
|
||||||
@ -174,7 +174,7 @@ class ClubMembersView(ClubTabsMixin, CanViewMixin, UpdateView):
|
|||||||
if (form.cleaned_data['role'] <= SITH_MAXIMUM_FREE_ROLE or
|
if (form.cleaned_data['role'] <= SITH_MAXIMUM_FREE_ROLE or
|
||||||
(ms is not None and ms.role >= form.cleaned_data['role']) or
|
(ms is not None and ms.role >= form.cleaned_data['role']) or
|
||||||
request.user.is_board_member or
|
request.user.is_board_member or
|
||||||
request.user.is_root):
|
request.user.is_root):
|
||||||
return self.form_valid(form)
|
return self.form_valid(form)
|
||||||
else:
|
else:
|
||||||
form.add_error(None, _("You do not have the permission to do that"))
|
form.add_error(None, _("You do not have the permission to do that"))
|
||||||
@ -182,6 +182,7 @@ class ClubMembersView(ClubTabsMixin, CanViewMixin, UpdateView):
|
|||||||
else:
|
else:
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
|
|
||||||
|
|
||||||
class ClubOldMembersView(ClubTabsMixin, CanViewMixin, DetailView):
|
class ClubOldMembersView(ClubTabsMixin, CanViewMixin, DetailView):
|
||||||
"""
|
"""
|
||||||
Old members of a club
|
Old members of a club
|
||||||
@ -191,11 +192,13 @@ class ClubOldMembersView(ClubTabsMixin, CanViewMixin, DetailView):
|
|||||||
template_name = 'club/club_old_members.jinja'
|
template_name = 'club/club_old_members.jinja'
|
||||||
current_tab = "elderlies"
|
current_tab = "elderlies"
|
||||||
|
|
||||||
|
|
||||||
class SellingsFormBase(forms.Form):
|
class SellingsFormBase(forms.Form):
|
||||||
begin_date = forms.DateTimeField(['%Y-%m-%d %H:%M:%S'], label=_("Begin date"), required=False, widget=SelectDateTime)
|
begin_date = forms.DateTimeField(['%Y-%m-%d %H:%M:%S'], label=_("Begin date"), required=False, widget=SelectDateTime)
|
||||||
end_date = forms.DateTimeField(['%Y-%m-%d %H:%M:%S'], label=_("End date"), required=False, widget=SelectDateTime)
|
end_date = forms.DateTimeField(['%Y-%m-%d %H:%M:%S'], label=_("End date"), required=False, widget=SelectDateTime)
|
||||||
counter = forms.ModelChoiceField(Counter.objects.order_by('name').all(), label=_("Counter"), required=False)
|
counter = forms.ModelChoiceField(Counter.objects.order_by('name').all(), label=_("Counter"), required=False)
|
||||||
|
|
||||||
|
|
||||||
class ClubSellingView(ClubTabsMixin, CanEditMixin, DetailView):
|
class ClubSellingView(ClubTabsMixin, CanEditMixin, DetailView):
|
||||||
"""
|
"""
|
||||||
Sellings of a club
|
Sellings of a club
|
||||||
@ -207,8 +210,8 @@ class ClubSellingView(ClubTabsMixin, CanEditMixin, DetailView):
|
|||||||
|
|
||||||
def get_form_class(self):
|
def get_form_class(self):
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'product': forms.ModelChoiceField(self.object.products.order_by('name').all(), label=_("Product"), required=False)
|
'product': forms.ModelChoiceField(self.object.products.order_by('name').all(), label=_("Product"), required=False)
|
||||||
}
|
}
|
||||||
return type('SellingsForm', (SellingsFormBase,), kwargs)
|
return type('SellingsForm', (SellingsFormBase,), kwargs)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
@ -235,6 +238,7 @@ class ClubSellingView(ClubTabsMixin, CanEditMixin, DetailView):
|
|||||||
kwargs['form'] = form
|
kwargs['form'] = form
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class ClubSellingCSVView(ClubSellingView):
|
class ClubSellingCSVView(ClubSellingView):
|
||||||
"""
|
"""
|
||||||
Generate sellings in csv for a given period
|
Generate sellings in csv for a given period
|
||||||
@ -252,27 +256,31 @@ class ClubSellingCSVView(ClubSellingView):
|
|||||||
writer.writerow([_t('Quantity'), kwargs['total_quantity']])
|
writer.writerow([_t('Quantity'), kwargs['total_quantity']])
|
||||||
writer.writerow([_t('Total'), kwargs['total']])
|
writer.writerow([_t('Total'), kwargs['total']])
|
||||||
writer.writerow([_t('Benefit'), kwargs['benefit']])
|
writer.writerow([_t('Benefit'), kwargs['benefit']])
|
||||||
writer.writerow([_t('Date'),_t('Counter'),_t('Barman'),_t('Customer'),_t('Label'),
|
writer.writerow([_t('Date'), _t('Counter'), _t('Barman'), _t('Customer'), _t('Label'),
|
||||||
_t('Quantity'), _t('Total'),_t('Payment method'), _t('Selling price'), _t('Purchase price'), _t('Benefit')])
|
_t('Quantity'), _t('Total'), _t('Payment method'), _t('Selling price'), _t('Purchase price'), _t('Benefit')])
|
||||||
for o in kwargs['result']:
|
for o in kwargs['result']:
|
||||||
row = [o.date, o.counter]
|
row = [o.date, o.counter]
|
||||||
if o.seller:
|
if o.seller:
|
||||||
row.append(o.seller.get_display_name())
|
row.append(o.seller.get_display_name())
|
||||||
else: row.append('')
|
else:
|
||||||
|
row.append('')
|
||||||
if o.customer:
|
if o.customer:
|
||||||
row.append(o.customer.user.get_display_name())
|
row.append(o.customer.user.get_display_name())
|
||||||
else: row.append('')
|
else:
|
||||||
row = row +[o.label, o.quantity, o.quantity * o.unit_price,
|
row.append('')
|
||||||
o.get_payment_method_display()]
|
row = row + [o.label, o.quantity, o.quantity * o.unit_price,
|
||||||
|
o.get_payment_method_display()]
|
||||||
if o.product:
|
if o.product:
|
||||||
row.append(o.product.selling_price)
|
row.append(o.product.selling_price)
|
||||||
row.append(o.product.purchase_price)
|
row.append(o.product.purchase_price)
|
||||||
row.append(o.product.selling_price - o.product.purchase_price)
|
row.append(o.product.selling_price - o.product.purchase_price)
|
||||||
else: row = row + ['', '', '']
|
else:
|
||||||
|
row = row + ['', '', '']
|
||||||
writer.writerow(row)
|
writer.writerow(row)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
class ClubEditView(ClubTabsMixin, CanEditMixin, UpdateView):
|
class ClubEditView(ClubTabsMixin, CanEditMixin, UpdateView):
|
||||||
"""
|
"""
|
||||||
Edit a Club's main informations (for the club's members)
|
Edit a Club's main informations (for the club's members)
|
||||||
@ -283,6 +291,7 @@ class ClubEditView(ClubTabsMixin, CanEditMixin, UpdateView):
|
|||||||
template_name = 'core/edit.jinja'
|
template_name = 'core/edit.jinja'
|
||||||
current_tab = "edit"
|
current_tab = "edit"
|
||||||
|
|
||||||
|
|
||||||
class ClubEditPropView(ClubTabsMixin, CanEditPropMixin, UpdateView):
|
class ClubEditPropView(ClubTabsMixin, CanEditPropMixin, UpdateView):
|
||||||
"""
|
"""
|
||||||
Edit the properties of a Club object (for the Sith admins)
|
Edit the properties of a Club object (for the Sith admins)
|
||||||
@ -293,6 +302,7 @@ class ClubEditPropView(ClubTabsMixin, CanEditPropMixin, UpdateView):
|
|||||||
template_name = 'core/edit.jinja'
|
template_name = 'core/edit.jinja'
|
||||||
current_tab = "props"
|
current_tab = "props"
|
||||||
|
|
||||||
|
|
||||||
class ClubCreateView(CanEditPropMixin, CreateView):
|
class ClubCreateView(CanEditPropMixin, CreateView):
|
||||||
"""
|
"""
|
||||||
Create a club (for the Sith admin)
|
Create a club (for the Sith admin)
|
||||||
@ -302,6 +312,7 @@ class ClubCreateView(CanEditPropMixin, CreateView):
|
|||||||
fields = ['name', 'unix_name', 'parent']
|
fields = ['name', 'unix_name', 'parent']
|
||||||
template_name = 'core/edit.jinja'
|
template_name = 'core/edit.jinja'
|
||||||
|
|
||||||
|
|
||||||
class MembershipSetOldView(CanEditMixin, DetailView):
|
class MembershipSetOldView(CanEditMixin, DetailView):
|
||||||
"""
|
"""
|
||||||
Set a membership as beeing old
|
Set a membership as beeing old
|
||||||
@ -319,8 +330,9 @@ class MembershipSetOldView(CanEditMixin, DetailView):
|
|||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
return HttpResponseRedirect(reverse('club:club_members', args=self.args, kwargs={'club_id': self.object.club.id}))
|
return HttpResponseRedirect(reverse('club:club_members', args=self.args, kwargs={'club_id': self.object.club.id}))
|
||||||
|
|
||||||
|
|
||||||
class ClubStatView(TemplateView):
|
class ClubStatView(TemplateView):
|
||||||
template_name="club/stats.jinja"
|
template_name = "club/stats.jinja"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
kwargs = super(ClubStatView, self).get_context_data(**kwargs)
|
kwargs = super(ClubStatView, self).get_context_data(**kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user