2016-03-28 12:54:35 +00:00
|
|
|
from django.shortcuts import render
|
2016-03-31 08:36:00 +00:00
|
|
|
from django.views.generic import ListView, DetailView, RedirectView
|
2016-03-29 08:30:24 +00:00
|
|
|
from django.views.generic.edit import UpdateView, CreateView, DeleteView
|
|
|
|
from django.forms.models import modelform_factory
|
|
|
|
from django.forms import CheckboxSelectMultiple
|
|
|
|
from django.core.urlresolvers import reverse_lazy
|
2016-03-31 08:36:00 +00:00
|
|
|
from django.contrib.auth.forms import AuthenticationForm
|
2016-03-28 12:54:35 +00:00
|
|
|
|
|
|
|
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
|
|
|
|
from counter.models import Counter
|
|
|
|
|
|
|
|
class CounterDetail(CanViewMixin, DetailView):
|
2016-03-31 08:36:00 +00:00
|
|
|
"""
|
|
|
|
The public (barman) view
|
|
|
|
"""
|
2016-03-28 12:54:35 +00:00
|
|
|
model = Counter
|
|
|
|
template_name = 'counter/counter_detail.jinja'
|
|
|
|
pk_url_kwarg = "counter_id"
|
2016-03-29 08:30:24 +00:00
|
|
|
|
2016-03-31 08:36:00 +00:00
|
|
|
class CounterLogin(RedirectView):
|
|
|
|
permanent = False
|
|
|
|
def post(self): # TODO: finish that
|
|
|
|
print(self.request)
|
|
|
|
form = AuthenticationForm(self.request, data=self.request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
print("Barman logged")
|
|
|
|
|
|
|
|
class CounterListView(CanViewMixin, ListView):
|
|
|
|
"""
|
|
|
|
A list view for the admins
|
|
|
|
"""
|
|
|
|
model = Counter
|
|
|
|
template_name = 'counter/counter_list.jinja'
|
|
|
|
|
2016-03-29 08:30:24 +00:00
|
|
|
class CounterEditView(CanEditMixin, UpdateView):
|
|
|
|
"""
|
2016-03-31 08:36:00 +00:00
|
|
|
Edit a counter's main informations (for the counter's admin)
|
2016-03-29 08:30:24 +00:00
|
|
|
"""
|
|
|
|
model = Counter
|
|
|
|
form_class = modelform_factory(Counter, fields=['name', 'club', 'type', 'products'],
|
|
|
|
widgets={'products':CheckboxSelectMultiple})
|
|
|
|
pk_url_kwarg = "counter_id"
|
|
|
|
template_name = 'counter/counter_edit.jinja'
|
|
|
|
|
|
|
|
class CounterCreateView(CanEditMixin, CreateView):
|
|
|
|
"""
|
2016-03-31 08:36:00 +00:00
|
|
|
Create a counter (for the admins)
|
2016-03-29 08:30:24 +00:00
|
|
|
"""
|
|
|
|
model = Counter
|
|
|
|
form_class = modelform_factory(Counter, fields=['name', 'club', 'type', 'products'],
|
|
|
|
widgets={'products':CheckboxSelectMultiple})
|
|
|
|
template_name = 'counter/counter_edit.jinja'
|
|
|
|
|
|
|
|
class CounterDeleteView(CanEditMixin, DeleteView):
|
|
|
|
"""
|
2016-03-31 08:36:00 +00:00
|
|
|
Delete a counter (for the admins)
|
2016-03-29 08:30:24 +00:00
|
|
|
"""
|
|
|
|
model = Counter
|
|
|
|
pk_url_kwarg = "counter_id"
|
|
|
|
template_name = 'core/delete_confirm.jinja'
|
|
|
|
success_url = reverse_lazy('counter:admin_list')
|
2016-03-31 08:36:00 +00:00
|
|
|
|
|
|
|
|