mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 15:51:19 +00:00
Creation of the Stock list, edit, create views and creation StockItem create view
This commit is contained in:
parent
ccb339b9bd
commit
887893fb2d
@ -31,14 +31,14 @@
|
||||
{% if user.can_edit(c) %}
|
||||
<a href="{{ url('counter:admin', counter_id=c.id) }}">{% trans %}Edit{% endtrans %}</a> -
|
||||
<a href="{{ url('counter:stats', counter_id=c.id) }}">{% trans %}Stats{% endtrans %}</a> -
|
||||
{%if c.stock %}
|
||||
<a href="{{ url('stock:main', stock_id=c.stock.id) }}">Stock</a> -
|
||||
{% else %}
|
||||
<a href="{{ url('stock:new', counter_id=c.id) }}">{% trans %}Create new stock{% endtrans%}</a> -
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if user.is_owner(c) %}
|
||||
<a href="{{ url('counter:prop_admin', counter_id=c.id) }}">{% trans %}Props{% endtrans %}</a> -
|
||||
{%if c.stock %}
|
||||
<a href="{{ url('stock:main', stock_id=c.stock.id) }}">{{c.stock}}</a>
|
||||
{% else %}
|
||||
<a href="{{ url('stock:new', counter_id=c.id) }}">{% trans %}Create new stock{% endtrans%}</a>
|
||||
{% endif %}
|
||||
<a href="{{ url('counter:prop_admin', counter_id=c.id) }}">{% trans %}Props{% endtrans %}</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
@ -443,6 +443,11 @@ class CounterLogout(RedirectView):
|
||||
class CounterAdminTabsMixin(TabedViewMixin):
|
||||
tabs_title = _("Counter administration")
|
||||
list_of_tabs = [
|
||||
{
|
||||
'url': reverse_lazy('stock:list'),
|
||||
'slug': 'stocks',
|
||||
'name': _("Stocks"),
|
||||
},
|
||||
{
|
||||
'url': reverse_lazy('counter:admin_list'),
|
||||
'slug': 'counters',
|
||||
|
Binary file not shown.
2862
locale/fr/LC_MESSAGES/django.po
Normal file
2862
locale/fr/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,7 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
|
||||
from counter.models import Counter
|
||||
|
||||
@ -11,6 +13,9 @@ class Stock(models.Model):
|
||||
def __str__(self):
|
||||
return "%s (%s)" % (self.name, self.counter)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('stock:list')
|
||||
|
||||
class StockItem(models.Model):
|
||||
""" The StockItem class, element of the stock """
|
||||
name = models.CharField(_('name'), max_length=64)
|
||||
|
23
stock/templates/stock/stock_list.jinja
Normal file
23
stock/templates/stock/stock_list.jinja
Normal file
@ -0,0 +1,23 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Stock list{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if stock_list %}
|
||||
<h3>{% trans %}Stock list{% endtrans %}</h3>
|
||||
<ul>
|
||||
{% for s in stock_list.order_by('name') %}
|
||||
<li>
|
||||
{% if user.can_edit(s) %}
|
||||
<a href="{{ url('stock:main', stock_id=s.id) }}">{{s}}</a>
|
||||
- <a href="{{ url('stock:edit', stock_id=s.id) }}">Edit</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{% trans %}There is no stocks in this website.{% endtrans %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
@ -6,6 +6,6 @@
|
||||
|
||||
{% block content %}
|
||||
<h3>{{stock}}</h3>
|
||||
<a href="{{ url('stock:new_item', stock_id=stock.id) }}">{{stock.name}}</a>
|
||||
<a href="{{ url('stock:new_item', stock_id=stock.id) }}">{% trans %}New Item{% endtrans %}</a>
|
||||
{% endblock %}
|
||||
|
||||
|
@ -5,5 +5,7 @@ from stock.views import *
|
||||
urlpatterns = [
|
||||
url(r'^(?P<stock_id>[0-9]+)$', StockMain.as_view(), name='main'),
|
||||
url(r'^new/counter/(?P<counter_id>[0-9]+)$', StockCreateView.as_view(), name='new'),
|
||||
url(r'^edit/(?P<stock_id>[0-9]+)$', StockEditView.as_view(), name='edit'),
|
||||
url(r'^list$', StockListView.as_view(), name='list'),
|
||||
url(r'^(?P<stock_id>[0-9]+)/newItem$', StockItemCreateView.as_view(), name='new_item'),
|
||||
]
|
||||
|
@ -1,24 +1,85 @@
|
||||
from django.shortcuts import render
|
||||
from django.views.generic import ListView, DetailView, RedirectView, TemplateView
|
||||
from django.views.generic.edit import UpdateView, CreateView, DeleteView, ProcessFormView, FormMixin
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django import forms
|
||||
from django.forms.models import modelform_factory
|
||||
from django.core.urlresolvers import reverse_lazy, reverse
|
||||
|
||||
|
||||
from stock.models import Stock
|
||||
|
||||
class StockMain(DetailView):
|
||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin
|
||||
from counter.views import CounterAdminTabsMixin
|
||||
from counter.models import Counter
|
||||
from stock.models import Stock, StockItem
|
||||
|
||||
|
||||
|
||||
class StockMain(CounterAdminTabsMixin, CanCreateMixin, DetailView):
|
||||
"""
|
||||
The stock view for the counter owner
|
||||
The stock view for the counter owner
|
||||
"""
|
||||
model = Stock
|
||||
template_name = 'stock/stock_main.jinja'
|
||||
pk_url_kwarg = "stock_id"
|
||||
current_tab = "stocks"
|
||||
|
||||
class StockCreateView(CreateView):
|
||||
class StockListView(CounterAdminTabsMixin, CanViewMixin, ListView):
|
||||
"""
|
||||
docstring for StockCreateView
|
||||
A list view for the admins
|
||||
"""
|
||||
model = Stock
|
||||
template_name = 'stock/stock_list.jinja'
|
||||
current_tab = "stocks"
|
||||
|
||||
class StockItemCreateView(CreateView):
|
||||
|
||||
class StockEditForm(forms.ModelForm):
|
||||
"""
|
||||
docstring for StockEditForm"forms.ModelForm
|
||||
"""
|
||||
class Meta:
|
||||
model = Stock
|
||||
fields = ['name']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(StockEditForm, self).__init__(*args, **kwargs)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
return super(StockEditForm, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class StockEditView(CounterAdminTabsMixin, CanEditPropMixin, UpdateView):
|
||||
"""
|
||||
A edit view for the stock
|
||||
"""
|
||||
model = Stock
|
||||
form_class = StockEditForm
|
||||
pk_url_kwarg = "stock_id"
|
||||
template_name = 'core/edit.jinja'
|
||||
current_tab = "stocks"
|
||||
|
||||
|
||||
class StockCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView):
|
||||
"""
|
||||
A create view for a new Stock
|
||||
"""
|
||||
model = Stock
|
||||
form_class = modelform_factory(Stock, fields=['name', 'counter'])
|
||||
template_name = 'core/create.jinja'
|
||||
pk_url_kwarg = "counter_id"
|
||||
current_tab = "stocks"
|
||||
success_url = reverse_lazy('stock:list')
|
||||
|
||||
|
||||
class StockItemCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView):
|
||||
"""
|
||||
A create view for a new StockItem
|
||||
"""
|
||||
model = StockItem
|
||||
form_class = modelform_factory(StockItem, fields=['name', 'unit_quantity', 'effective_quantity', 'stock_owner'])
|
||||
template_name = 'core/create.jinja'
|
||||
pk_url_kwarg = "stock_id"
|
||||
current_tab = "stocks"
|
||||
|
||||
"""
|
||||
def get_success_url(self):
|
||||
return reverse_lazy('stock:main', kwargs={'stock_id': self.object.stock_owner.id})
|
||||
|
Loading…
Reference in New Issue
Block a user