diff --git a/core/management/commands/populate.py b/core/management/commands/populate.py
index 239a3de9..7328c399 100644
--- a/core/management/commands/populate.py
+++ b/core/management/commands/populate.py
@@ -6,7 +6,7 @@ from django.conf import settings
from core.models import Group, User, Page, PageRev
from accounting.models import Customer, GeneralJournal, ProductType, Product
-from club.models import Club
+from club.models import Club, Membership
from subscription.models import Subscription, Subscriber
class Command(BaseCommand):
@@ -48,7 +48,6 @@ Welcome to the wiki page!
s.set_password("plop")
s.save()
s.view_groups=[settings.AE_GROUPS['members']['id']]
- s.groups=[settings.AE_GROUPS['board']['id']]
s.save()
# Adding user Guy
u = User(username='guy', last_name="Carlier", first_name="Guy",
@@ -98,6 +97,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
address="Woenzel", parent=guyut).save()
Club(name="BdF", unix_name="bdf",
address="Guyéuéyuéyuyé").save()
+ Membership(user=s, club=ae, role=3, description="").save()
# Accounting test values:
Customer(user=s, account_id="6568j").save()
@@ -105,5 +105,11 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
p.save()
Product(name="Barbar", code="BARB", product_type=p, purchase_price="1.50", selling_price="1.7",
special_selling_price="1.6").save()
+ Product(name="Chimay", code="CBLE", product_type=p, purchase_price="1.50", selling_price="1.7",
+ special_selling_price="1.6").save()
+ Product(name="Corsendonk", code="CORS", product_type=p, purchase_price="1.50", selling_price="1.7",
+ special_selling_price="1.6").save()
+ Product(name="Carolus", code="CARO", product_type=p, purchase_price="1.50", selling_price="1.7",
+ special_selling_price="1.6").save()
GeneralJournal(start_date="2015-06-12", name="A15").save()
diff --git a/core/templates/core/delete_confirm.jinja b/core/templates/core/delete_confirm.jinja
new file mode 100644
index 00000000..79b6d08d
--- /dev/null
+++ b/core/templates/core/delete_confirm.jinja
@@ -0,0 +1,14 @@
+{% extends "core/base.jinja" %}
+
+{% block content %}
+
Delete confirmation
+
+{% endblock %}
+
+
+
+
diff --git a/core/templates/core/user_tools.jinja b/core/templates/core/user_tools.jinja
index cdd0fdfd..5920a7f7 100644
--- a/core/templates/core/user_tools.jinja
+++ b/core/templates/core/user_tools.jinja
@@ -14,7 +14,7 @@
{% endif %}
{% if user.is_in_group(settings.AE_GROUPS['root']['name']) or user.is_in_group(settings.AE_GROUPS['board']['name']) %}
Subscriptions
- Counters management
+ Counters management
{% endif %}
diff --git a/counter/migrations/0002_counter_type.py b/counter/migrations/0002_counter_type.py
new file mode 100644
index 00000000..10fb3b20
--- /dev/null
+++ b/counter/migrations/0002_counter_type.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('counter', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='counter',
+ name='type',
+ field=models.CharField(max_length=255, default='BAR', verbose_name='subscription type', choices=[('BAR', 'Bar'), ('OFFICE', 'Office')]),
+ preserve_default=False,
+ ),
+ ]
diff --git a/counter/models.py b/counter/models.py
index 0e5fbbee..8d1d81b3 100644
--- a/counter/models.py
+++ b/counter/models.py
@@ -1,6 +1,7 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
+from django.core.urlresolvers import reverse
from club.models import Club
from accounting.models import Product
@@ -10,6 +11,9 @@ class Counter(models.Model):
name = models.CharField(_('name'), max_length=30)
club = models.ForeignKey(Club, related_name="counters")
products = models.ManyToManyField(Product, related_name="counters", blank=True)
+ type = models.CharField(_('subscription type'),
+ max_length=255,
+ choices=[('BAR',_('Bar')), ('OFFICE',_('Office'))]) # TODO: add _ to translate
edit_groups = models.ManyToManyField(Group, related_name="editable_counters", blank=True)
view_groups = models.ManyToManyField(Group, related_name="viewable_counters", blank=True)
@@ -20,3 +24,9 @@ class Counter(models.Model):
def __str__(self):
return self.name
+
+ def get_absolute_url(self):
+ return reverse('counter:details', kwargs={'counter_id': self.id})
+
+ def can_be_viewed_by(self, user):
+ return user.is_in_group(settings.AE_GROUPS['board']['name'])
diff --git a/counter/templates/counter/counter_edit.jinja b/counter/templates/counter/counter_edit.jinja
new file mode 100644
index 00000000..6cc3efe3
--- /dev/null
+++ b/counter/templates/counter/counter_edit.jinja
@@ -0,0 +1,13 @@
+{% extends "core/base.jinja" %}
+
+{% block content %}
+ Edit counter
+
+{% endblock %}
+
+
+
diff --git a/counter/templates/counter/counter_list.jinja b/counter/templates/counter/counter_list.jinja
index a66dbb55..6457336f 100644
--- a/counter/templates/counter/counter_list.jinja
+++ b/counter/templates/counter/counter_list.jinja
@@ -1,15 +1,18 @@
{% extends "core/base.jinja" %}
{% block title %}
- Counter list
+ Counter admin list
{% endblock %}
{% block content %}
+ New counter
{% if counter_list %}
- Counter list
+ Counter admin list
{% else %}
diff --git a/counter/urls.py b/counter/urls.py
index 79d1c866..d0aa55f9 100644
--- a/counter/urls.py
+++ b/counter/urls.py
@@ -3,8 +3,11 @@ from django.conf.urls import url, include
from counter.views import *
urlpatterns = [
- url(r'^$', CounterListView.as_view(), name='list'),
url(r'^(?P[0-9]+)$', CounterDetail.as_view(), name='details'),
+ url(r'^admin/(?P[0-9]+)$', CounterEditView.as_view(), name='admin'),
+ url(r'^admin$', CounterListView.as_view(), name='admin_list'),
+ url(r'^admin/new$', CounterCreateView.as_view(), name='new'),
+ url(r'^admin/delete/(?P[0-9]+)$', CounterDeleteView.as_view(), name='delete'),
]
diff --git a/counter/views.py b/counter/views.py
index cc234c91..d36c5554 100644
--- a/counter/views.py
+++ b/counter/views.py
@@ -1,5 +1,9 @@
from django.shortcuts import render
from django.views.generic import ListView, DetailView
+from django.views.generic.edit import UpdateView, CreateView, DeleteView
+from django.forms.models import modelform_factory
+from django.forms import CheckboxSelectMultiple
+from django.core.urlresolvers import reverse_lazy
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
from counter.models import Counter
@@ -13,3 +17,31 @@ class CounterDetail(CanViewMixin, DetailView):
model = Counter
template_name = 'counter/counter_detail.jinja'
pk_url_kwarg = "counter_id"
+
+class CounterEditView(CanEditMixin, UpdateView):
+ """
+ Edit a Counter's main informations (for the counter's members)
+ """
+ model = Counter
+ form_class = modelform_factory(Counter, fields=['name', 'club', 'type', 'products'],
+ widgets={'products':CheckboxSelectMultiple})
+ pk_url_kwarg = "counter_id"
+ template_name = 'counter/counter_edit.jinja'
+
+class CounterCreateView(CanEditMixin, CreateView):
+ """
+ Edit a Counter's main informations (for the counter's members)
+ """
+ model = Counter
+ form_class = modelform_factory(Counter, fields=['name', 'club', 'type', 'products'],
+ widgets={'products':CheckboxSelectMultiple})
+ template_name = 'counter/counter_edit.jinja'
+
+class CounterDeleteView(CanEditMixin, DeleteView):
+ """
+ Edit a Counter's main informations (for the counter's members)
+ """
+ model = Counter
+ pk_url_kwarg = "counter_id"
+ template_name = 'core/delete_confirm.jinja'
+ success_url = reverse_lazy('counter:admin_list')
diff --git a/sith/settings.py b/sith/settings.py
index c93d2199..16b4a615 100644
--- a/sith/settings.py
+++ b/sith/settings.py
@@ -191,11 +191,11 @@ AE_GROUPS = {
},
'board': {
'id': 2,
- 'name': "ae_bureau",
+ 'name': "ae-board",
},
'members': {
'id': 3,
- 'name': "ae_membres",
+ 'name': "ae-members",
},
'public': {
'id': 4,