mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
Refactor lots of tabed templates, and create TabedViewMixin
This commit is contained in:
parent
976ae09e55
commit
b1f6754e6e
@ -1,7 +1,7 @@
|
|||||||
{% extends "club/club_base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
{% from 'core/macros.jinja' import user_profile_link %}
|
{% from 'core/macros.jinja' import user_profile_link %}
|
||||||
|
|
||||||
{% block club %}
|
{% block content %}
|
||||||
<h3>{% trans %}Club{% endtrans %}</h3>
|
<h3>{% trans %}Club{% endtrans %}</h3>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -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 %}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -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 %}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
|||||||
{% extends "club/club_base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
{% from 'core/macros.jinja' import user_profile_link %}
|
{% from 'core/macros.jinja' import user_profile_link %}
|
||||||
|
|
||||||
{% block club %}
|
{% block content %}
|
||||||
<h2>{% trans %}Club members{% endtrans %}</h2>
|
<h2>{% trans %}Club members{% endtrans %}</h2>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{% extends "club/club_base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
{% from 'core/macros.jinja' import user_profile_link %}
|
{% from 'core/macros.jinja' import user_profile_link %}
|
||||||
|
|
||||||
{% block club %}
|
{% block content %}
|
||||||
<h2>{% trans %}Club old members{% endtrans %}</h2>
|
<h2>{% trans %}Club old members{% endtrans %}</h2>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{% extends "club/club_base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
|
|
||||||
{% block club %}
|
{% block content %}
|
||||||
<h3>{% trans %}Club tools{% endtrans %}</h3>
|
<h3>{% trans %}Club tools{% endtrans %}</h3>
|
||||||
<div>
|
<div>
|
||||||
{% if object.counters.filter(type="OFFICE")|count > 0 %}
|
{% if object.counters.filter(type="OFFICE")|count > 0 %}
|
||||||
|
@ -7,11 +7,53 @@ from django.core.exceptions import ValidationError
|
|||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.utils import timezone
|
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 club.models import Club, Membership
|
||||||
from sith.settings import SITH_MAXIMUM_FREE_ROLE, SITH_MAIN_BOARD_GROUP
|
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):
|
class ClubListView(ListView):
|
||||||
"""
|
"""
|
||||||
List the Clubs
|
List the Clubs
|
||||||
@ -19,31 +61,23 @@ class ClubListView(ListView):
|
|||||||
model = Club
|
model = Club
|
||||||
template_name = 'club/club_list.jinja'
|
template_name = 'club/club_list.jinja'
|
||||||
|
|
||||||
class ClubView(DetailView):
|
class ClubView(ClubTabsMixin, DetailView):
|
||||||
"""
|
"""
|
||||||
Front page of a Club
|
Front page of a Club
|
||||||
"""
|
"""
|
||||||
model = Club
|
model = Club
|
||||||
pk_url_kwarg = "club_id"
|
pk_url_kwarg = "club_id"
|
||||||
template_name = 'club/club_detail.jinja'
|
template_name = 'club/club_detail.jinja'
|
||||||
|
current_tab = "infos"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
class ClubToolsView(ClubTabsMixin, CanEditMixin, DetailView):
|
||||||
kwargs = super(ClubView, self).get_context_data(**kwargs)
|
|
||||||
kwargs['tab'] = "infos"
|
|
||||||
return kwargs
|
|
||||||
|
|
||||||
class ClubToolsView(CanEditMixin, DetailView):
|
|
||||||
"""
|
"""
|
||||||
Tools page of a Club
|
Tools page of a Club
|
||||||
"""
|
"""
|
||||||
model = Club
|
model = Club
|
||||||
pk_url_kwarg = "club_id"
|
pk_url_kwarg = "club_id"
|
||||||
template_name = 'club/club_tools.jinja'
|
template_name = 'club/club_tools.jinja'
|
||||||
|
current_tab = "tools"
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
kwargs = super(ClubToolsView, self).get_context_data(**kwargs)
|
|
||||||
kwargs['tab'] = "tools"
|
|
||||||
return kwargs
|
|
||||||
|
|
||||||
class ClubMemberForm(forms.ModelForm):
|
class ClubMemberForm(forms.ModelForm):
|
||||||
"""
|
"""
|
||||||
@ -76,7 +110,7 @@ class ClubMemberForm(forms.ModelForm):
|
|||||||
ret = super(ClubMemberForm, self).save(*args, **kwargs)
|
ret = super(ClubMemberForm, self).save(*args, **kwargs)
|
||||||
return self.instance.club
|
return self.instance.club
|
||||||
|
|
||||||
class ClubMembersView(CanViewMixin, UpdateView):
|
class ClubMembersView(ClubTabsMixin, CanViewMixin, UpdateView):
|
||||||
"""
|
"""
|
||||||
View of a club's members
|
View of a club's members
|
||||||
"""
|
"""
|
||||||
@ -84,6 +118,7 @@ class ClubMembersView(CanViewMixin, UpdateView):
|
|||||||
pk_url_kwarg = "club_id"
|
pk_url_kwarg = "club_id"
|
||||||
form_class = ClubMemberForm
|
form_class = ClubMemberForm
|
||||||
template_name = 'club/club_members.jinja'
|
template_name = 'club/club_members.jinja'
|
||||||
|
current_tab = "members"
|
||||||
|
|
||||||
def get_form(self):
|
def get_form(self):
|
||||||
"""
|
"""
|
||||||
@ -99,51 +134,34 @@ class ClubMembersView(CanViewMixin, UpdateView):
|
|||||||
form._user = self.request.user
|
form._user = self.request.user
|
||||||
return form
|
return form
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
class ClubOldMembersView(ClubTabsMixin, CanViewMixin, DetailView):
|
||||||
kwargs = super(ClubMembersView, self).get_context_data(**kwargs)
|
|
||||||
kwargs['tab'] = "members"
|
|
||||||
return kwargs
|
|
||||||
|
|
||||||
class ClubOldMembersView(CanViewMixin, DetailView):
|
|
||||||
"""
|
"""
|
||||||
Old members of a club
|
Old members of a club
|
||||||
"""
|
"""
|
||||||
model = Club
|
model = Club
|
||||||
pk_url_kwarg = "club_id"
|
pk_url_kwarg = "club_id"
|
||||||
template_name = 'club/club_old_members.jinja'
|
template_name = 'club/club_old_members.jinja'
|
||||||
|
current_tab = "elderlies"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
class ClubEditView(ClubTabsMixin, CanEditMixin, UpdateView):
|
||||||
kwargs = super(ClubOldMembersView, self).get_context_data(**kwargs)
|
|
||||||
kwargs['tab'] = "elderlies"
|
|
||||||
return kwargs
|
|
||||||
|
|
||||||
class ClubEditView(CanEditMixin, UpdateView):
|
|
||||||
"""
|
"""
|
||||||
Edit a Club's main informations (for the club's members)
|
Edit a Club's main informations (for the club's members)
|
||||||
"""
|
"""
|
||||||
model = Club
|
model = Club
|
||||||
pk_url_kwarg = "club_id"
|
pk_url_kwarg = "club_id"
|
||||||
fields = ['address']
|
fields = ['address']
|
||||||
template_name = 'club/club_edit.jinja'
|
template_name = 'core/edit.jinja'
|
||||||
|
current_tab = "edit"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
class ClubEditPropView(ClubTabsMixin, CanEditPropMixin, UpdateView):
|
||||||
kwargs = super(ClubEditView, self).get_context_data(**kwargs)
|
|
||||||
kwargs['tab'] = "edit"
|
|
||||||
return kwargs
|
|
||||||
|
|
||||||
class ClubEditPropView(CanEditPropMixin, UpdateView):
|
|
||||||
"""
|
"""
|
||||||
Edit the properties of a Club object (for the Sith admins)
|
Edit the properties of a Club object (for the Sith admins)
|
||||||
"""
|
"""
|
||||||
model = Club
|
model = Club
|
||||||
pk_url_kwarg = "club_id"
|
pk_url_kwarg = "club_id"
|
||||||
fields = ['name', 'unix_name', 'parent']
|
fields = ['name', 'unix_name', 'parent']
|
||||||
template_name = 'club/club_edit_prop.jinja'
|
template_name = 'core/edit.jinja'
|
||||||
|
current_tab = "props"
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
kwargs = super(ClubEditPropView, self).get_context_data(**kwargs)
|
|
||||||
kwargs['tab'] = "props"
|
|
||||||
return kwargs
|
|
||||||
|
|
||||||
class ClubCreateView(CanEditPropMixin, CreateView):
|
class ClubCreateView(CanEditPropMixin, CreateView):
|
||||||
"""
|
"""
|
||||||
@ -152,7 +170,7 @@ class ClubCreateView(CanEditPropMixin, CreateView):
|
|||||||
model = Club
|
model = Club
|
||||||
pk_url_kwarg = "club_id"
|
pk_url_kwarg = "club_id"
|
||||||
fields = ['name', 'unix_name', 'parent']
|
fields = ['name', 'unix_name', 'parent']
|
||||||
template_name = 'club/club_edit_prop.jinja'
|
template_name = 'core/edit.jinja'
|
||||||
|
|
||||||
class MembershipSetOldView(CanEditMixin, DetailView):
|
class MembershipSetOldView(CanEditMixin, DetailView):
|
||||||
"""
|
"""
|
||||||
|
@ -74,6 +74,22 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
<div id="content">
|
<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 %}
|
{% if error %}
|
||||||
{{ error }}
|
{{ error }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{% extends "core/user_base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{% trans user_name=profile.get_display_name() %}{{ user_name }}'s account{% endtrans %}
|
{% trans user_name=profile.get_display_name() %}{{ user_name }}'s account{% endtrans %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block infos %}
|
{% block content %}
|
||||||
{% if customer %}
|
{% if customer %}
|
||||||
<h3>{% trans %}User account{% endtrans %}</h3>
|
<h3>{% trans %}User account{% endtrans %}</h3>
|
||||||
<p>{% trans %}Amount: {% endtrans %}{{ customer.amount }} €</p>
|
<p>{% trans %}Amount: {% endtrans %}{{ customer.amount }} €</p>
|
||||||
|
@ -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 %}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
|||||||
{% extends "core/user_base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{% trans user_name=profile.get_display_name() %}{{ user_name }}'s profile{% endtrans %}
|
{% trans user_name=profile.get_display_name() %}{{ user_name }}'s profile{% endtrans %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block infos %}
|
{% block content %}
|
||||||
|
|
||||||
<div id="user_profile_container">
|
<div id="user_profile_container">
|
||||||
<div id="user_profile">
|
<div id="user_profile">
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{% extends "core/user_base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{% trans %}Edit user{% endtrans %}
|
{% trans %}Edit user{% endtrans %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block infos %}
|
{% block content %}
|
||||||
<h2>{% trans %}Edit user profile{% endtrans %}</h2>
|
<h2>{% trans %}Edit user profile{% endtrans %}</h2>
|
||||||
<form action="" method="post" enctype="multipart/form-data" id="user_edit">
|
<form action="" method="post" enctype="multipart/form-data" id="user_edit">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
@ -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>
|
<h2>{% trans user_name=profile.get_full_name() %}Edit user groups for {{ user_name }}{% endtrans %}</h2>
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{% extends "core/user_base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{% trans user_name=profile.get_display_name() %}{{ user_name }}'s stats{% endtrans %}
|
{% trans user_name=profile.get_display_name() %}{{ user_name }}'s stats{% endtrans %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block infos %}
|
{% block content %}
|
||||||
{% if profile.permanencies %}
|
{% if profile.permanencies %}
|
||||||
<div>
|
<div>
|
||||||
<h3>{% trans %}Permanencies{% endtrans %}</h3>
|
<h3>{% trans %}Permanencies{% endtrans %}</h3>
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{% extends "core/user_base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{% trans user_name=user.get_display_name() %}{{ user_name }}'s tools{% endtrans %}
|
{% trans user_name=user.get_display_name() %}{{ user_name }}'s tools{% endtrans %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block infos %}
|
{% block content %}
|
||||||
<h3>{% trans %}User Tools{% endtrans %}</h3>
|
<h3>{% trans %}User Tools{% endtrans %}</h3>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponseForbidden, HttpResponseNotFound
|
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 django.views.generic.base import View
|
||||||
|
|
||||||
from core.models import Group
|
from core.models import Group
|
||||||
@ -110,8 +110,39 @@ class CanViewMixin(View):
|
|||||||
context['object_list'] = l
|
context['object_list'] = l
|
||||||
return context
|
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 .user import *
|
||||||
from .page import *
|
from .page import *
|
||||||
from .files import *
|
from .files import *
|
||||||
from .site import *
|
from .site import *
|
||||||
from .group import *
|
from .group import *
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ from django.conf import settings
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
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.views.forms import RegisteringForm, UserPropForm, UserProfileForm, LoginForm
|
||||||
from core.models import User, SithFile
|
from core.models import User, SithFile
|
||||||
|
|
||||||
@ -96,7 +96,6 @@ def password_reset_complete(request):
|
|||||||
template_name="core/password_reset_complete.jinja",
|
template_name="core/password_reset_complete.jinja",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def register(request):
|
def register(request):
|
||||||
context = {}
|
context = {}
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
@ -115,7 +114,53 @@ def register(request):
|
|||||||
context['form'] = form.as_p()
|
context['form'] = form.as_p()
|
||||||
return render(request, "core/register.jinja", context)
|
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
|
Display a user's profile
|
||||||
"""
|
"""
|
||||||
@ -123,13 +168,9 @@ class UserView(CanViewMixin, DetailView):
|
|||||||
pk_url_kwarg = "user_id"
|
pk_url_kwarg = "user_id"
|
||||||
context_object_name = "profile"
|
context_object_name = "profile"
|
||||||
template_name = "core/user_detail.jinja"
|
template_name = "core/user_detail.jinja"
|
||||||
|
current_tab = 'infos'
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
class UserStatsView(UserTabsMixin, CanViewMixin, DetailView):
|
||||||
kwargs = super(UserView, self).get_context_data(**kwargs)
|
|
||||||
kwargs['tab'] = "infos"
|
|
||||||
return kwargs
|
|
||||||
|
|
||||||
class UserStatsView(CanViewMixin, DetailView):
|
|
||||||
"""
|
"""
|
||||||
Display a user's stats
|
Display a user's stats
|
||||||
"""
|
"""
|
||||||
@ -137,6 +178,7 @@ class UserStatsView(CanViewMixin, DetailView):
|
|||||||
pk_url_kwarg = "user_id"
|
pk_url_kwarg = "user_id"
|
||||||
context_object_name = "profile"
|
context_object_name = "profile"
|
||||||
template_name = "core/user_stats.jinja"
|
template_name = "core/user_stats.jinja"
|
||||||
|
current_tab = 'stats'
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
kwargs = super(UserStatsView, self).get_context_data(**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_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_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['total_gommette_time'] = sum([p.end-p.start for p in self.object.permanencies.filter(counter=gommette)], timedelta())
|
||||||
kwargs['tab'] = "stats"
|
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
class UserMiniView(CanViewMixin, DetailView):
|
class UserMiniView(CanViewMixin, DetailView):
|
||||||
@ -196,7 +237,7 @@ class UserUploadProfilePictView(CanEditMixin, DetailView):
|
|||||||
self.object.save()
|
self.object.save()
|
||||||
return redirect("core:user_edit", user_id=self.object.id)
|
return redirect("core:user_edit", user_id=self.object.id)
|
||||||
|
|
||||||
class UserUpdateProfileView(CanEditMixin, UpdateView):
|
class UserUpdateProfileView(UserTabsMixin, CanEditMixin, UpdateView):
|
||||||
"""
|
"""
|
||||||
Edit a user's profile
|
Edit a user's profile
|
||||||
"""
|
"""
|
||||||
@ -204,6 +245,7 @@ class UserUpdateProfileView(CanEditMixin, UpdateView):
|
|||||||
pk_url_kwarg = "user_id"
|
pk_url_kwarg = "user_id"
|
||||||
template_name = "core/user_edit.jinja"
|
template_name = "core/user_edit.jinja"
|
||||||
form_class = UserProfileForm
|
form_class = UserProfileForm
|
||||||
|
current_tab = "edit"
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
@ -227,10 +269,9 @@ class UserUpdateProfileView(CanEditMixin, UpdateView):
|
|||||||
kwargs = super(UserUpdateProfileView, self).get_context_data(**kwargs)
|
kwargs = super(UserUpdateProfileView, self).get_context_data(**kwargs)
|
||||||
kwargs['profile'] = self.form.instance
|
kwargs['profile'] = self.form.instance
|
||||||
kwargs['form'] = self.form
|
kwargs['form'] = self.form
|
||||||
kwargs['tab'] = "edit"
|
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
class UserUpdateGroupView(CanEditPropMixin, UpdateView):
|
class UserUpdateGroupView(UserTabsMixin, CanEditPropMixin, UpdateView):
|
||||||
"""
|
"""
|
||||||
Edit a user's groups
|
Edit a user's groups
|
||||||
"""
|
"""
|
||||||
@ -240,33 +281,32 @@ class UserUpdateGroupView(CanEditPropMixin, UpdateView):
|
|||||||
form_class = modelform_factory(User, fields=['groups'],
|
form_class = modelform_factory(User, fields=['groups'],
|
||||||
widgets={'groups':CheckboxSelectMultiple})
|
widgets={'groups':CheckboxSelectMultiple})
|
||||||
context_object_name = "profile"
|
context_object_name = "profile"
|
||||||
|
current_tab = "groups"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
class UserToolsView(UserTabsMixin, TemplateView):
|
||||||
kwargs = super(UserUpdateGroupView, self).get_context_data(**kwargs)
|
|
||||||
kwargs['tab'] = "groups"
|
|
||||||
return kwargs
|
|
||||||
|
|
||||||
class UserToolsView(TemplateView):
|
|
||||||
"""
|
"""
|
||||||
Displays the logged user's tools
|
Displays the logged user's tools
|
||||||
"""
|
"""
|
||||||
template_name = "core/user_tools.jinja"
|
template_name = "core/user_tools.jinja"
|
||||||
|
current_tab = "tools"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
self.object = self.request.user
|
||||||
from launderette.models import Launderette
|
from launderette.models import Launderette
|
||||||
kwargs = super(UserToolsView, self).get_context_data(**kwargs)
|
kwargs = super(UserToolsView, self).get_context_data(**kwargs)
|
||||||
kwargs['launderettes'] = Launderette.objects.all()
|
kwargs['launderettes'] = Launderette.objects.all()
|
||||||
kwargs['profile'] = self.request.user
|
kwargs['profile'] = self.request.user
|
||||||
kwargs['tab'] = "tools"
|
kwargs['object'] = self.request.user
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
class UserAccountView(DetailView):
|
class UserAccountView(UserTabsMixin, DetailView):
|
||||||
"""
|
"""
|
||||||
Display a user's account
|
Display a user's account
|
||||||
"""
|
"""
|
||||||
model = User
|
model = User
|
||||||
pk_url_kwarg = "user_id"
|
pk_url_kwarg = "user_id"
|
||||||
template_name = "core/user_account.jinja"
|
template_name = "core/user_account.jinja"
|
||||||
|
current_tab = "account"
|
||||||
|
|
||||||
def dispatch(self, request, *arg, **kwargs): # Manually validates the rights
|
def dispatch(self, request, *arg, **kwargs): # Manually validates the rights
|
||||||
res = super(UserAccountView, self).dispatch(request, *arg, **kwargs)
|
res = super(UserAccountView, self).dispatch(request, *arg, **kwargs)
|
||||||
@ -284,7 +324,6 @@ class UserAccountView(DetailView):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
# TODO: add list of month where account has activity
|
# TODO: add list of month where account has activity
|
||||||
kwargs['tab'] = "account"
|
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
|
@ -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 %}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
|||||||
{% extends "counter/counter_base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{% trans %}Counter admin list{% endtrans %}
|
{% trans %}Counter admin list{% endtrans %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block admin_content %}
|
{% block content %}
|
||||||
<p><a href="{{ url('counter:new') }}">{% trans %}New counter{% endtrans %}</a></p>
|
<p><a href="{{ url('counter:new') }}">{% trans %}New counter{% endtrans %}</a></p>
|
||||||
{% if counter_list %}
|
{% if counter_list %}
|
||||||
<h3>{% trans %}Counter admin list{% endtrans %}</h3>
|
<h3>{% trans %}Counter admin list{% endtrans %}</h3>
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{% extends "counter/counter_base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{% trans %}Product list{% endtrans %}
|
{% trans %}Product list{% endtrans %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block admin_content %}
|
{% block content %}
|
||||||
{% if tab == "products" %}
|
{% if tab == "products" %}
|
||||||
<p><a href="{{ url('counter:new_product') }}">{% trans %}New product{% endtrans %}</a></p>
|
<p><a href="{{ url('counter:new_product') }}">{% trans %}New product{% endtrans %}</a></p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{% extends "counter/counter_base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{% trans %}Product type list{% endtrans %}
|
{% trans %}Product type list{% endtrans %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block admin_content %}
|
{% block content %}
|
||||||
<p><a href="{{ url('counter:new_producttype') }}">{% trans %}New product type{% endtrans %}</a></p>
|
<p><a href="{{ url('counter:new_producttype') }}">{% trans %}New product type{% endtrans %}</a></p>
|
||||||
{% if producttype_list %}
|
{% if producttype_list %}
|
||||||
<h3>{% trans %}Product type list{% endtrans %}</h3>
|
<h3>{% trans %}Product type list{% endtrans %}</h3>
|
||||||
|
@ -16,7 +16,7 @@ from datetime import date, timedelta
|
|||||||
from ajax_select.fields import AutoCompleteSelectField, AutoCompleteSelectMultipleField
|
from ajax_select.fields import AutoCompleteSelectField, AutoCompleteSelectMultipleField
|
||||||
from ajax_select import make_ajax_form, make_ajax_field
|
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.views.forms import SelectUser, LoginForm
|
||||||
from core.models import User
|
from core.models import User
|
||||||
from subscription.models import Subscriber
|
from subscription.models import Subscriber
|
||||||
@ -383,17 +383,38 @@ class CounterLogout(RedirectView):
|
|||||||
|
|
||||||
## Counter admin views
|
## 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
|
A list view for the admins
|
||||||
"""
|
"""
|
||||||
model = Counter
|
model = Counter
|
||||||
template_name = 'counter/counter_list.jinja'
|
template_name = 'counter/counter_list.jinja'
|
||||||
|
current_tab = "counters"
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
kwargs = super(CounterListView, self).get_context_data(**kwargs)
|
|
||||||
kwargs['tab'] = "counters"
|
|
||||||
return kwargs
|
|
||||||
|
|
||||||
class CounterEditForm(forms.ModelForm):
|
class CounterEditForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -402,7 +423,7 @@ class CounterEditForm(forms.ModelForm):
|
|||||||
sellers = make_ajax_field(Counter, 'sellers', 'users', help_text="")
|
sellers = make_ajax_field(Counter, 'sellers', 'users', help_text="")
|
||||||
products = make_ajax_field(Counter, 'products', 'products', 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)
|
Edit a counter's main informations (for the counter's manager)
|
||||||
"""
|
"""
|
||||||
@ -410,11 +431,12 @@ class CounterEditView(CanEditMixin, UpdateView):
|
|||||||
form_class = CounterEditForm
|
form_class = CounterEditForm
|
||||||
pk_url_kwarg = "counter_id"
|
pk_url_kwarg = "counter_id"
|
||||||
template_name = 'core/edit.jinja'
|
template_name = 'core/edit.jinja'
|
||||||
|
current_tab = "counters"
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse_lazy('counter:admin', kwargs={'counter_id': self.object.id})
|
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)
|
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'])
|
form_class = modelform_factory(Counter, fields=['name', 'club', 'type'])
|
||||||
pk_url_kwarg = "counter_id"
|
pk_url_kwarg = "counter_id"
|
||||||
template_name = 'core/edit.jinja'
|
template_name = 'core/edit.jinja'
|
||||||
|
current_tab = "counters"
|
||||||
|
|
||||||
class CounterCreateView(CanEditMixin, CreateView):
|
class CounterCreateView(CounterTabsMixin, CanEditMixin, CreateView):
|
||||||
"""
|
"""
|
||||||
Create a counter (for the admins)
|
Create a counter (for the admins)
|
||||||
"""
|
"""
|
||||||
@ -431,8 +454,9 @@ class CounterCreateView(CanEditMixin, CreateView):
|
|||||||
form_class = modelform_factory(Counter, fields=['name', 'club', 'type', 'products'],
|
form_class = modelform_factory(Counter, fields=['name', 'club', 'type', 'products'],
|
||||||
widgets={'products':CheckboxSelectMultiple})
|
widgets={'products':CheckboxSelectMultiple})
|
||||||
template_name = 'core/create.jinja'
|
template_name = 'core/create.jinja'
|
||||||
|
current_tab = "counters"
|
||||||
|
|
||||||
class CounterDeleteView(CanEditMixin, DeleteView):
|
class CounterDeleteView(CounterTabsMixin, CanEditMixin, DeleteView):
|
||||||
"""
|
"""
|
||||||
Delete a counter (for the admins)
|
Delete a counter (for the admins)
|
||||||
"""
|
"""
|
||||||
@ -440,30 +464,28 @@ class CounterDeleteView(CanEditMixin, DeleteView):
|
|||||||
pk_url_kwarg = "counter_id"
|
pk_url_kwarg = "counter_id"
|
||||||
template_name = 'core/delete_confirm.jinja'
|
template_name = 'core/delete_confirm.jinja'
|
||||||
success_url = reverse_lazy('counter:admin_list')
|
success_url = reverse_lazy('counter:admin_list')
|
||||||
|
current_tab = "counters"
|
||||||
|
|
||||||
# Product management
|
# Product management
|
||||||
|
|
||||||
class ProductTypeListView(CanEditPropMixin, ListView):
|
class ProductTypeListView(CounterTabsMixin, CanEditPropMixin, ListView):
|
||||||
"""
|
"""
|
||||||
A list view for the admins
|
A list view for the admins
|
||||||
"""
|
"""
|
||||||
model = ProductType
|
model = ProductType
|
||||||
template_name = 'counter/producttype_list.jinja'
|
template_name = 'counter/producttype_list.jinja'
|
||||||
|
current_tab = "product_types"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
class ProductTypeCreateView(CounterTabsMixin, CanCreateMixin, CreateView):
|
||||||
kwargs = super(ProductTypeListView, self).get_context_data(**kwargs)
|
|
||||||
kwargs['tab'] = "product_types"
|
|
||||||
return kwargs
|
|
||||||
|
|
||||||
class ProductTypeCreateView(CanCreateMixin, CreateView):
|
|
||||||
"""
|
"""
|
||||||
A create view for the admins
|
A create view for the admins
|
||||||
"""
|
"""
|
||||||
model = ProductType
|
model = ProductType
|
||||||
fields = ['name', 'description', 'icon']
|
fields = ['name', 'description', 'icon']
|
||||||
template_name = 'core/create.jinja'
|
template_name = 'core/create.jinja'
|
||||||
|
current_tab = "products"
|
||||||
|
|
||||||
class ProductTypeEditView(CanEditPropMixin, UpdateView):
|
class ProductTypeEditView(CounterTabsMixin, CanEditPropMixin, UpdateView):
|
||||||
"""
|
"""
|
||||||
An edit view for the admins
|
An edit view for the admins
|
||||||
"""
|
"""
|
||||||
@ -471,8 +493,9 @@ class ProductTypeEditView(CanEditPropMixin, UpdateView):
|
|||||||
template_name = 'core/edit.jinja'
|
template_name = 'core/edit.jinja'
|
||||||
fields = ['name', 'description', 'icon']
|
fields = ['name', 'description', 'icon']
|
||||||
pk_url_kwarg = "type_id"
|
pk_url_kwarg = "type_id"
|
||||||
|
current_tab = "products"
|
||||||
|
|
||||||
class ProductArchivedListView(CanEditPropMixin, ListView):
|
class ProductArchivedListView(CounterTabsMixin, CanEditPropMixin, ListView):
|
||||||
"""
|
"""
|
||||||
A list view for the admins
|
A list view for the admins
|
||||||
"""
|
"""
|
||||||
@ -480,13 +503,9 @@ class ProductArchivedListView(CanEditPropMixin, ListView):
|
|||||||
template_name = 'counter/product_list.jinja'
|
template_name = 'counter/product_list.jinja'
|
||||||
queryset = Product.objects.filter(archived=True)
|
queryset = Product.objects.filter(archived=True)
|
||||||
ordering = ['name']
|
ordering = ['name']
|
||||||
|
current_tab = "archive"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
class ProductListView(CounterTabsMixin, CanEditPropMixin, ListView):
|
||||||
kwargs = super(ProductArchivedListView, self).get_context_data(**kwargs)
|
|
||||||
kwargs['tab'] = "archive"
|
|
||||||
return kwargs
|
|
||||||
|
|
||||||
class ProductListView(CanEditPropMixin, ListView):
|
|
||||||
"""
|
"""
|
||||||
A list view for the admins
|
A list view for the admins
|
||||||
"""
|
"""
|
||||||
@ -494,11 +513,7 @@ class ProductListView(CanEditPropMixin, ListView):
|
|||||||
template_name = 'counter/product_list.jinja'
|
template_name = 'counter/product_list.jinja'
|
||||||
queryset = Product.objects.filter(archived=False)
|
queryset = Product.objects.filter(archived=False)
|
||||||
ordering = ['name']
|
ordering = ['name']
|
||||||
|
current_tab = "products"
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
kwargs = super(ProductListView, self).get_context_data(**kwargs)
|
|
||||||
kwargs['tab'] = "products"
|
|
||||||
return kwargs
|
|
||||||
|
|
||||||
class ProductEditForm(forms.ModelForm):
|
class ProductEditForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -528,15 +543,16 @@ class ProductEditForm(forms.ModelForm):
|
|||||||
c.save()
|
c.save()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
class ProductCreateView(CanCreateMixin, CreateView):
|
class ProductCreateView(CounterTabsMixin, CanCreateMixin, CreateView):
|
||||||
"""
|
"""
|
||||||
A create view for the admins
|
A create view for the admins
|
||||||
"""
|
"""
|
||||||
model = Product
|
model = Product
|
||||||
form_class = ProductEditForm
|
form_class = ProductEditForm
|
||||||
template_name = 'core/create.jinja'
|
template_name = 'core/create.jinja'
|
||||||
|
current_tab = "products"
|
||||||
|
|
||||||
class ProductEditView(CanEditPropMixin, UpdateView):
|
class ProductEditView(CounterTabsMixin, CanEditPropMixin, UpdateView):
|
||||||
"""
|
"""
|
||||||
An edit view for the admins
|
An edit view for the admins
|
||||||
"""
|
"""
|
||||||
@ -544,6 +560,7 @@ class ProductEditView(CanEditPropMixin, UpdateView):
|
|||||||
form_class = ProductEditForm
|
form_class = ProductEditForm
|
||||||
pk_url_kwarg = "product_id"
|
pk_url_kwarg = "product_id"
|
||||||
template_name = 'core/edit.jinja'
|
template_name = 'core/edit.jinja'
|
||||||
|
current_tab = "products"
|
||||||
|
|
||||||
class RefillingDeleteView(CanEditPropMixin, DeleteView):
|
class RefillingDeleteView(CanEditPropMixin, DeleteView):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user