From a033c4dfd23a91972fafe470c3f2fcd5f80322cd Mon Sep 17 00:00:00 2001 From: Skia Date: Sat, 13 Aug 2016 16:39:09 +0200 Subject: [PATCH] Improve launderette rights to match with launderette club --- club/templates/club/club_tools.jinja | 21 +++++++++--------- core/management/commands/populate.py | 2 ++ core/static/core/style.css | 5 +++++ core/templates/core/user_tools.jinja | 4 ---- core/views/user.py | 6 +++++ launderette/models.py | 22 ++++++++++++++----- .../launderette/launderette_admin.jinja | 14 ++++++++++-- launderette/views.py | 8 ++++--- sith/settings_sample.py | 7 +++++- 9 files changed, 62 insertions(+), 27 deletions(-) diff --git a/club/templates/club/club_tools.jinja b/club/templates/club/club_tools.jinja index c8d49ee3..9b957ee0 100644 --- a/club/templates/club/club_tools.jinja +++ b/club/templates/club/club_tools.jinja @@ -5,22 +5,21 @@

Back to club

{% endblock %} diff --git a/core/management/commands/populate.py b/core/management/commands/populate.py index 7ec26c92..4418bda5 100644 --- a/core/management/commands/populate.py +++ b/core/management/commands/populate.py @@ -6,6 +6,7 @@ from django.core.management.base import BaseCommand, CommandError from django.core.management import call_command from django.conf import settings from django.db import connection +from django.contrib.sites.models import Site from core.models import Group, User, Page, PageRev, SithFile @@ -28,6 +29,7 @@ class Command(BaseCommand): def handle(self, *args, **options): os.environ['DJANGO_COLORS'] = 'nocolor' + Site(id=4000, domain=settings.SITH_URL, name=settings.SITH_NAME).save() root_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) for g in settings.SITH_GROUPS.values(): Group(id=g['id'], name=g['name']).save() diff --git a/core/static/core/style.css b/core/static/core/style.css index 3f333ea0..713ca7e9 100644 --- a/core/static/core/style.css +++ b/core/static/core/style.css @@ -105,6 +105,7 @@ p, pre { ul, ol { margin-top: 1em; + margin-bottom: 1em; list-style-type: disc; margin-left: 25px; } @@ -200,6 +201,10 @@ textarea { width: 98%; margin-top: 10px; } +/*---------------------------LAUNDERETTE-------------------------------*/ +#token_form label { + display: inline; +} /*--------------------------------FOOTER-------------------------------*/ footer{ diff --git a/core/templates/core/user_tools.jinja b/core/templates/core/user_tools.jinja index 6b759946..2be117be 100644 --- a/core/templates/core/user_tools.jinja +++ b/core/templates/core/user_tools.jinja @@ -16,10 +16,6 @@ {% if user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user.is_in_group(settings.SITH_GROUPS['root']['name']) %}
  • {% trans %}Subscriptions{% endtrans %}
  • {% endif %} -
    {% trans %}Launderette{% endtrans %}
    - {% if user.is_in_group(settings.SITH_GROUPS['launderette-admin']['name']) or user.is_in_group(settings.SITH_GROUPS['root']['name']) %} -
  • {% trans %}Launderette{% endtrans %}
  • - {% endif %}
    diff --git a/core/views/user.py b/core/views/user.py index 95da12a4..4edffd55 100644 --- a/core/views/user.py +++ b/core/views/user.py @@ -158,6 +158,12 @@ class UserToolsView(TemplateView): """ template_name = "core/user_tools.jinja" + def get_context_data(self, **kwargs): + from launderette.models import Launderette + kwargs = super(UserToolsView, self).get_context_data(**kwargs) + kwargs['launderettes'] = Launderette.objects.all() + return kwargs + class UserAccountView(DetailView): """ Display a user's account diff --git a/launderette/models.py b/launderette/models.py index b3bcf8f8..5f65fe75 100644 --- a/launderette/models.py +++ b/launderette/models.py @@ -3,10 +3,11 @@ from django.utils.translation import ugettext_lazy as _ from django.conf import settings from django.core.urlresolvers import reverse -from core.models import User from counter.models import Counter, Product +from core.models import User from subscription.models import Subscriber from subscription.views import get_subscriber +from club.models import Club # Create your models here. @@ -21,13 +22,18 @@ class Launderette(models.Model): """ Method to see if that object can be edited by the given user """ - if user.is_in_group(settings.SITH_GROUPS['launderette-admin']['name']): + launderette_club = Club.objects.filter(unix_name=settings.SITH_LAUNDERETTE_MANAGER['unix_name']).first() + m = launderette_club.get_membership_for(user) + if m and m.role >= 9: return True return False def can_be_edited_by(self, user): - sub = get_subscriber(user) - return sub in self.counter.sellers.all() + launderette_club = Club.objects.filter(unix_name=settings.SITH_LAUNDERETTE_MANAGER['unix_name']).first() + m = launderette_club.get_membership_for(user) + if m and m.role >= 2: + return True + return False def can_be_viewed_by(self, user): return user.is_in_group(settings.SITH_MAIN_MEMBERS_GROUP) @@ -63,7 +69,9 @@ class Machine(models.Model): """ Method to see if that object can be edited by the given user """ - if user.is_in_group(settings.SITH_GROUPS['launderette-admin']['name']): + launderette_club = Club.objects.filter(unix_name=settings.SITH_LAUNDERETTE_MANAGER['unix_name']).first() + m = launderette_club.get_membership_for(user) + if m and m.role >= 9: return True return False @@ -95,7 +103,9 @@ class Token(models.Model): """ Method to see if that object can be edited by the given user """ - if user.is_in_group(settings.SITH_GROUPS['launderette-admin']['name']): + launderette_club = Club.objects.filter(unix_name=settings.SITH_LAUNDERETTE_MANAGER['unix_name']).first() + m = launderette_club.get_membership_for(user) + if m and m.role >= 9: return True return False diff --git a/launderette/templates/launderette/launderette_admin.jinja b/launderette/templates/launderette/launderette_admin.jinja index aca57a52..07984a7a 100644 --- a/launderette/templates/launderette/launderette_admin.jinja +++ b/launderette/templates/launderette/launderette_admin.jinja @@ -19,9 +19,19 @@

    {% trans %}Tokens{% endtrans %}

    -

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

    {{ form.action.errors }} + {% for c in form.action %} + {{ c }} + {% endfor %} +

    +

    {{ form.token_type.errors }} + {% for c in form.token_type %} + {{ c }} + {% endfor %} +

    + {{ form.tokens }}

    diff --git a/launderette/views.py b/launderette/views.py index 885caada..11a0467c 100644 --- a/launderette/views.py +++ b/launderette/views.py @@ -143,13 +143,15 @@ class LaunderetteCreateView(CanCreateMixin, CreateView): return super(LaunderetteCreateView, self).form_valid(form) class ManageTokenForm(forms.Form): - action = forms.ChoiceField(choices=[("BACK", _("Back")), ("ADD", _("Add")), ("DEL", _("Delete"))], label=_("Action")) - token_type = forms.ChoiceField(choices=settings.SITH_LAUNDERETTE_MACHINE_TYPES, label=_("Type")) + action = forms.ChoiceField(choices=[("BACK", _("Back")), ("ADD", _("Add")), ("DEL", _("Delete"))], initial="BACK", + label=_("Action"), widget=forms.RadioSelect) + token_type = forms.ChoiceField(choices=settings.SITH_LAUNDERETTE_MACHINE_TYPES, label=_("Type"), initial="WASHING", + widget=forms.RadioSelect) tokens = forms.CharField(max_length=512, widget=forms.widgets.Textarea, label=_("Tokens, separated by spaces")) def process(self, launderette): cleaned_data = self.cleaned_data - token_list = cleaned_data['tokens'].strip(" ").split(" ") + token_list = cleaned_data['tokens'].strip(" \n\r").split(" ") token_type = cleaned_data['token_type'] self.data = {} if cleaned_data['action'] == "BACK": diff --git a/sith/settings_sample.py b/sith/settings_sample.py index 8b004e2a..4c2f5708 100644 --- a/sith/settings_sample.py +++ b/sith/settings_sample.py @@ -32,7 +32,7 @@ ALLOWED_HOSTS = [] # Application definition -SITE_ID = 1 +SITE_ID = 4000 INSTALLED_APPS = ( 'django.contrib.admin', @@ -167,6 +167,8 @@ LOCALE_PATHS = ( os.path.join(BASE_DIR, "locale"), ) +PHONENUMBER_DEFAULT_REGION = "FR" + # Medias MEDIA_ROOT = './data/' MEDIA_URL = '/data/' @@ -189,6 +191,9 @@ DEFAULT_FROM_EMAIL="bibou@git.an" EMAIL_HOST="localhost" EMAIL_PORT=25 +SITH_URL = "ae-taiste.utbm.fr" +SITH_NAME = "AE taiste" + # AE configuration SITH_MAIN_CLUB = { 'name': "AE",