Add product management views

This commit is contained in:
Skia 2016-07-27 17:23:02 +02:00
parent 4408890ab2
commit f230fbc135
12 changed files with 98 additions and 10 deletions

View File

@ -10,14 +10,14 @@ from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
from club.models import Club, Membership from club.models import Club, Membership
from sith.settings import SITH_MAXIMUM_FREE_ROLE, SITH_MAIN_BOARD_GROUP from sith.settings import SITH_MAXIMUM_FREE_ROLE, SITH_MAIN_BOARD_GROUP
class ClubListView(CanViewMixin, ListView): class ClubListView(ListView):
""" """
List the Clubs List the Clubs
""" """
model = Club model = Club
template_name = 'club/club_list.jinja' template_name = 'club/club_list.jinja'
class ClubView(CanViewMixin, DetailView): class ClubView(DetailView):
""" """
Front page of a Club Front page of a Club
""" """

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0007_user_is_superuser'),
]
operations = [
migrations.AddField(
model_name='pagerev',
name='revision',
field=models.IntegerField(default=1, verbose_name='revision'),
preserve_default=False,
),
]

View File

@ -457,6 +457,7 @@ class PageRev(models.Model):
is the real content of the page. is the real content of the page.
The content is in PageRev.title and PageRev.content . The content is in PageRev.title and PageRev.content .
""" """
revision = models.IntegerField(_("revision"))
title = models.CharField(_("page title"), max_length=255, blank=True) title = models.CharField(_("page title"), max_length=255, blank=True)
content = models.TextField(_("page content"), blank=True) content = models.TextField(_("page content"), blank=True)
date = models.DateTimeField(_('date'), auto_now=True) date = models.DateTimeField(_('date'), auto_now=True)
@ -488,6 +489,8 @@ class PageRev(models.Model):
return object.__getattribute__(self, attr) return object.__getattribute__(self, attr)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if self.revision is None:
self.revision = self.page.revisions.all().count() + 1
super(PageRev, self).save(*args, **kwargs) super(PageRev, self).save(*args, **kwargs)
# Don't forget to unlock, otherwise, people will have to wait for the page's timeout # Don't forget to unlock, otherwise, people will have to wait for the page's timeout
self.page.unset_lock() self.page.unset_lock()

View File

@ -30,6 +30,7 @@
<a href="{{ url('core:page', page_name="Index") }}">{% trans %}Wiki{% endtrans %}</a> <a href="{{ url('core:page', page_name="Index") }}">{% trans %}Wiki{% endtrans %}</a>
<a href="{{ url('core:page_list') }}">{% trans %}Pages{% endtrans %}</a> <a href="{{ url('core:page_list') }}">{% trans %}Pages{% endtrans %}</a>
<a href="{{ url('club:club_list') }}">{% trans %}Clubs{% endtrans %}</a> <a href="{{ url('club:club_list') }}">{% trans %}Clubs{% endtrans %}</a>
<a href="{{ url('core:page', "Services") }}">{% trans %}Services{% endtrans %}</a>
</nav> </nav>
<div id="content"> <div id="content">

View File

@ -0,0 +1,3 @@
{% macro user_profile_link(user) -%}
<a href="{{ url("core:user_profile", user_id=user.id) }}">{{ user.get_display_name() }}</a>
{%- endmacro %}

View File

@ -2,7 +2,7 @@
{% block page %} {% block page %}
{% if rev %} {% if rev %}
<h4>{% trans rev_id=rev.id %}This may not be the last update, you are seeing revision {{ rev_id }}!{% endtrans %}</h4> <h4>{% trans rev_id=rev.revision %}This may not be the last update, you are seeing revision {{ rev_id }}!{% endtrans %}</h4>
<h3>{{ rev.title }}</h3> <h3>{{ rev.title }}</h3>
<div class="page_content">{{ rev.content|markdown }}</div> <div class="page_content">{{ rev.content|markdown }}</div>
{% else %} {% else %}

View File

@ -1,16 +1,20 @@
{% extends "core/page.jinja" %} {% extends "core/page.jinja" %}
{% from "core/macros.jinja" import user_profile_link %}
{% block page %} {% block page %}
<h3>{% trans %}Page history{% endtrans %}</h3> <h3>{% trans %}Page history{% endtrans %}</h3>
<p>{% trans page_name=page.name %}You're seeing the history of page "{{ page_name }}"{% endtrans %}</p> <p>{% trans page_name=page.name %}You're seeing the history of page "{{ page_name }}"{% endtrans %}</p>
<ul> <ul>
{% for r in (page.revisions.all()|sort(attribute='date', reverse=True)) %} {% for r in (page.revisions.all()|sort(attribute='date', reverse=True)) %}
{% if loop.index < 2 %} {% if loop.index < 2 %}
<li><a href="{{ url('core:page', page_name=page.get_full_name()) }}"> <li><a href="{{ url('core:page', page_name=page.get_full_name()) }}">{% trans %}last{% endtrans %}</a> -
last - {{ page.revisions.last().author }} - {{ page.revisions.last().date|date('Y-m-d H:i') }}</a></li> {{ user_profile_link(page.revisions.last().author) }} -
{{ page.revisions.last().date|localtime|date(DATETIME_FORMAT) }} {{ page.revisions.last().date|localtime|time(DATETIME_FORMAT) }}</a></li>
{% else %} {% else %}
<li><a href="{{ url('core:page_rev', page_name=page.get_full_name(), rev=r['id']) }}"> <li><a href="{{ url('core:page_rev', page_name=page.get_full_name(), rev=r['id']) }}">{{ r.revision }}</a> -
{{ r['author'] }} - {{ r['date']|date('Y-m-d H:i') }}</a></li> {{ user_profile_link(r.author) }} -
{{ page.revisions.last().date|localtime|date(DATETIME_FORMAT) }} {{ page.revisions.last().date|localtime|time(DATETIME_FORMAT) }}</a></li>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</ul> </ul>

View File

@ -23,6 +23,7 @@
<ul> <ul>
{% if user.is_in_group(settings.SITH_GROUPS['counter-admin']['name']) or user.is_in_group(settings.SITH_GROUPS['root']['name']) %} {% if user.is_in_group(settings.SITH_GROUPS['counter-admin']['name']) or user.is_in_group(settings.SITH_GROUPS['root']['name']) %}
<li><a href="{{ url('counter:admin_list') }}">{% trans %}General counters management{% endtrans %}</a></li> <li><a href="{{ url('counter:admin_list') }}">{% trans %}General counters management{% endtrans %}</a></li>
<li><a href="{{ url('counter:product_list') }}">{% trans %}General products management{% endtrans %}</a></li>
{% endif %} {% endif %}
{% for b in settings.SITH_COUNTER_BARS %} {% for b in settings.SITH_COUNTER_BARS %}
{% if user.is_in_group(b[1]+" admin") %} {% if user.is_in_group(b[1]+" admin") %}

View File

@ -75,6 +75,9 @@ class Product(models.Model):
def __str__(self): def __str__(self):
return self.name return self.name
def get_absolute_url(self):
return reverse('counter:product_list')
class Counter(models.Model): class Counter(models.Model):
name = models.CharField(_('name'), max_length=30) name = models.CharField(_('name'), max_length=30)
club = models.ForeignKey(Club, related_name="counters") club = models.ForeignKey(Club, related_name="counters")

View File

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

View File

@ -11,6 +11,9 @@ urlpatterns = [
url(r'^admin$', CounterListView.as_view(), name='admin_list'), url(r'^admin$', CounterListView.as_view(), name='admin_list'),
url(r'^admin/new$', CounterCreateView.as_view(), name='new'), 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/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/create$', ProductCreateView.as_view(), name='new_product'),
url(r'^admin/product/(?P<product_id>[0-9]+)$', ProductEditView.as_view(), name='product_edit'),
] ]

View File

@ -351,6 +351,33 @@ class CounterDeleteView(CanEditMixin, DeleteView):
template_name = 'core/delete_confirm.jinja' template_name = 'core/delete_confirm.jinja'
success_url = reverse_lazy('counter:admin_list') success_url = reverse_lazy('counter:admin_list')
# Product management
class ProductListView(ListView):
"""
A list view for the admins
"""
model = Product
template_name = 'counter/product_list.jinja'
class ProductCreateView(CreateView):
"""
A create view for the admins
"""
model = Product
template_name = 'core/edit.jinja'
class ProductEditView(UpdateView):
"""
An edit view for the admins
"""
model = Product
form_class = modelform_factory(Product, fields=['name', 'description', 'product_type', 'code', 'purchase_price',
'selling_price', 'special_selling_price', 'icon', 'club'])
pk_url_kwarg = "product_id"
template_name = 'core/edit.jinja'
# TODO: add management of the 'counters' ForeignKey
# User accounting infos # User accounting infos
class UserAccountView(DetailView): class UserAccountView(DetailView):