Commit 21f13930 authored by Skia's avatar Skia

Add basic counter model

parent 7d7652e3
Pipeline #2 skipped
......@@ -4,3 +4,4 @@ db.sqlite3
.DS_Store
env_sith
doc/html
data/
......@@ -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)
......
......@@ -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",
......
......@@ -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):
......
......@@ -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']) %}
<li><a href="{{ url('subscription:subscription') }}">Subscriptions</a></li>
<li><a href="{{ url('counter:list') }}">Counters management</a></li>
{% endif %}
</ul>
......
from django.contrib import admin
from counter.models import Counter
# Register your models here.
admin.site.register(Counter)
# -*- 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)),
],
),
]
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
{% extends "core/base.jinja" %}
{% block content %}
<h3>Counter</h3>
<h4>{{ counter }}</h4>
<p><strong>Club: </strong> {{ counter.club }}</p>
<p><strong>Products: </strong> {{ counter.products.all() }}</p>
{% endblock %}
{% extends "core/base.jinja" %}
{% block title %}
Counter list
{% endblock %}
{% block content %}
{% if counter_list %}
<h3>Counter list</h3>
<ul>
{% for c in counter_list %}
<li><a href="{{ url('counter:details', counter_id=c.id) }}">{{ c }}</a></li>
{% endfor %}
</ul>
{% else %}
There is no counters in this website.
{% endif %}
{% endblock %}
from django.test import TestCase
# Create your tests here.
from django.conf.urls import url, include
from counter.views import *
urlpatterns = [
url(r'^$', CounterListView.as_view(), name='list'),
url(r'^(?P<counter_id>[0-9]+)$', CounterDetail.as_view(), name='details'),
]
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"
......@@ -42,6 +42,7 @@ INSTALLED_APPS = (
'club',
'subscription',
'accounting',
'counter',
)
MIDDLEWARE_CLASSES = (
......
......@@ -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!!!
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