|
|
|
@@ -23,27 +23,21 @@
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
from django import forms
|
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
from django.views.generic import ListView, DetailView, TemplateView
|
|
|
|
|
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.core.urlresolvers import reverse
|
|
|
|
|
from django.utils import timezone
|
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
from django.utils.translation import ugettext as _t
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
from ajax_select.fields import AutoCompleteSelectField
|
|
|
|
|
|
|
|
|
|
from datetime import timedelta
|
|
|
|
|
|
|
|
|
|
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 core.models import User
|
|
|
|
|
from sith.settings import SITH_MAXIMUM_FREE_ROLE, SITH_MAIN_BOARD_GROUP
|
|
|
|
|
from counter.models import Product, Selling, Counter
|
|
|
|
|
from sith.settings import SITH_MAXIMUM_FREE_ROLE
|
|
|
|
|
from counter.models import Selling, Counter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClubTabsMixin(TabedViewMixin):
|
|
|
|
|
def get_tabs_title(self):
|
|
|
|
@@ -91,6 +85,7 @@ class ClubTabsMixin(TabedViewMixin):
|
|
|
|
|
})
|
|
|
|
|
return tab_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClubListView(ListView):
|
|
|
|
|
"""
|
|
|
|
|
List the Clubs
|
|
|
|
@@ -98,6 +93,7 @@ class ClubListView(ListView):
|
|
|
|
|
model = Club
|
|
|
|
|
template_name = 'club/club_list.jinja'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClubView(ClubTabsMixin, DetailView):
|
|
|
|
|
"""
|
|
|
|
|
Front page of a Club
|
|
|
|
@@ -107,6 +103,7 @@ class ClubView(ClubTabsMixin, DetailView):
|
|
|
|
|
template_name = 'club/club_detail.jinja'
|
|
|
|
|
current_tab = "infos"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClubToolsView(ClubTabsMixin, CanEditMixin, DetailView):
|
|
|
|
|
"""
|
|
|
|
|
Tools page of a Club
|
|
|
|
@@ -116,12 +113,14 @@ class ClubToolsView(ClubTabsMixin, CanEditMixin, DetailView):
|
|
|
|
|
template_name = 'club/club_tools.jinja'
|
|
|
|
|
current_tab = "tools"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClubMemberForm(forms.ModelForm):
|
|
|
|
|
"""
|
|
|
|
|
Form handling the members of a club
|
|
|
|
|
"""
|
|
|
|
|
error_css_class = 'error'
|
|
|
|
|
required_css_class = 'required'
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
model = Membership
|
|
|
|
|
fields = ['user', 'role', 'start_date', 'description']
|
|
|
|
@@ -134,9 +133,10 @@ class ClubMemberForm(forms.ModelForm):
|
|
|
|
|
"""
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClubMembersView(ClubTabsMixin, CanViewMixin, UpdateView):
|
|
|
|
|
"""
|
|
|
|
|
View of a club's members
|
|
|
|
@@ -182,6 +182,7 @@ class ClubMembersView(ClubTabsMixin, CanViewMixin, UpdateView):
|
|
|
|
|
else:
|
|
|
|
|
return self.form_invalid(form)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClubOldMembersView(ClubTabsMixin, CanViewMixin, DetailView):
|
|
|
|
|
"""
|
|
|
|
|
Old members of a club
|
|
|
|
@@ -191,11 +192,13 @@ class ClubOldMembersView(ClubTabsMixin, CanViewMixin, DetailView):
|
|
|
|
|
template_name = 'club/club_old_members.jinja'
|
|
|
|
|
current_tab = "elderlies"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SellingsFormBase(forms.Form):
|
|
|
|
|
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)
|
|
|
|
|
counter = forms.ModelChoiceField(Counter.objects.order_by('name').all(), label=_("Counter"), required=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClubSellingView(ClubTabsMixin, CanEditMixin, DetailView):
|
|
|
|
|
"""
|
|
|
|
|
Sellings of a club
|
|
|
|
@@ -235,6 +238,7 @@ class ClubSellingView(ClubTabsMixin, CanEditMixin, DetailView):
|
|
|
|
|
kwargs['form'] = form
|
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClubSellingCSVView(ClubSellingView):
|
|
|
|
|
"""
|
|
|
|
|
Generate sellings in csv for a given period
|
|
|
|
@@ -258,21 +262,25 @@ class ClubSellingCSVView(ClubSellingView):
|
|
|
|
|
row = [o.date, o.counter]
|
|
|
|
|
if o.seller:
|
|
|
|
|
row.append(o.seller.get_display_name())
|
|
|
|
|
else: row.append('')
|
|
|
|
|
else:
|
|
|
|
|
row.append('')
|
|
|
|
|
if o.customer:
|
|
|
|
|
row.append(o.customer.user.get_display_name())
|
|
|
|
|
else: row.append('')
|
|
|
|
|
else:
|
|
|
|
|
row.append('')
|
|
|
|
|
row = row + [o.label, o.quantity, o.quantity * o.unit_price,
|
|
|
|
|
o.get_payment_method_display()]
|
|
|
|
|
if o.product:
|
|
|
|
|
row.append(o.product.selling_price)
|
|
|
|
|
row.append(o.product.purchase_price)
|
|
|
|
|
row.append(o.product.selling_price - o.product.purchase_price)
|
|
|
|
|
else: row = row + ['', '', '']
|
|
|
|
|
else:
|
|
|
|
|
row = row + ['', '', '']
|
|
|
|
|
writer.writerow(row)
|
|
|
|
|
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClubEditView(ClubTabsMixin, CanEditMixin, UpdateView):
|
|
|
|
|
"""
|
|
|
|
|
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'
|
|
|
|
|
current_tab = "edit"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClubEditPropView(ClubTabsMixin, CanEditPropMixin, UpdateView):
|
|
|
|
|
"""
|
|
|
|
|
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'
|
|
|
|
|
current_tab = "props"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClubCreateView(CanEditPropMixin, CreateView):
|
|
|
|
|
"""
|
|
|
|
|
Create a club (for the Sith admin)
|
|
|
|
@@ -302,6 +312,7 @@ class ClubCreateView(CanEditPropMixin, CreateView):
|
|
|
|
|
fields = ['name', 'unix_name', 'parent']
|
|
|
|
|
template_name = 'core/edit.jinja'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MembershipSetOldView(CanEditMixin, DetailView):
|
|
|
|
|
"""
|
|
|
|
|
Set a membership as beeing old
|
|
|
|
@@ -319,6 +330,7 @@ class MembershipSetOldView(CanEditMixin, DetailView):
|
|
|
|
|
self.object = self.get_object()
|
|
|
|
|
return HttpResponseRedirect(reverse('club:club_members', args=self.args, kwargs={'club_id': self.object.club.id}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClubStatView(TemplateView):
|
|
|
|
|
template_name = "club/stats.jinja"
|
|
|
|
|
|
|
|
|
|