mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-21 21:53:30 +00:00
Add product management views
This commit is contained in:
parent
4408890ab2
commit
f230fbc135
@ -10,14 +10,14 @@ from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
|
||||
from club.models import Club, Membership
|
||||
from sith.settings import SITH_MAXIMUM_FREE_ROLE, SITH_MAIN_BOARD_GROUP
|
||||
|
||||
class ClubListView(CanViewMixin, ListView):
|
||||
class ClubListView(ListView):
|
||||
"""
|
||||
List the Clubs
|
||||
"""
|
||||
model = Club
|
||||
template_name = 'club/club_list.jinja'
|
||||
|
||||
class ClubView(CanViewMixin, DetailView):
|
||||
class ClubView(DetailView):
|
||||
"""
|
||||
Front page of a Club
|
||||
"""
|
||||
|
20
core/migrations/0008_pagerev_revision.py
Normal file
20
core/migrations/0008_pagerev_revision.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 = [
|
||||
('core', '0007_user_is_superuser'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='pagerev',
|
||||
name='revision',
|
||||
field=models.IntegerField(default=1, verbose_name='revision'),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
@ -457,6 +457,7 @@ class PageRev(models.Model):
|
||||
is the real content of the page.
|
||||
The content is in PageRev.title and PageRev.content .
|
||||
"""
|
||||
revision = models.IntegerField(_("revision"))
|
||||
title = models.CharField(_("page title"), max_length=255, blank=True)
|
||||
content = models.TextField(_("page content"), blank=True)
|
||||
date = models.DateTimeField(_('date'), auto_now=True)
|
||||
@ -488,6 +489,8 @@ class PageRev(models.Model):
|
||||
return object.__getattribute__(self, attr)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.revision is None:
|
||||
self.revision = self.page.revisions.all().count() + 1
|
||||
super(PageRev, self).save(*args, **kwargs)
|
||||
# Don't forget to unlock, otherwise, people will have to wait for the page's timeout
|
||||
self.page.unset_lock()
|
||||
|
@ -30,6 +30,7 @@
|
||||
<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('club:club_list') }}">{% trans %}Clubs{% endtrans %}</a>
|
||||
<a href="{{ url('core:page', "Services") }}">{% trans %}Services{% endtrans %}</a>
|
||||
</nav>
|
||||
|
||||
<div id="content">
|
||||
|
3
core/templates/core/macros.jinja
Normal file
3
core/templates/core/macros.jinja
Normal 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 %}
|
@ -2,7 +2,7 @@
|
||||
|
||||
{% block page %}
|
||||
{% 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>
|
||||
<div class="page_content">{{ rev.content|markdown }}</div>
|
||||
{% else %}
|
||||
|
@ -1,18 +1,22 @@
|
||||
{% extends "core/page.jinja" %}
|
||||
|
||||
{% from "core/macros.jinja" import user_profile_link %}
|
||||
|
||||
{% 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>
|
||||
<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 %}
|
||||
<li><a href="{{ url('core:page', page_name=page.get_full_name()) }}">
|
||||
last - {{ page.revisions.last().author }} - {{ page.revisions.last().date|date('Y-m-d H:i') }}</a></li>
|
||||
<li><a href="{{ url('core:page', page_name=page.get_full_name()) }}">{% trans %}last{% endtrans %}</a> -
|
||||
{{ 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 %}
|
||||
<li><a href="{{ url('core:page_rev', page_name=page.get_full_name(), rev=r['id']) }}">
|
||||
{{ r['author'] }} - {{ r['date']|date('Y-m-d H:i') }}</a></li>
|
||||
<li><a href="{{ url('core:page_rev', page_name=page.get_full_name(), rev=r['id']) }}">{{ r.revision }}</a> -
|
||||
{{ user_profile_link(r.author) }} -
|
||||
{{ page.revisions.last().date|localtime|date(DATETIME_FORMAT) }} {{ page.revisions.last().date|localtime|time(DATETIME_FORMAT) }}</a></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
<ul>
|
||||
{% 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:product_list') }}">{% trans %}General products management{% endtrans %}</a></li>
|
||||
{% endif %}
|
||||
{% for b in settings.SITH_COUNTER_BARS %}
|
||||
{% if user.is_in_group(b[1]+" admin") %}
|
||||
|
@ -75,6 +75,9 @@ class Product(models.Model):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('counter:product_list')
|
||||
|
||||
class Counter(models.Model):
|
||||
name = models.CharField(_('name'), max_length=30)
|
||||
club = models.ForeignKey(Club, related_name="counters")
|
||||
|
23
counter/templates/counter/product_list.jinja
Normal file
23
counter/templates/counter/product_list.jinja
Normal 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 %}
|
||||
|
||||
|
||||
|
||||
|
@ -11,6 +11,9 @@ urlpatterns = [
|
||||
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'),
|
||||
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'),
|
||||
]
|
||||
|
||||
|
||||
|
@ -351,6 +351,33 @@ class CounterDeleteView(CanEditMixin, DeleteView):
|
||||
template_name = 'core/delete_confirm.jinja'
|
||||
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
|
||||
|
||||
class UserAccountView(DetailView):
|
||||
|
Loading…
Reference in New Issue
Block a user