Improvements in counter admin templates

This commit is contained in:
Skia
2016-09-04 15:49:25 +02:00
parent d93dda1c0e
commit e1ce661a04
13 changed files with 291 additions and 131 deletions

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('counter', '0006_auto_20160831_1304'),
]
operations = [
migrations.AddField(
model_name='product',
name='archived',
field=models.BooleanField(verbose_name='archived', default=False),
),
]

View File

@ -89,6 +89,7 @@ class Product(models.Model):
parent_product = models.ForeignKey('self', related_name='children_products', verbose_name=_("parent product"), null=True,
blank=True, on_delete=models.SET_NULL)
buying_groups = models.ManyToManyField(Group, related_name='products', verbose_name=_("buying groups"), blank=True)
archived = models.BooleanField(_("archived"), default=False)
class Meta:
verbose_name = _('product')
@ -184,7 +185,7 @@ class Counter(models.Model):
return bl[random.randrange(0, len(bl))]
def is_open(self):
return len(self.get_barmen_list()) > 0:
return len(self.get_barmen_list()) > 0
def barman_list(self):
return [b.id for b in self.get_barmen_list()]

View File

@ -0,0 +1,40 @@
{% extends "core/base.jinja" %}
{% block content %}
<div class="tool-bar">
<div>{% trans %}Counter administration{% endtrans %}</div>
<div class="tools">
<a href="{{ url('counter:admin_list') }}"
{%- if tab == "counters" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Counters{% endtrans %}</a>
<a href="{{ url('counter:product_list') }}"
{%- if tab == "products" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Products{% endtrans %}</a>
<a href="{{ url('counter:product_list_archived') }}"
{%- if tab == "archive" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Archived products{% endtrans %}</a>
<a href="{{ url('counter:producttype_list') }}"
{%- if tab == "product_types" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Product types{% endtrans %}</a>
</div>
<hr>
</div>
<div>
{% block admin_content %}
{% endblock %}
</div>
{% endblock %}

View File

@ -1,21 +1,46 @@
{% extends "core/base.jinja" %}
{% extends "counter/counter_base.jinja" %}
{% block title %}
{% trans %}Counter admin list{% endtrans %}
{% endblock %}
{% block content %}
{% block admin_content %}
<p><a href="{{ url('counter:new') }}">{% trans %}New counter{% endtrans %}</a></p>
{% if counter_list %}
<h3>{% trans %}Counter admin list{% endtrans %}</h3>
<h4>{% trans %}Eboutic{% endtrans %}</h4>
<ul>
{% for c in counter_list %}
<li>
{% if c.type == "EBOUTIC" %}
<a href="{{ url('eboutic:main') }}">{{ c }}</a> -
{% else %}
<a href="{{ url('counter:details', counter_id=c.id) }}">{{ c }}</a> -
{% for c in counter_list.filter(type="EBOUTIC").order_by('name') %}
<li>
<a href="{{ url('eboutic:main') }}">{{ c }}</a> -
{% if user.can_edit(c) %}
<a href="{{ url('counter:admin', counter_id=c.id) }}">{% trans %}Edit{% endtrans %}</a> -
{% endif %}
{% if user.is_owner(c) %}
<a href="{{ url('counter:prop_admin', counter_id=c.id) }}">{% trans %}Props{% endtrans %}</a>
{% endif %}
</li>
{% endfor %}
</ul>
<h4>{% trans %}Bars{% endtrans %}</h4>
<ul>
{% for c in counter_list.filter(type="BAR").order_by('name') %}
<li>
<a href="{{ url('counter:details', counter_id=c.id) }}">{{ c }}</a> -
{% if user.can_edit(c) %}
<a href="{{ url('counter:admin', counter_id=c.id) }}">{% trans %}Edit{% endtrans %}</a> -
{% endif %}
{% if user.is_owner(c) %}
<a href="{{ url('counter:prop_admin', counter_id=c.id) }}">{% trans %}Props{% endtrans %}</a>
{% endif %}
</li>
{% endfor %}
</ul>
<h4>{% trans %}Offices{% endtrans %}</h4>
<ul>
{% for c in counter_list.exclude(type="BAR").exclude(type="EBOUTIC").order_by('name') %}
<li>
<a href="{{ url('counter:details', counter_id=c.id) }}">{{ c }}</a> -
{% if user.can_edit(c) %}
<a href="{{ url('counter:admin', counter_id=c.id) }}">{% trans %}Edit{% endtrans %}</a> -
{% endif %}

View File

@ -1,18 +1,23 @@
{% extends "core/base.jinja" %}
{% extends "counter/counter_base.jinja" %}
{% block title %}
{% trans %}Product list{% endtrans %}
{% endblock %}
{% block content %}
{% block admin_content %}
{% if tab == "products" %}
<p><a href="{{ url('counter:new_product') }}">{% trans %}New product{% endtrans %}</a></p>
{% endif %}
{% if product_list %}
<h3>{% trans %}Product list{% endtrans %}</h3>
{% for t in ProductType.objects.all().order_by('name') %}
<h4>{{ t }}</h4>
<ul>
{% for p in product_list %}
{% for p in product_list.filter(product_type=t).all().order_by('name') %}
<li><a href="{{ url('counter:product_edit', product_id=p.id) }}">{{ p }}</a></li>
{% endfor %}
</ul>
{% endfor %}
{% else %}
{% trans %}There is no products in this website.{% endtrans %}
{% endif %}

View File

@ -1,10 +1,10 @@
{% extends "core/base.jinja" %}
{% extends "counter/counter_base.jinja" %}
{% block title %}
{% trans %}Product type list{% endtrans %}
{% endblock %}
{% block content %}
{% block admin_content %}
<p><a href="{{ url('counter:new_producttype') }}">{% trans %}New product type{% endtrans %}</a></p>
{% if producttype_list %}
<h3>{% trans %}Product type list{% endtrans %}</h3>

View File

@ -14,6 +14,7 @@ urlpatterns = [
url(r'^admin/new$', CounterCreateView.as_view(), name='new'),
url(r'^admin/delete/(?P<counter_id>[0-9]+)$', CounterDeleteView.as_view(), name='delete'),
url(r'^admin/product/list$', ProductListView.as_view(), name='product_list'),
url(r'^admin/product/list_archived$', ProductArchivedListView.as_view(), name='product_list_archived'),
url(r'^admin/product/create$', ProductCreateView.as_view(), name='new_product'),
url(r'^admin/product/(?P<product_id>[0-9]+)$', ProductEditView.as_view(), name='product_edit'),
url(r'^admin/producttype/list$', ProductTypeListView.as_view(), name='producttype_list'),

View File

@ -390,6 +390,11 @@ class CounterListView(CanViewMixin, ListView):
model = Counter
template_name = 'counter/counter_list.jinja'
def get_context_data(self, **kwargs):
kwargs = super(CounterListView, self).get_context_data(**kwargs)
kwargs['tab'] = "counters"
return kwargs
class CounterEditForm(forms.ModelForm):
class Meta:
model = Counter
@ -445,6 +450,11 @@ class ProductTypeListView(CanEditPropMixin, ListView):
model = ProductType
template_name = 'counter/producttype_list.jinja'
def get_context_data(self, **kwargs):
kwargs = super(ProductTypeListView, self).get_context_data(**kwargs)
kwargs['tab'] = "product_types"
return kwargs
class ProductTypeCreateView(CanCreateMixin, CreateView):
"""
A create view for the admins
@ -462,19 +472,39 @@ class ProductTypeEditView(CanEditPropMixin, UpdateView):
fields = ['name', 'description', 'icon']
pk_url_kwarg = "type_id"
class ProductArchivedListView(CanEditPropMixin, ListView):
"""
A list view for the admins
"""
model = Product
template_name = 'counter/product_list.jinja'
queryset = Product.objects.filter(archived=True)
ordering = ['name']
def get_context_data(self, **kwargs):
kwargs = super(ProductArchivedListView, self).get_context_data(**kwargs)
kwargs['tab'] = "archive"
return kwargs
class ProductListView(CanEditPropMixin, ListView):
"""
A list view for the admins
"""
model = Product
template_name = 'counter/product_list.jinja'
queryset = Product.objects.filter(archived=False)
ordering = ['name']
def get_context_data(self, **kwargs):
kwargs = super(ProductListView, self).get_context_data(**kwargs)
kwargs['tab'] = "products"
return kwargs
class ProductEditForm(forms.ModelForm):
class Meta:
model = Product
fields = ['name', 'description', 'product_type', 'code', 'parent_product', 'buying_groups', 'purchase_price',
'selling_price', 'special_selling_price', 'icon', 'club', 'limit_age', 'tray']
'selling_price', 'special_selling_price', 'icon', 'club', 'limit_age', 'tray', 'archived']
parent_product = AutoCompleteSelectField('products', show_help_text=False, label=_("Parent product"), required=False)
buying_groups = AutoCompleteSelectMultipleField('groups', show_help_text=False, help_text="", label=_("Buying groups"), required=False)
club = AutoCompleteSelectField('clubs', show_help_text=False)