Refactor lots of tabed templates, and create TabedViewMixin

This commit is contained in:
Skia 2016-09-04 19:24:53 +02:00
parent 976ae09e55
commit b1f6754e6e
22 changed files with 243 additions and 253 deletions

View File

@ -1,7 +1,7 @@
{% extends "club/club_base.jinja" %}
{% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import user_profile_link %}
{% block club %}
{% block content %}
<h3>{% trans %}Club{% endtrans %}</h3>
{% endblock %}

View File

@ -1,13 +0,0 @@
{% extends "club/club_base.jinja" %}
{% block club %}
<h2>{% trans %}Edit club{% endtrans %}</h2>
<form action="{{ url('club:club_edit', club_id=club.id) }}" method="post">
{% csrf_token %}
{{ form.as_p() }}
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
</form>
{% endblock %}

View File

@ -1,13 +0,0 @@
{% extends "club/club_base.jinja" %}
{% block club %}
<h2>{% trans %}Edit club properties{% endtrans %}</h2>
<form action="" method="post">
{% csrf_token %}
{{ form.as_p() }}
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
</form>
{% endblock %}

View File

@ -1,7 +1,7 @@
{% extends "club/club_base.jinja" %}
{% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import user_profile_link %}
{% block club %}
{% block content %}
<h2>{% trans %}Club members{% endtrans %}</h2>
<table>
<thead>

View File

@ -1,7 +1,7 @@
{% extends "club/club_base.jinja" %}
{% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import user_profile_link %}
{% block club %}
{% block content %}
<h2>{% trans %}Club old members{% endtrans %}</h2>
<table>
<thead>

View File

@ -1,6 +1,6 @@
{% extends "club/club_base.jinja" %}
{% extends "core/base.jinja" %}
{% block club %}
{% block content %}
<h3>{% trans %}Club tools{% endtrans %}</h3>
<div>
{% if object.counters.filter(type="OFFICE")|count > 0 %}

View File

@ -7,11 +7,53 @@ from django.core.exceptions import ValidationError
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.utils import timezone
from django.utils.translation import ugettext as _
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin
from club.models import Club, Membership
from sith.settings import SITH_MAXIMUM_FREE_ROLE, SITH_MAIN_BOARD_GROUP
class ClubTabsMixin(TabedViewMixin):
def get_tabs_title(self):
return self.object.get_display_name()
def get_list_of_tabs(self):
tab_list = []
tab_list.append({
'url': reverse('club:club_view', kwargs={'club_id': self.object.id}),
'slug': 'infos',
'name': _("Infos"),
})
if self.request.user.can_view(self.object):
tab_list.append({
'url': reverse('club:club_members', kwargs={'club_id': self.object.id}),
'slug': 'members',
'name': _("Members"),
})
tab_list.append({
'url': reverse('club:club_old_members', kwargs={'club_id': self.object.id}),
'slug': 'elderlies',
'name': _("Old members"),
})
if self.request.user.can_edit(self.object):
tab_list.append({
'url': reverse('club:tools', kwargs={'club_id': self.object.id}),
'slug': 'tools',
'name': _("Tools"),
})
tab_list.append({
'url': reverse('club:club_edit', kwargs={'club_id': self.object.id}),
'slug': 'edit',
'name': _("Edit"),
})
if self.request.user.is_owner(self.object):
tab_list.append({
'url': reverse('club:club_prop', kwargs={'club_id': self.object.id}),
'slug': 'props',
'name': _("Props"),
})
return tab_list
class ClubListView(ListView):
"""
List the Clubs
@ -19,31 +61,23 @@ class ClubListView(ListView):
model = Club
template_name = 'club/club_list.jinja'
class ClubView(DetailView):
class ClubView(ClubTabsMixin, DetailView):
"""
Front page of a Club
"""
model = Club
pk_url_kwarg = "club_id"
template_name = 'club/club_detail.jinja'
current_tab = "infos"
def get_context_data(self, **kwargs):
kwargs = super(ClubView, self).get_context_data(**kwargs)
kwargs['tab'] = "infos"
return kwargs
class ClubToolsView(CanEditMixin, DetailView):
class ClubToolsView(ClubTabsMixin, CanEditMixin, DetailView):
"""
Tools page of a Club
"""
model = Club
pk_url_kwarg = "club_id"
template_name = 'club/club_tools.jinja'
def get_context_data(self, **kwargs):
kwargs = super(ClubToolsView, self).get_context_data(**kwargs)
kwargs['tab'] = "tools"
return kwargs
current_tab = "tools"
class ClubMemberForm(forms.ModelForm):
"""
@ -76,7 +110,7 @@ class ClubMemberForm(forms.ModelForm):
ret = super(ClubMemberForm, self).save(*args, **kwargs)
return self.instance.club
class ClubMembersView(CanViewMixin, UpdateView):
class ClubMembersView(ClubTabsMixin, CanViewMixin, UpdateView):
"""
View of a club's members
"""
@ -84,6 +118,7 @@ class ClubMembersView(CanViewMixin, UpdateView):
pk_url_kwarg = "club_id"
form_class = ClubMemberForm
template_name = 'club/club_members.jinja'
current_tab = "members"
def get_form(self):
"""
@ -99,51 +134,34 @@ class ClubMembersView(CanViewMixin, UpdateView):
form._user = self.request.user
return form
def get_context_data(self, **kwargs):
kwargs = super(ClubMembersView, self).get_context_data(**kwargs)
kwargs['tab'] = "members"
return kwargs
class ClubOldMembersView(CanViewMixin, DetailView):
class ClubOldMembersView(ClubTabsMixin, CanViewMixin, DetailView):
"""
Old members of a club
"""
model = Club
pk_url_kwarg = "club_id"
template_name = 'club/club_old_members.jinja'
current_tab = "elderlies"
def get_context_data(self, **kwargs):
kwargs = super(ClubOldMembersView, self).get_context_data(**kwargs)
kwargs['tab'] = "elderlies"
return kwargs
class ClubEditView(CanEditMixin, UpdateView):
class ClubEditView(ClubTabsMixin, CanEditMixin, UpdateView):
"""
Edit a Club's main informations (for the club's members)
"""
model = Club
pk_url_kwarg = "club_id"
fields = ['address']
template_name = 'club/club_edit.jinja'
template_name = 'core/edit.jinja'
current_tab = "edit"
def get_context_data(self, **kwargs):
kwargs = super(ClubEditView, self).get_context_data(**kwargs)
kwargs['tab'] = "edit"
return kwargs
class ClubEditPropView(CanEditPropMixin, UpdateView):
class ClubEditPropView(ClubTabsMixin, CanEditPropMixin, UpdateView):
"""
Edit the properties of a Club object (for the Sith admins)
"""
model = Club
pk_url_kwarg = "club_id"
fields = ['name', 'unix_name', 'parent']
template_name = 'club/club_edit_prop.jinja'
def get_context_data(self, **kwargs):
kwargs = super(ClubEditPropView, self).get_context_data(**kwargs)
kwargs['tab'] = "props"
return kwargs
template_name = 'core/edit.jinja'
current_tab = "props"
class ClubCreateView(CanEditPropMixin, CreateView):
"""
@ -152,7 +170,7 @@ class ClubCreateView(CanEditPropMixin, CreateView):
model = Club
pk_url_kwarg = "club_id"
fields = ['name', 'unix_name', 'parent']
template_name = 'club/club_edit_prop.jinja'
template_name = 'core/edit.jinja'
class MembershipSetOldView(CanEditMixin, DetailView):
"""

View File

@ -74,6 +74,22 @@
{% endblock %}
<div id="content">
{% if list_of_tabs %}
<div class="tool-bar">
<div>{{ tabs_title }}</div>
<div class="tools">
{% for t in list_of_tabs %}
<a href="{{ t.url }}"
{%- if current_tab == t.slug -%}
class="selected_tab"
{%- endif -%}
>{{ t.name }}</a>
{% endfor %}
</div>
<hr>
</div>
{% endif %}
{% if error %}
{{ error }}
{% endif %}

View File

@ -1,10 +1,10 @@
{% extends "core/user_base.jinja" %}
{% extends "core/base.jinja" %}
{% block title %}
{% trans user_name=profile.get_display_name() %}{{ user_name }}'s account{% endtrans %}
{% endblock %}
{% block infos %}
{% block content %}
{% if customer %}
<h3>{% trans %}User account{% endtrans %}</h3>
<p>{% trans %}Amount: {% endtrans %}{{ customer.amount }} €</p>

View File

@ -1,65 +0,0 @@
{% extends "core/base.jinja" %}
{% block content %}
<div class="tool-bar">
<div>{{ profile.get_display_name() }}</div>
<div class="tools">
<a href="{{ url('core:user_profile', user_id=profile.id) }}"
{%- if tab == "infos" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Infos{% endtrans %}</a>
{% if profile == user %}
<a href="{{ url('core:user_tools') }}"
{%- if tab == "tools" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Tools{% endtrans %}</a>
{% endif %}
<a href="{{ url('core:user_stats', user_id=profile.id) }}"
{%- if tab == "stats" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Stats{% endtrans %}</a>
{% if can_edit(profile, request.user) or user.id == profile.id %}
<a href="{{ url('core:user_edit', user_id=profile.id) }}"
{%- if tab == "edit" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Edit{% endtrans %}</a>
{% endif %}
{% if can_edit_prop(profile, request.user) %}
<a href="{{ url('core:user_groups', user_id=profile.id) }}"
{%- if tab == "groups" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Groups{% endtrans %}</a>
{% endif %}
{% if profile.customer and (profile == request.user
or request.user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name'])
or request.user.is_root) %}
<a href="{{ url('core:user_account', user_id=profile.id) }}"
{%- if tab == "account" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Account{% endtrans %} ({{ profile.customer.amount }}€)</a>
{% endif %}
</div>
<hr>
</div>
<div>
{% block infos %}
{% endblock %}
</div>
{% endblock %}

View File

@ -1,10 +1,10 @@
{% extends "core/user_base.jinja" %}
{% extends "core/base.jinja" %}
{% block title %}
{% trans user_name=profile.get_display_name() %}{{ user_name }}'s profile{% endtrans %}
{% endblock %}
{% block infos %}
{% block content %}
<div id="user_profile_container">
<div id="user_profile">

View File

@ -1,10 +1,10 @@
{% extends "core/user_base.jinja" %}
{% extends "core/base.jinja" %}
{% block title %}
{% trans %}Edit user{% endtrans %}
{% endblock %}
{% block infos %}
{% block content %}
<h2>{% trans %}Edit user profile{% endtrans %}</h2>
<form action="" method="post" enctype="multipart/form-data" id="user_edit">
{% csrf_token %}

View File

@ -1,6 +1,6 @@
{% extends "core/user_base.jinja" %}
{% extends "core/base.jinja" %}
{% block infos %}
{% block content %}
<h2>{% trans user_name=profile.get_full_name() %}Edit user groups for {{ user_name }}{% endtrans %}</h2>
<form action="" method="post">
{% csrf_token %}

View File

@ -1,10 +1,10 @@
{% extends "core/user_base.jinja" %}
{% extends "core/base.jinja" %}
{% block title %}
{% trans user_name=profile.get_display_name() %}{{ user_name }}'s stats{% endtrans %}
{% endblock %}
{% block infos %}
{% block content %}
{% if profile.permanencies %}
<div>
<h3>{% trans %}Permanencies{% endtrans %}</h3>

View File

@ -1,10 +1,10 @@
{% extends "core/user_base.jinja" %}
{% extends "core/base.jinja" %}
{% block title %}
{% trans user_name=user.get_display_name() %}{{ user_name }}'s tools{% endtrans %}
{% endblock %}
{% block infos %}
{% block content %}
<h3>{% trans %}User Tools{% endtrans %}</h3>
<hr>

View File

@ -1,7 +1,7 @@
from django.shortcuts import render
from django.http import HttpResponseForbidden, HttpResponseNotFound
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist, ImproperlyConfigured
from django.views.generic.base import View
from core.models import Group
@ -110,8 +110,39 @@ class CanViewMixin(View):
context['object_list'] = l
return context
class TabedViewMixin(View):
"""
This view provide the basic functions for displaying tabs in the template
"""
def get_tabs_title(self):
try:
return self.tabs_title
except:
raise ImproperlyConfigured("tabs_title is required")
def get_current_tab(self):
try:
return self.current_tab
except:
raise ImproperlyConfigured("current_tab is required")
def get_list_of_tabs(self):
try:
return self.list_of_tabs
except:
raise ImproperlyConfigured("list_of_tabs is required")
def get_context_data(self, **kwargs):
kwargs = super(TabedViewMixin, self).get_context_data(**kwargs)
kwargs['tabs_title'] = self.get_tabs_title()
kwargs['current_tab'] = self.get_current_tab()
kwargs['list_of_tabs'] = self.get_list_of_tabs()
return kwargs
from .user import *
from .page import *
from .files import *
from .site import *
from .group import *

View File

@ -15,7 +15,7 @@ from django.conf import settings
from datetime import timedelta
import logging
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin
from core.views.forms import RegisteringForm, UserPropForm, UserProfileForm, LoginForm
from core.models import User, SithFile
@ -96,7 +96,6 @@ def password_reset_complete(request):
template_name="core/password_reset_complete.jinja",
)
def register(request):
context = {}
if request.method == 'POST':
@ -115,7 +114,53 @@ def register(request):
context['form'] = form.as_p()
return render(request, "core/register.jinja", context)
class UserView(CanViewMixin, DetailView):
class UserTabsMixin(TabedViewMixin):
def get_tabs_title(self):
return self.object.get_display_name()
def get_list_of_tabs(self):
tab_list = []
tab_list.append({
'url': reverse('core:user_profile', kwargs={'user_id': self.object.id}),
'slug': 'infos',
'name': _("Infos"),
})
if self.request.user == self.object:
tab_list.append({
'url': reverse('core:user_tools'),
'slug': 'tools',
'name': _("Tools"),
})
tab_list.append({
'url': reverse('core:user_stats', kwargs={'user_id': self.object.id}),
'slug': 'stats',
'name': _("Stats"),
})
if self.request.user.can_edit(self.object):
tab_list.append({
'url': reverse('core:user_edit', kwargs={'user_id': self.object.id}),
'slug': 'edit',
'name': _("Edit"),
})
if self.request.user.is_owner(self.object):
tab_list.append({
'url': reverse('core:user_groups', kwargs={'user_id': self.object.id}),
'slug': 'groups',
'name': _("Groups"),
})
try:
if (self.object.customer and (self.object == self.request.user
or self.request.user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name'])
or self.request.user.is_root)):
tab_list.append({
'url': reverse('core:user_account', kwargs={'user_id': self.object.id}),
'slug': 'account',
'name': _("Account")+" (%s €)" % self.object.customer.amount,
})
except: pass
return tab_list
class UserView(UserTabsMixin, CanViewMixin, DetailView):
"""
Display a user's profile
"""
@ -123,13 +168,9 @@ class UserView(CanViewMixin, DetailView):
pk_url_kwarg = "user_id"
context_object_name = "profile"
template_name = "core/user_detail.jinja"
current_tab = 'infos'
def get_context_data(self, **kwargs):
kwargs = super(UserView, self).get_context_data(**kwargs)
kwargs['tab'] = "infos"
return kwargs
class UserStatsView(CanViewMixin, DetailView):
class UserStatsView(UserTabsMixin, CanViewMixin, DetailView):
"""
Display a user's stats
"""
@ -137,6 +178,7 @@ class UserStatsView(CanViewMixin, DetailView):
pk_url_kwarg = "user_id"
context_object_name = "profile"
template_name = "core/user_stats.jinja"
current_tab = 'stats'
def get_context_data(self, **kwargs):
kwargs = super(UserStatsView, self).get_context_data(**kwargs)
@ -148,7 +190,6 @@ class UserStatsView(CanViewMixin, DetailView):
kwargs['total_foyer_time'] = sum([p.end-p.start for p in self.object.permanencies.filter(counter=foyer)], timedelta())
kwargs['total_mde_time'] = sum([p.end-p.start for p in self.object.permanencies.filter(counter=mde)], timedelta())
kwargs['total_gommette_time'] = sum([p.end-p.start for p in self.object.permanencies.filter(counter=gommette)], timedelta())
kwargs['tab'] = "stats"
return kwargs
class UserMiniView(CanViewMixin, DetailView):
@ -196,7 +237,7 @@ class UserUploadProfilePictView(CanEditMixin, DetailView):
self.object.save()
return redirect("core:user_edit", user_id=self.object.id)
class UserUpdateProfileView(CanEditMixin, UpdateView):
class UserUpdateProfileView(UserTabsMixin, CanEditMixin, UpdateView):
"""
Edit a user's profile
"""
@ -204,6 +245,7 @@ class UserUpdateProfileView(CanEditMixin, UpdateView):
pk_url_kwarg = "user_id"
template_name = "core/user_edit.jinja"
form_class = UserProfileForm
current_tab = "edit"
def get(self, request, *args, **kwargs):
self.object = self.get_object()
@ -227,10 +269,9 @@ class UserUpdateProfileView(CanEditMixin, UpdateView):
kwargs = super(UserUpdateProfileView, self).get_context_data(**kwargs)
kwargs['profile'] = self.form.instance
kwargs['form'] = self.form
kwargs['tab'] = "edit"
return kwargs
class UserUpdateGroupView(CanEditPropMixin, UpdateView):
class UserUpdateGroupView(UserTabsMixin, CanEditPropMixin, UpdateView):
"""
Edit a user's groups
"""
@ -240,33 +281,32 @@ class UserUpdateGroupView(CanEditPropMixin, UpdateView):
form_class = modelform_factory(User, fields=['groups'],
widgets={'groups':CheckboxSelectMultiple})
context_object_name = "profile"
current_tab = "groups"
def get_context_data(self, **kwargs):
kwargs = super(UserUpdateGroupView, self).get_context_data(**kwargs)
kwargs['tab'] = "groups"
return kwargs
class UserToolsView(TemplateView):
class UserToolsView(UserTabsMixin, TemplateView):
"""
Displays the logged user's tools
"""
template_name = "core/user_tools.jinja"
current_tab = "tools"
def get_context_data(self, **kwargs):
self.object = self.request.user
from launderette.models import Launderette
kwargs = super(UserToolsView, self).get_context_data(**kwargs)
kwargs['launderettes'] = Launderette.objects.all()
kwargs['profile'] = self.request.user
kwargs['tab'] = "tools"
kwargs['object'] = self.request.user
return kwargs
class UserAccountView(DetailView):
class UserAccountView(UserTabsMixin, DetailView):
"""
Display a user's account
"""
model = User
pk_url_kwarg = "user_id"
template_name = "core/user_account.jinja"
current_tab = "account"
def dispatch(self, request, *arg, **kwargs): # Manually validates the rights
res = super(UserAccountView, self).dispatch(request, *arg, **kwargs)
@ -284,7 +324,6 @@ class UserAccountView(DetailView):
except:
pass
# TODO: add list of month where account has activity
kwargs['tab'] = "account"
return kwargs

View File

@ -1,40 +0,0 @@
{% extends "core/base.jinja" %}
{% block content %}
<div class="tool-bar">
<div>{% trans %}Counter administration{% endtrans %}</div>
<div class="tools">
<a href="{{ url('counter:admin_list') }}"
{%- if tab == "counters" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Counters{% endtrans %}</a>
<a href="{{ url('counter:product_list') }}"
{%- if tab == "products" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Products{% endtrans %}</a>
<a href="{{ url('counter:product_list_archived') }}"
{%- if tab == "archive" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Archived products{% endtrans %}</a>
<a href="{{ url('counter:producttype_list') }}"
{%- if tab == "product_types" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Product types{% endtrans %}</a>
</div>
<hr>
</div>
<div>
{% block admin_content %}
{% endblock %}
</div>
{% endblock %}

View File

@ -1,10 +1,10 @@
{% extends "counter/counter_base.jinja" %}
{% extends "core/base.jinja" %}
{% block title %}
{% trans %}Counter admin list{% endtrans %}
{% endblock %}
{% block admin_content %}
{% block content %}
<p><a href="{{ url('counter:new') }}">{% trans %}New counter{% endtrans %}</a></p>
{% if counter_list %}
<h3>{% trans %}Counter admin list{% endtrans %}</h3>

View File

@ -1,10 +1,10 @@
{% extends "counter/counter_base.jinja" %}
{% extends "core/base.jinja" %}
{% block title %}
{% trans %}Product list{% endtrans %}
{% endblock %}
{% block admin_content %}
{% block content %}
{% if tab == "products" %}
<p><a href="{{ url('counter:new_product') }}">{% trans %}New product{% endtrans %}</a></p>
{% endif %}

View File

@ -1,10 +1,10 @@
{% extends "counter/counter_base.jinja" %}
{% extends "core/base.jinja" %}
{% block title %}
{% trans %}Product type list{% endtrans %}
{% endblock %}
{% block admin_content %}
{% block content %}
<p><a href="{{ url('counter:new_producttype') }}">{% trans %}New product type{% endtrans %}</a></p>
{% if producttype_list %}
<h3>{% trans %}Product type list{% endtrans %}</h3>

View File

@ -16,7 +16,7 @@ from datetime import date, timedelta
from ajax_select.fields import AutoCompleteSelectField, AutoCompleteSelectMultipleField
from ajax_select import make_ajax_form, make_ajax_field
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin
from core.views.forms import SelectUser, LoginForm
from core.models import User
from subscription.models import Subscriber
@ -383,17 +383,38 @@ class CounterLogout(RedirectView):
## Counter admin views
class CounterListView(CanViewMixin, ListView):
class CounterTabsMixin(TabedViewMixin):
tabs_title = _("Counter administration")
list_of_tabs = [
{
'url': reverse_lazy('counter:admin_list'),
'slug': 'counters',
'name': _("Counters"),
},
{
'url': reverse_lazy('counter:product_list'),
'slug': 'products',
'name': _("Products"),
},
{
'url': reverse_lazy('counter:product_list_archived'),
'slug': 'archive',
'name': _("Archived products"),
},
{
'url': reverse_lazy('counter:producttype_list'),
'slug': 'product_types',
'name': _("Product types"),
},
]
class CounterListView(CounterTabsMixin, CanViewMixin, ListView):
"""
A list view for the admins
"""
model = Counter
template_name = 'counter/counter_list.jinja'
def get_context_data(self, **kwargs):
kwargs = super(CounterListView, self).get_context_data(**kwargs)
kwargs['tab'] = "counters"
return kwargs
current_tab = "counters"
class CounterEditForm(forms.ModelForm):
class Meta:
@ -402,7 +423,7 @@ class CounterEditForm(forms.ModelForm):
sellers = make_ajax_field(Counter, 'sellers', 'users', help_text="")
products = make_ajax_field(Counter, 'products', 'products', help_text="")
class CounterEditView(CanEditMixin, UpdateView):
class CounterEditView(CounterTabsMixin, CanEditMixin, UpdateView):
"""
Edit a counter's main informations (for the counter's manager)
"""
@ -410,11 +431,12 @@ class CounterEditView(CanEditMixin, UpdateView):
form_class = CounterEditForm
pk_url_kwarg = "counter_id"
template_name = 'core/edit.jinja'
current_tab = "counters"
def get_success_url(self):
return reverse_lazy('counter:admin', kwargs={'counter_id': self.object.id})
class CounterEditPropView(CanEditPropMixin, UpdateView):
class CounterEditPropView(CounterTabsMixin, CanEditPropMixin, UpdateView):
"""
Edit a counter's main informations (for the counter's admin)
"""
@ -422,8 +444,9 @@ class CounterEditPropView(CanEditPropMixin, UpdateView):
form_class = modelform_factory(Counter, fields=['name', 'club', 'type'])
pk_url_kwarg = "counter_id"
template_name = 'core/edit.jinja'
current_tab = "counters"
class CounterCreateView(CanEditMixin, CreateView):
class CounterCreateView(CounterTabsMixin, CanEditMixin, CreateView):
"""
Create a counter (for the admins)
"""
@ -431,8 +454,9 @@ class CounterCreateView(CanEditMixin, CreateView):
form_class = modelform_factory(Counter, fields=['name', 'club', 'type', 'products'],
widgets={'products':CheckboxSelectMultiple})
template_name = 'core/create.jinja'
current_tab = "counters"
class CounterDeleteView(CanEditMixin, DeleteView):
class CounterDeleteView(CounterTabsMixin, CanEditMixin, DeleteView):
"""
Delete a counter (for the admins)
"""
@ -440,30 +464,28 @@ class CounterDeleteView(CanEditMixin, DeleteView):
pk_url_kwarg = "counter_id"
template_name = 'core/delete_confirm.jinja'
success_url = reverse_lazy('counter:admin_list')
current_tab = "counters"
# Product management
class ProductTypeListView(CanEditPropMixin, ListView):
class ProductTypeListView(CounterTabsMixin, CanEditPropMixin, ListView):
"""
A list view for the admins
"""
model = ProductType
template_name = 'counter/producttype_list.jinja'
current_tab = "product_types"
def get_context_data(self, **kwargs):
kwargs = super(ProductTypeListView, self).get_context_data(**kwargs)
kwargs['tab'] = "product_types"
return kwargs
class ProductTypeCreateView(CanCreateMixin, CreateView):
class ProductTypeCreateView(CounterTabsMixin, CanCreateMixin, CreateView):
"""
A create view for the admins
"""
model = ProductType
fields = ['name', 'description', 'icon']
template_name = 'core/create.jinja'
current_tab = "products"
class ProductTypeEditView(CanEditPropMixin, UpdateView):
class ProductTypeEditView(CounterTabsMixin, CanEditPropMixin, UpdateView):
"""
An edit view for the admins
"""
@ -471,8 +493,9 @@ class ProductTypeEditView(CanEditPropMixin, UpdateView):
template_name = 'core/edit.jinja'
fields = ['name', 'description', 'icon']
pk_url_kwarg = "type_id"
current_tab = "products"
class ProductArchivedListView(CanEditPropMixin, ListView):
class ProductArchivedListView(CounterTabsMixin, CanEditPropMixin, ListView):
"""
A list view for the admins
"""
@ -480,13 +503,9 @@ class ProductArchivedListView(CanEditPropMixin, ListView):
template_name = 'counter/product_list.jinja'
queryset = Product.objects.filter(archived=True)
ordering = ['name']
current_tab = "archive"
def get_context_data(self, **kwargs):
kwargs = super(ProductArchivedListView, self).get_context_data(**kwargs)
kwargs['tab'] = "archive"
return kwargs
class ProductListView(CanEditPropMixin, ListView):
class ProductListView(CounterTabsMixin, CanEditPropMixin, ListView):
"""
A list view for the admins
"""
@ -494,11 +513,7 @@ class ProductListView(CanEditPropMixin, ListView):
template_name = 'counter/product_list.jinja'
queryset = Product.objects.filter(archived=False)
ordering = ['name']
def get_context_data(self, **kwargs):
kwargs = super(ProductListView, self).get_context_data(**kwargs)
kwargs['tab'] = "products"
return kwargs
current_tab = "products"
class ProductEditForm(forms.ModelForm):
class Meta:
@ -528,15 +543,16 @@ class ProductEditForm(forms.ModelForm):
c.save()
return ret
class ProductCreateView(CanCreateMixin, CreateView):
class ProductCreateView(CounterTabsMixin, CanCreateMixin, CreateView):
"""
A create view for the admins
"""
model = Product
form_class = ProductEditForm
template_name = 'core/create.jinja'
current_tab = "products"
class ProductEditView(CanEditPropMixin, UpdateView):
class ProductEditView(CounterTabsMixin, CanEditPropMixin, UpdateView):
"""
An edit view for the admins
"""
@ -544,6 +560,7 @@ class ProductEditView(CanEditPropMixin, UpdateView):
form_class = ProductEditForm
pk_url_kwarg = "product_id"
template_name = 'core/edit.jinja'
current_tab = "products"
class RefillingDeleteView(CanEditPropMixin, DeleteView):
"""