diff --git a/club/templates/club/club_detail.jinja b/club/templates/club/club_detail.jinja index 95100a82..daedbfcb 100644 --- a/club/templates/club/club_detail.jinja +++ b/club/templates/club/club_detail.jinja @@ -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 %}

{% trans %}Club{% endtrans %}

{% endblock %} diff --git a/club/templates/club/club_edit.jinja b/club/templates/club/club_edit.jinja deleted file mode 100644 index 3426185b..00000000 --- a/club/templates/club/club_edit.jinja +++ /dev/null @@ -1,13 +0,0 @@ -{% extends "club/club_base.jinja" %} - -{% block club %} -

{% trans %}Edit club{% endtrans %}

-
- {% csrf_token %} - {{ form.as_p() }} -

-
-{% endblock %} - - - diff --git a/club/templates/club/club_edit_prop.jinja b/club/templates/club/club_edit_prop.jinja deleted file mode 100644 index ccaefb74..00000000 --- a/club/templates/club/club_edit_prop.jinja +++ /dev/null @@ -1,13 +0,0 @@ -{% extends "club/club_base.jinja" %} - -{% block club %} -

{% trans %}Edit club properties{% endtrans %}

-
- {% csrf_token %} - {{ form.as_p() }} -

-
-{% endblock %} - - - diff --git a/club/templates/club/club_members.jinja b/club/templates/club/club_members.jinja index d60f6099..5f68a9df 100644 --- a/club/templates/club/club_members.jinja +++ b/club/templates/club/club_members.jinja @@ -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 %}

{% trans %}Club members{% endtrans %}

diff --git a/club/templates/club/club_old_members.jinja b/club/templates/club/club_old_members.jinja index 4c99697b..dd1bc3df 100644 --- a/club/templates/club/club_old_members.jinja +++ b/club/templates/club/club_old_members.jinja @@ -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 %}

{% trans %}Club old members{% endtrans %}

diff --git a/club/templates/club/club_tools.jinja b/club/templates/club/club_tools.jinja index 31af885f..ca450eb2 100644 --- a/club/templates/club/club_tools.jinja +++ b/club/templates/club/club_tools.jinja @@ -1,6 +1,6 @@ -{% extends "club/club_base.jinja" %} +{% extends "core/base.jinja" %} -{% block club %} +{% block content %}

{% trans %}Club tools{% endtrans %}

{% if object.counters.filter(type="OFFICE")|count > 0 %} diff --git a/club/views.py b/club/views.py index 82bffb56..b0136e8e 100644 --- a/club/views.py +++ b/club/views.py @@ -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): """ diff --git a/core/templates/core/base.jinja b/core/templates/core/base.jinja index a4a1b8e7..cd293c87 100644 --- a/core/templates/core/base.jinja +++ b/core/templates/core/base.jinja @@ -74,6 +74,22 @@ {% endblock %}
+ {% if list_of_tabs %} +
+
{{ tabs_title }}
+
+ {% for t in list_of_tabs %} + {{ t.name }} + {% endfor %} +
+
+
+ {% endif %} + {% if error %} {{ error }} {% endif %} diff --git a/core/templates/core/user_account.jinja b/core/templates/core/user_account.jinja index 991173c0..e06c04ec 100644 --- a/core/templates/core/user_account.jinja +++ b/core/templates/core/user_account.jinja @@ -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 %}

{% trans %}User account{% endtrans %}

{% trans %}Amount: {% endtrans %}{{ customer.amount }} €

diff --git a/core/templates/core/user_base.jinja b/core/templates/core/user_base.jinja deleted file mode 100644 index 1605f648..00000000 --- a/core/templates/core/user_base.jinja +++ /dev/null @@ -1,65 +0,0 @@ -{% extends "core/base.jinja" %} - -{% block content %} -
-
{{ profile.get_display_name() }}
-
- - {% trans %}Infos{% endtrans %} - - {% if profile == user %} - {% trans %}Tools{% endtrans %} - {% endif %} - - {% trans %}Stats{% endtrans %} - - {% if can_edit(profile, request.user) or user.id == profile.id %} - {% trans %}Edit{% endtrans %} - {% endif %} - - {% if can_edit_prop(profile, request.user) %} - {% trans %}Groups{% endtrans %} - {% 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) %} - {% trans %}Account{% endtrans %} ({{ profile.customer.amount }}€) - {% endif %} -
-
-
- -
- {% block infos %} - {% endblock %} -
- -{% endblock %} - - - diff --git a/core/templates/core/user_detail.jinja b/core/templates/core/user_detail.jinja index 8f4dcfd6..55eb0870 100644 --- a/core/templates/core/user_detail.jinja +++ b/core/templates/core/user_detail.jinja @@ -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 %}
diff --git a/core/templates/core/user_edit.jinja b/core/templates/core/user_edit.jinja index a54066b4..7bee0f15 100644 --- a/core/templates/core/user_edit.jinja +++ b/core/templates/core/user_edit.jinja @@ -1,10 +1,10 @@ -{% extends "core/user_base.jinja" %} +{% extends "core/base.jinja" %} {% block title %} {% trans %}Edit user{% endtrans %} {% endblock %} -{% block infos %} +{% block content %}

{% trans %}Edit user profile{% endtrans %}

{% csrf_token %} diff --git a/core/templates/core/user_group.jinja b/core/templates/core/user_group.jinja index f4471ea3..b062cafb 100644 --- a/core/templates/core/user_group.jinja +++ b/core/templates/core/user_group.jinja @@ -1,6 +1,6 @@ -{% extends "core/user_base.jinja" %} +{% extends "core/base.jinja" %} -{% block infos %} +{% block content %}

{% trans user_name=profile.get_full_name() %}Edit user groups for {{ user_name }}{% endtrans %}

{% csrf_token %} diff --git a/core/templates/core/user_stats.jinja b/core/templates/core/user_stats.jinja index b3a64820..bf1333d6 100644 --- a/core/templates/core/user_stats.jinja +++ b/core/templates/core/user_stats.jinja @@ -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 %}

{% trans %}Permanencies{% endtrans %}

diff --git a/core/templates/core/user_tools.jinja b/core/templates/core/user_tools.jinja index a6f4c6a9..1806d63d 100644 --- a/core/templates/core/user_tools.jinja +++ b/core/templates/core/user_tools.jinja @@ -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 %}

{% trans %}User Tools{% endtrans %}


diff --git a/core/views/__init__.py b/core/views/__init__.py index 1c8e6af8..4e958e8f 100644 --- a/core/views/__init__.py +++ b/core/views/__init__.py @@ -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 * + + diff --git a/core/views/user.py b/core/views/user.py index 302e0914..41224f64 100644 --- a/core/views/user.py +++ b/core/views/user.py @@ -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 diff --git a/counter/templates/counter/counter_base.jinja b/counter/templates/counter/counter_base.jinja deleted file mode 100644 index 2ac9d2bc..00000000 --- a/counter/templates/counter/counter_base.jinja +++ /dev/null @@ -1,40 +0,0 @@ -{% extends "core/base.jinja" %} - -{% block content %} - - -
- {% block admin_content %} - {% endblock %} -
- -{% endblock %} - - - diff --git a/counter/templates/counter/counter_list.jinja b/counter/templates/counter/counter_list.jinja index ddf0eab5..ca3ca699 100644 --- a/counter/templates/counter/counter_list.jinja +++ b/counter/templates/counter/counter_list.jinja @@ -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 %}

{% trans %}New counter{% endtrans %}

{% if counter_list %}

{% trans %}Counter admin list{% endtrans %}

diff --git a/counter/templates/counter/product_list.jinja b/counter/templates/counter/product_list.jinja index 0485a18f..05630a47 100644 --- a/counter/templates/counter/product_list.jinja +++ b/counter/templates/counter/product_list.jinja @@ -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" %}

{% trans %}New product{% endtrans %}

{% endif %} diff --git a/counter/templates/counter/producttype_list.jinja b/counter/templates/counter/producttype_list.jinja index e218fae8..9a686dc8 100644 --- a/counter/templates/counter/producttype_list.jinja +++ b/counter/templates/counter/producttype_list.jinja @@ -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 %}

{% trans %}New product type{% endtrans %}

{% if producttype_list %}

{% trans %}Product type list{% endtrans %}

diff --git a/counter/views.py b/counter/views.py index 920e31e2..77d1c26b 100644 --- a/counter/views.py +++ b/counter/views.py @@ -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): """