mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 02:24:26 +00:00
Improve counters views
This commit is contained in:
parent
21f1393097
commit
5bcc94f992
@ -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()
|
||||
|
||||
|
14
core/templates/core/delete_confirm.jinja
Normal file
14
core/templates/core/delete_confirm.jinja
Normal file
@ -0,0 +1,14 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Delete confirmation</h2>
|
||||
<form action="" method="post">{% csrf_token %}
|
||||
<p>Are you sure you want to delete "{{ object }}"?</p>
|
||||
<input type="submit" value="Confirm" />
|
||||
<input type="submit" name="cancel" value="Cancel" />
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
||||
|
@ -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']) %}
|
||||
<li><a href="{{ url('subscription:subscription') }}">Subscriptions</a></li>
|
||||
<li><a href="{{ url('counter:list') }}">Counters management</a></li>
|
||||
<li><a href="{{ url('counter:admin_list') }}">Counters management</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
|
20
counter/migrations/0002_counter_type.py
Normal file
20
counter/migrations/0002_counter_type.py
Normal file
@ -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,
|
||||
),
|
||||
]
|
@ -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'])
|
||||
|
13
counter/templates/counter/counter_edit.jinja
Normal file
13
counter/templates/counter/counter_edit.jinja
Normal file
@ -0,0 +1,13 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Edit counter</h2>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p() }}
|
||||
<p><input type="submit" value="Save!" /></p>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@ -1,15 +1,18 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
Counter list
|
||||
Counter admin list
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p><a href="{{ url('counter:new') }}">New counter</a></p>
|
||||
{% if counter_list %}
|
||||
<h3>Counter list</h3>
|
||||
<h3>Counter admin list</h3>
|
||||
<ul>
|
||||
{% for c in counter_list %}
|
||||
<li><a href="{{ url('counter:details', counter_id=c.id) }}">{{ c }}</a></li>
|
||||
<li><a href="{{ url('counter:details', counter_id=c.id) }}">{{ c }}</a> -
|
||||
<a href="{{ url('counter:admin', counter_id=c.id) }}">Edit</a> -
|
||||
<a href="{{ url('counter:delete', counter_id=c.id) }}">Delete</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
|
@ -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<counter_id>[0-9]+)$', CounterDetail.as_view(), name='details'),
|
||||
url(r'^admin/(?P<counter_id>[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<counter_id>[0-9]+)$', CounterDeleteView.as_view(), name='delete'),
|
||||
]
|
||||
|
||||
|
||||
|
@ -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')
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user