diff --git a/.gitignore b/.gitignore
index 95f82ac7..6f07f810 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ db.sqlite3
.DS_Store
env_sith
doc/html
+data/
diff --git a/accounting/models.py b/accounting/models.py
index d6ac8222..f95051ae 100644
--- a/accounting/models.py
+++ b/accounting/models.py
@@ -39,7 +39,7 @@ class Customer(models.Model):
class ProductType(models.Model):
"""
This describes a product type
- Useful only for categorizing, changes are made at the product level
+ Useful only for categorizing, changes are made at the product level for now
"""
name = models.CharField(_('name'), max_length=30)
description = models.TextField(_('description'), null=True, blank=True)
diff --git a/core/management/commands/populate.py b/core/management/commands/populate.py
index c3132de4..239a3de9 100644
--- a/core/management/commands/populate.py
+++ b/core/management/commands/populate.py
@@ -48,6 +48,7 @@ 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",
diff --git a/core/models.py b/core/models.py
index 31eacd3e..5da48a0c 100644
--- a/core/models.py
+++ b/core/models.py
@@ -101,7 +101,7 @@ class User(AbstractBaseUser, PermissionsMixin):
if group_name == settings.AE_GROUPS['public']['name']:
return True
if group_name == settings.AE_GROUPS['members']['name']: # We check the subscription if asked
- try:
+ try: # TODO: change for a test in settings.INSTALLED_APP
from subscription import Subscriber
s = Subscriber.objects.filter(pk=self.pk).first()
if s is not None and s.is_subscribed():
@@ -110,6 +110,16 @@ class User(AbstractBaseUser, PermissionsMixin):
return False
except Exception as e:
print(e)
+ return False
+ if group_name[-6:] == "-board":
+ try: # TODO: change for a test in settings.INSTALLED_APP
+ from club.models import Club
+ name = group_name[:-6]
+ c = Club.objects.filter(unix_name=name).first()
+ return c.get_membership_for(self).role >= 2
+ except Exception as e:
+ print(e)
+ return False
return self.groups.filter(name=group_name).exists()
def get_profile(self):
diff --git a/core/templates/core/user_tools.jinja b/core/templates/core/user_tools.jinja
index 2ee9d738..cdd0fdfd 100644
--- a/core/templates/core/user_tools.jinja
+++ b/core/templates/core/user_tools.jinja
@@ -14,6 +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
{% endif %}
diff --git a/counter/__init__.py b/counter/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/counter/admin.py b/counter/admin.py
new file mode 100644
index 00000000..d3f24f8d
--- /dev/null
+++ b/counter/admin.py
@@ -0,0 +1,6 @@
+from django.contrib import admin
+
+from counter.models import Counter
+
+# Register your models here.
+admin.site.register(Counter)
diff --git a/counter/migrations/0001_initial.py b/counter/migrations/0001_initial.py
new file mode 100644
index 00000000..d852a3f4
--- /dev/null
+++ b/counter/migrations/0001_initial.py
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('club', '0004_auto_20160321_1648'),
+ ('core', '0001_initial'),
+ ('accounting', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Counter',
+ fields=[
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)),
+ ('name', models.CharField(max_length=30, verbose_name='name')),
+ ('club', models.ForeignKey(to='club.Club', related_name='counters')),
+ ('edit_groups', models.ManyToManyField(related_name='editable_counters', to='core.Group', blank=True)),
+ ('products', models.ManyToManyField(related_name='counters', to='accounting.Product', blank=True)),
+ ('view_groups', models.ManyToManyField(related_name='viewable_counters', to='core.Group', blank=True)),
+ ],
+ ),
+ ]
diff --git a/counter/migrations/__init__.py b/counter/migrations/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/counter/models.py b/counter/models.py
new file mode 100644
index 00000000..0e5fbbee
--- /dev/null
+++ b/counter/models.py
@@ -0,0 +1,22 @@
+from django.db import models
+from django.utils.translation import ugettext_lazy as _
+from django.conf import settings
+
+from club.models import Club
+from accounting.models import Product
+from core.models import Group
+
+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)
+ edit_groups = models.ManyToManyField(Group, related_name="editable_counters", blank=True)
+ view_groups = models.ManyToManyField(Group, related_name="viewable_counters", blank=True)
+
+ def __getattribute__(self, name):
+ if name == "owner_group":
+ return Group(name=self.club.unix_name+"-board")
+ return object.__getattribute__(self, name)
+
+ def __str__(self):
+ return self.name
diff --git a/counter/templates/counter/counter_detail.jinja b/counter/templates/counter/counter_detail.jinja
new file mode 100644
index 00000000..f0c6b657
--- /dev/null
+++ b/counter/templates/counter/counter_detail.jinja
@@ -0,0 +1,11 @@
+{% extends "core/base.jinja" %}
+
+{% block content %}
+ Counter
+ {{ counter }}
+ Club: {{ counter.club }}
+ Products: {{ counter.products.all() }}
+{% endblock %}
+
+
+
diff --git a/counter/templates/counter/counter_list.jinja b/counter/templates/counter/counter_list.jinja
new file mode 100644
index 00000000..a66dbb55
--- /dev/null
+++ b/counter/templates/counter/counter_list.jinja
@@ -0,0 +1,21 @@
+{% extends "core/base.jinja" %}
+
+{% block title %}
+ Counter list
+{% endblock %}
+
+{% block content %}
+ {% if counter_list %}
+ Counter list
+
+ {% for c in counter_list %}
+ - {{ c }}
+ {% endfor %}
+
+ {% else %}
+ There is no counters in this website.
+ {% endif %}
+{% endblock %}
+
+
+
diff --git a/counter/tests.py b/counter/tests.py
new file mode 100644
index 00000000..7ce503c2
--- /dev/null
+++ b/counter/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/counter/urls.py b/counter/urls.py
new file mode 100644
index 00000000..79d1c866
--- /dev/null
+++ b/counter/urls.py
@@ -0,0 +1,10 @@
+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'),
+]
+
+
diff --git a/counter/views.py b/counter/views.py
new file mode 100644
index 00000000..cc234c91
--- /dev/null
+++ b/counter/views.py
@@ -0,0 +1,15 @@
+from django.shortcuts import render
+from django.views.generic import ListView, DetailView
+
+from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
+from counter.models import Counter
+# Create your views here.
+
+class CounterListView(CanViewMixin, ListView):
+ model = Counter
+ template_name = 'counter/counter_list.jinja'
+
+class CounterDetail(CanViewMixin, DetailView):
+ model = Counter
+ template_name = 'counter/counter_detail.jinja'
+ pk_url_kwarg = "counter_id"
diff --git a/sith/settings.py b/sith/settings.py
index 7a6d200e..c93d2199 100644
--- a/sith/settings.py
+++ b/sith/settings.py
@@ -42,6 +42,7 @@ INSTALLED_APPS = (
'club',
'subscription',
'accounting',
+ 'counter',
)
MIDDLEWARE_CLASSES = (
diff --git a/sith/urls.py b/sith/urls.py
index 42130de9..55847365 100644
--- a/sith/urls.py
+++ b/sith/urls.py
@@ -25,5 +25,6 @@ urlpatterns = [
url(r'^', include('core.urls', namespace="core", app_name="core")),
url(r'^subscription/', include('subscription.urls', namespace="subscription", app_name="subscription")),
url(r'^club/', include('club.urls', namespace="club", app_name="club")),
+ url(r'^counter/', include('counter.urls', namespace="counter", app_name="counter")),
url(r'^admin/', include(admin.site.urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # TODO: remove me for production!!!