views.py 1.69 KB
Newer Older
Skia's avatar
Skia committed
1
2
from django.shortcuts import render
from django.views.generic import ListView, DetailView
Skia's avatar
Skia committed
3
4
5
6
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
Skia's avatar
Skia committed
7
8
9
10
11
12
13
14
15
16
17
18
19

from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
from counter.models import Counter
# Create your views here.

class CounterListView(CanViewMixin, ListView):
    model = Counter
    template_name = 'counter/counter_list.jinja'

class CounterDetail(CanViewMixin, DetailView):
    model = Counter
    template_name = 'counter/counter_detail.jinja'
    pk_url_kwarg = "counter_id"
Skia's avatar
Skia committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

class CounterEditView(CanEditMixin, UpdateView):
    """
    Edit a Counter's main informations (for the counter's members)
    """
    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):
    """
    Edit a Counter's main informations (for the counter's members)
    """
    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):
    """
    Edit a Counter's main informations (for the counter's members)
    """
    model = Counter
    pk_url_kwarg = "counter_id"
    template_name = 'core/delete_confirm.jinja'
    success_url = reverse_lazy('counter:admin_list')