Commit a033c4df authored by Skia's avatar Skia
Browse files

Improve launderette rights to match with launderette club

parent 4ec32855
Pipeline #113 failed with stage
in 3 minutes and 1 second
...@@ -5,22 +5,21 @@ ...@@ -5,22 +5,21 @@
<p><a href="{{ url('club:club_view', club_id=object.id) }}">Back to club</a></p> <p><a href="{{ url('club:club_view', club_id=object.id) }}">Back to club</a></p>
<ul> <ul>
{% if object.counters.all()|count > 0 %} {% if object.counters.all()|count > 0 %}
<li><h4>{% trans %}Counters:{% endtrans %}</h4> <h4>{% trans %}Counters:{% endtrans %}</h4>
<ul> <ul>
{% for c in object.counters.all() %} {% for c in object.counters.all() %}
<li>{{ c }}: <li>{{ c }}:
<a href="{{ url('counter:details', counter_id=c.id) }}">View</a> <a href="{{ url('counter:details', counter_id=c.id) }}">View</a>
<a href="{{ url('counter:admin', counter_id=c.id) }}">Edit</a> <a href="{{ url('counter:admin', counter_id=c.id) }}">Edit</a>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
</li>
{% endif %} {% endif %}
{% if object.club_account %} {% if object.club_account %}
<li>Accouting: <a href="{{ url('accounting:club_details', c_account_id=object.club_account.id) }}">{{ object }}</a></li> <li>Accouting: <a href="{{ url('accounting:club_details', c_account_id=object.club_account.id) }}">{{ object }}</a></li>
{% endif %} {% endif %}
{% if object.unix_name == settings.SITH_LAUNDERETTE_MANAGER['unix_name'] %} {% if object.unix_name == settings.SITH_LAUNDERETTE_MANAGER['unix_name'] %}
<li><a href="{{ url('launderette:launderette_list') }}">{% trans %}Launderette{% endtrans %}</a></li> <li><a href="{{ url('launderette:launderette_list') }}">{% trans %}Manage launderettes{% endtrans %}</a></li>
{% endif %} {% endif %}
</ul> </ul>
{% endblock %} {% endblock %}
......
...@@ -6,6 +6,7 @@ from django.core.management.base import BaseCommand, CommandError ...@@ -6,6 +6,7 @@ from django.core.management.base import BaseCommand, CommandError
from django.core.management import call_command from django.core.management import call_command
from django.conf import settings from django.conf import settings
from django.db import connection from django.db import connection
from django.contrib.sites.models import Site
from core.models import Group, User, Page, PageRev, SithFile from core.models import Group, User, Page, PageRev, SithFile
...@@ -28,6 +29,7 @@ class Command(BaseCommand): ...@@ -28,6 +29,7 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
os.environ['DJANGO_COLORS'] = 'nocolor' 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__)))) root_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
for g in settings.SITH_GROUPS.values(): for g in settings.SITH_GROUPS.values():
Group(id=g['id'], name=g['name']).save() Group(id=g['id'], name=g['name']).save()
......
...@@ -105,6 +105,7 @@ p, pre { ...@@ -105,6 +105,7 @@ p, pre {
ul, ol { ul, ol {
margin-top: 1em; margin-top: 1em;
margin-bottom: 1em;
list-style-type: disc; list-style-type: disc;
margin-left: 25px; margin-left: 25px;
} }
...@@ -200,6 +201,10 @@ textarea { ...@@ -200,6 +201,10 @@ textarea {
width: 98%; width: 98%;
margin-top: 10px; margin-top: 10px;
} }
/*---------------------------LAUNDERETTE-------------------------------*/
#token_form label {
display: inline;
}
/*--------------------------------FOOTER-------------------------------*/ /*--------------------------------FOOTER-------------------------------*/
footer{ footer{
......
...@@ -16,10 +16,6 @@ ...@@ -16,10 +16,6 @@
{% if user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user.is_in_group(settings.SITH_GROUPS['root']['name']) %} {% if user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user.is_in_group(settings.SITH_GROUPS['root']['name']) %}
<li><a href="{{ url('subscription:subscription') }}">{% trans %}Subscriptions{% endtrans %}</a></li> <li><a href="{{ url('subscription:subscription') }}">{% trans %}Subscriptions{% endtrans %}</a></li>
{% endif %} {% endif %}
<h5>{% trans %}Launderette{% endtrans %}</h5>
{% if user.is_in_group(settings.SITH_GROUPS['launderette-admin']['name']) or user.is_in_group(settings.SITH_GROUPS['root']['name']) %}
<li><a href="{{ url('launderette:launderette_list') }}">{% trans %}Launderette{% endtrans %}</a></li>
{% endif %}
</ul> </ul>
<hr> <hr>
......
...@@ -158,6 +158,12 @@ class UserToolsView(TemplateView): ...@@ -158,6 +158,12 @@ class UserToolsView(TemplateView):
""" """
template_name = "core/user_tools.jinja" 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): class UserAccountView(DetailView):
""" """
Display a user's account Display a user's account
......
...@@ -3,10 +3,11 @@ from django.utils.translation import ugettext_lazy as _ ...@@ -3,10 +3,11 @@ from django.utils.translation import ugettext_lazy as _
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from core.models import User
from counter.models import Counter, Product from counter.models import Counter, Product
from core.models import User
from subscription.models import Subscriber from subscription.models import Subscriber
from subscription.views import get_subscriber from subscription.views import get_subscriber
from club.models import Club
# Create your models here. # Create your models here.
...@@ -21,13 +22,18 @@ class Launderette(models.Model): ...@@ -21,13 +22,18 @@ class Launderette(models.Model):
""" """
Method to see if that object can be edited by the given user 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 True
return False return False
def can_be_edited_by(self, user): def can_be_edited_by(self, user):
sub = get_subscriber(user) launderette_club = Club.objects.filter(unix_name=settings.SITH_LAUNDERETTE_MANAGER['unix_name']).first()
return sub in self.counter.sellers.all() m = launderette_club.get_membership_for(user)
if m and m.role >= 2:
return True
return False
def can_be_viewed_by(self, user): def can_be_viewed_by(self, user):
return user.is_in_group(settings.SITH_MAIN_MEMBERS_GROUP) return user.is_in_group(settings.SITH_MAIN_MEMBERS_GROUP)
...@@ -63,7 +69,9 @@ class Machine(models.Model): ...@@ -63,7 +69,9 @@ class Machine(models.Model):
""" """
Method to see if that object can be edited by the given user 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 True
return False return False
...@@ -95,7 +103,9 @@ class Token(models.Model): ...@@ -95,7 +103,9 @@ class Token(models.Model):
""" """
Method to see if that object can be edited by the given user 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 True
return False return False
......
...@@ -19,9 +19,19 @@ ...@@ -19,9 +19,19 @@
<hr> <hr>
<h3>{% trans %}Tokens{% endtrans %}</h3> <h3>{% trans %}Tokens{% endtrans %}</h3>
<p> <p>
<form method="post" action=""> <form method="post" action="" id="token_form">
{% csrf_token %} {% csrf_token %}
{{ form.as_p() }} <p>{{ form.action.errors }}<label for="{{ form.action.name }}">{{ form.action.label }}</label>
{% for c in form.action %}
{{ c }}
{% endfor %}
</p>
<p>{{ form.token_type.errors }}<label for="{{ form.token_type.name }}">{{ form.token_type.label }}</label>
{% for c in form.token_type %}
{{ c }}
{% endfor %}
</p>
{{ form.tokens }}
<p><input type="submit" value="{% trans %}Go{% endtrans %}" /></p> <p><input type="submit" value="{% trans %}Go{% endtrans %}" /></p>
</form> </form>
</p> </p>
......
...@@ -143,13 +143,15 @@ class LaunderetteCreateView(CanCreateMixin, CreateView): ...@@ -143,13 +143,15 @@ class LaunderetteCreateView(CanCreateMixin, CreateView):
return super(LaunderetteCreateView, self).form_valid(form) return super(LaunderetteCreateView, self).form_valid(form)
class ManageTokenForm(forms.Form): class ManageTokenForm(forms.Form):
action = forms.ChoiceField(choices=[("BACK", _("Back")), ("ADD", _("Add")), ("DEL", _("Delete"))], label=_("Action")) action = forms.ChoiceField(choices=[("BACK", _("Back")), ("ADD", _("Add")), ("DEL", _("Delete"))], initial="BACK",
token_type = forms.ChoiceField(choices=settings.SITH_LAUNDERETTE_MACHINE_TYPES, label=_("Type")) 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")) tokens = forms.CharField(max_length=512, widget=forms.widgets.Textarea, label=_("Tokens, separated by spaces"))
def process(self, launderette): def process(self, launderette):
cleaned_data = self.cleaned_data 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'] token_type = cleaned_data['token_type']
self.data = {} self.data = {}
if cleaned_data['action'] == "BACK": if cleaned_data['action'] == "BACK":
......
...@@ -32,7 +32,7 @@ ALLOWED_HOSTS = [] ...@@ -32,7 +32,7 @@ ALLOWED_HOSTS = []
# Application definition # Application definition
SITE_ID = 1 SITE_ID = 4000
INSTALLED_APPS = ( INSTALLED_APPS = (
'django.contrib.admin', 'django.contrib.admin',
...@@ -167,6 +167,8 @@ LOCALE_PATHS = ( ...@@ -167,6 +167,8 @@ LOCALE_PATHS = (
os.path.join(BASE_DIR, "locale"), os.path.join(BASE_DIR, "locale"),
) )
PHONENUMBER_DEFAULT_REGION = "FR"
# Medias # Medias
MEDIA_ROOT = './data/' MEDIA_ROOT = './data/'
MEDIA_URL = '/data/' MEDIA_URL = '/data/'
...@@ -189,6 +191,9 @@ DEFAULT_FROM_EMAIL="bibou@git.an" ...@@ -189,6 +191,9 @@ DEFAULT_FROM_EMAIL="bibou@git.an"
EMAIL_HOST="localhost" EMAIL_HOST="localhost"
EMAIL_PORT=25 EMAIL_PORT=25
SITH_URL = "ae-taiste.utbm.fr"
SITH_NAME = "AE taiste"
# AE configuration # AE configuration
SITH_MAIN_CLUB = { SITH_MAIN_CLUB = {
'name': "AE", 'name': "AE",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment