Shopping list structure view addition

This commit is contained in:
guillaume-renaud 2016-11-24 10:40:42 +01:00
parent 9d8264bcbb
commit 5b2f126eee
5 changed files with 31 additions and 13 deletions

View File

@ -7,6 +7,7 @@
{% block content %} {% block content %}
{% if current_tab == "stocks" %} {% if current_tab == "stocks" %}
<p><a href="{{ url('stock:new_item', stock_id=stock.id)}}">{% trans %}New item{% endtrans %}</a></p> <p><a href="{{ url('stock:new_item', stock_id=stock.id)}}">{% trans %}New item{% endtrans %}</a></p>
<h5><a href="{{ url('stock:shopping_list', stock_id=stock.id)}}">{% trans %}Shopping list{% endtrans %}</a></h5>
{% endif %} {% endif %}
{% if stock %} {% if stock %}
<h3>{{ stock }}</h3> <h3>{{ stock }}</h3>

View File

@ -11,7 +11,7 @@
{% for s in stock_list.order_by('name') %} {% for s in stock_list.order_by('name') %}
<li> <li>
{% if user.can_edit(s) %} {% if user.can_edit(s) %}
<a href="{{ url('stock:items_list', stock_id=s.id)}}">{{s}}</a> <a href="{{ url('stock:items_list', stock_id=s.id) }}">{{s}}</a>
- <a href="{{ url('stock:edit', stock_id=s.id) }}">Edit</a> - <a href="{{ url('stock:edit', stock_id=s.id) }}">Edit</a>
{% endif %} {% endif %}
</li> </li>

View File

@ -0,0 +1,10 @@
{% extends "core/base.jinja" %}
{% block title %}
Shopping list for {{ stock }}
{% endblock %}
{% block content %}
<h3>Shopping list for {{ stock }}</h3>
{% endblock %}

View File

@ -12,5 +12,5 @@ urlpatterns = [
url(r'^(?P<stock_id>[0-9]+)$', StockItemList.as_view(), name='items_list'), url(r'^(?P<stock_id>[0-9]+)$', StockItemList.as_view(), name='items_list'),
url(r'^(?P<stock_id>[0-9]+)/stockItem/newItem$', StockItemCreateView.as_view(), name='new_item'), url(r'^(?P<stock_id>[0-9]+)/stockItem/newItem$', StockItemCreateView.as_view(), name='new_item'),
url(r'^stockItem/(?P<item_id>[0-9]+)/edit$', StockItemEditView.as_view(), name='edit_item'), url(r'^stockItem/(?P<item_id>[0-9]+)/edit$', StockItemEditView.as_view(), name='edit_item'),
url(r'^(?P<stock_id>[0-9]+)/shopping$', StockShoppingListView.as_view(), name='shopping_list'),
] ]

View File

@ -13,7 +13,7 @@ from stock.models import Stock, StockItem
class StockMain(CounterAdminTabsMixin, CanCreateMixin, DetailView): class StockItemList(CounterAdminTabsMixin, CanCreateMixin, ListView):
""" """
The stockitems list view for the counter owner The stockitems list view for the counter owner
""" """
@ -22,12 +22,6 @@ class StockMain(CounterAdminTabsMixin, CanCreateMixin, DetailView):
pk_url_kwarg = "stock_id" pk_url_kwarg = "stock_id"
current_tab = "stocks" current_tab = "stocks"
#def get_context_data(self, **kwargs):
# context = super(StockItemList, self).get_context_data(**kwargs)
# if 'stock' in self.request.GET.keys():
# context['stock'] = Stock.objects.filter(id=self.request.GET['stock']).first()
# return context
class StockListView(CounterAdminTabsMixin, CanViewMixin, ListView): class StockListView(CounterAdminTabsMixin, CanViewMixin, ListView):
""" """
A list view for the admins A list view for the admins
@ -95,7 +89,6 @@ class StockItemCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView):
""" """
A create view for a new StockItem A create view for a new StockItem
""" """
model = StockItem model = StockItem
form_class = modelform_factory(StockItem, fields=['name', 'unit_quantity', 'effective_quantity', 'type', 'stock_owner']) form_class = modelform_factory(StockItem, fields=['name', 'unit_quantity', 'effective_quantity', 'type', 'stock_owner'])
template_name = 'core/create.jinja' template_name = 'core/create.jinja'
@ -109,6 +102,20 @@ class StockItemCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView):
return ret return ret
def get_success_url(self): def get_success_url(self):
return reverse_lazy('stock:items_list', kwargs={'stock_id':self.object.stock_owner.id}) + '?stock=' + str(self.object.stock_owner.id) return reverse_lazy('stock:items_list', kwargs={'stock_id':self.object.stock_owner.id})
class StockShoppingListView(CounterAdminTabsMixin, CanViewMixin, ListView):
"""
A list view for the people to know the item to buy
"""
model = Stock
template_name = "stock/stock_shopping_list.jinja"
pk_url_kwarg = "stock_id"
current_tab = "stocks"
def get_context_data(self):
ret = super(StockShoppingListView, self).get_context_data()
if 'stock_id' in self.kwargs.keys():
ret['stock'] = Stock.objects.filter(id=self.kwargs['stock_id']).first();
return ret