mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-18 04:03:22 +00:00
75af525945
addition of Stock app, model, templates, urls Addition of the stock parameter to the counter admin list Fix translation files Creation of the Stock list, edit, create views and creation StockItem create view Stock application creation Addition of the StockItem class addition of Stock app, model, templates, urls Addition of the stock parameter to the counter admin list Fix translation files Creation of the Stock list, edit, create views and creation StockItem create view Initial StockItem create form value addition general modifications Stock admin gestion, items list views, create and edit items remove stock_main.jinja Stock application creation Addition of the StockItem class addition of Stock app, model, templates, urls Addition of the stock parameter to the counter admin list Fix translation files Creation of the Stock list, edit, create views and creation StockItem create view Addition of the StockItem class addition of Stock app, model, templates, urls Addition of the stock parameter to the counter admin list Fix translation files Creation of the Stock list, edit, create views and creation StockItem create view Initial StockItem create form value addition general modifications Stock admin gestion, items list views, create and edit items Shopping list structure view addition correct missing endif a correct missing endif Stock application creation addition of Stock app, model, templates, urls Addition of the stock parameter to the counter admin list Fix translation files Creation of the Stock list, edit, create views and creation StockItem create view Stock application creation addition of Stock app, model, templates, urls Fix translation files Creation of the Stock list, edit, create views and creation StockItem create view Initial StockItem create form value addition general modifications Stock admin gestion, items list views, create and edit items remove stock_main.jinja Stock application creation addition of Stock app, model, templates, urls Addition of the stock parameter to the counter admin list Fix translation files Creation of the Stock list, edit, create views and creation StockItem create view Fix translation files Creation of the Stock list, edit, create views and creation StockItem create view Initial StockItem create form value addition general modifications Shopping list structure view addition correct missing endif
166 lines
4.7 KiB
Python
166 lines
4.7 KiB
Python
from django.shortcuts import render, get_object_or_404
|
|
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 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 StockItemList(CounterAdminTabsMixin, CanCreateMixin, ListView):
|
|
"""
|
|
The stockitems list view for the counter owner
|
|
"""
|
|
model = Stock
|
|
template_name = 'stock/stock_item_list.jinja'
|
|
pk_url_kwarg = "stock_id"
|
|
current_tab = "stocks"
|
|
|
|
class StockListView(CounterAdminTabsMixin, CanViewMixin, ListView):
|
|
"""
|
|
A list view for the admins
|
|
"""
|
|
model = Stock
|
|
template_name = 'stock/stock_list.jinja'
|
|
current_tab = "stocks"
|
|
|
|
|
|
class StockEditForm(forms.ModelForm):
|
|
"""
|
|
A form to change stock's characteristics
|
|
"""
|
|
class Meta:
|
|
model = Stock
|
|
fields = ['name', 'counter']
|
|
|
|
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):
|
|
"""
|
|
An edit view for the stock
|
|
"""
|
|
model = Stock
|
|
form_class = StockEditForm
|
|
pk_url_kwarg = "stock_id"
|
|
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):
|
|
"""
|
|
A list view for the admins
|
|
"""
|
|
model = Stock
|
|
template_name = 'stock/stock_list.jinja'
|
|
current_tab = "stocks"
|
|
|
|
|
|
class StockEditForm(forms.ModelForm):
|
|
"""
|
|
A form to change stock's characteristics
|
|
"""
|
|
class Meta:
|
|
model = Stock
|
|
fields = ['name', 'counter']
|
|
|
|
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):
|
|
"""
|
|
An edit view for the stock
|
|
"""
|
|
model = Stock
|
|
form_class = StockEditForm
|
|
pk_url_kwarg = "stock_id"
|
|
template_name = 'core/edit.jinja'
|
|
current_tab = "stocks"
|
|
|
|
|
|
class StockItemEditView(CounterAdminTabsMixin, CanEditPropMixin, UpdateView):
|
|
"""
|
|
An edit view for a stock item
|
|
"""
|
|
model = StockItem
|
|
form_class = modelform_factory(StockItem, fields=['name', 'unit_quantity', 'effective_quantity', 'type', 'stock_owner'])
|
|
pk_url_kwarg = "item_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')
|
|
|
|
def get_initial(self):
|
|
ret = super(StockCreateView, self).get_initial()
|
|
if 'counter_id' in self.kwargs.keys():
|
|
ret['counter'] = self.kwargs['counter_id']
|
|
return ret
|
|
|
|
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', 'type', 'stock_owner'])
|
|
template_name = 'core/create.jinja'
|
|
pk_url_kwarg = "stock_id"
|
|
current_tab = "stocks"
|
|
|
|
def get_initial(self):
|
|
ret = super(StockItemCreateView, self).get_initial()
|
|
if 'stock_id' in self.kwargs.keys():
|
|
ret['stock_owner'] = self.kwargs['stock_id']
|
|
return ret
|
|
|
|
def get_success_url(self):
|
|
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
|
|
|
|
class StockItemOutEditView(CounterAdminTabsMixin, CanViewMixin, UpdateView):
|
|
"""
|
|
docstring for StockItemOutList
|
|
"""
|