Improve launderette rights to match with launderette club

This commit is contained in:
Skia 2016-08-13 16:39:09 +02:00
parent 4ec328556e
commit a033c4dfd2
9 changed files with 62 additions and 27 deletions

View File

@ -5,22 +5,21 @@
<p><a href="{{ url('club:club_view', club_id=object.id) }}">Back to club</a></p>
<ul>
{% if object.counters.all()|count > 0 %}
<li><h4>{% trans %}Counters:{% endtrans %}</h4>
<ul>
{% for c in object.counters.all() %}
<li>{{ c }}:
<a href="{{ url('counter:details', counter_id=c.id) }}">View</a>
<a href="{{ url('counter:admin', counter_id=c.id) }}">Edit</a>
</li>
{% endfor %}
</ul>
</li>
<h4>{% trans %}Counters:{% endtrans %}</h4>
<ul>
{% for c in object.counters.all() %}
<li>{{ c }}:
<a href="{{ url('counter:details', counter_id=c.id) }}">View</a>
<a href="{{ url('counter:admin', counter_id=c.id) }}">Edit</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% if object.club_account %}
<li>Accouting: <a href="{{ url('accounting:club_details', c_account_id=object.club_account.id) }}">{{ object }}</a></li>
{% endif %}
{% 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 %}
</ul>
{% endblock %}

View File

@ -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()

View File

@ -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{

View File

@ -16,10 +16,6 @@
{% 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>
{% 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>
<hr>

View File

@ -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

View File

@ -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

View File

@ -19,9 +19,19 @@
<hr>
<h3>{% trans %}Tokens{% endtrans %}</h3>
<p>
<form method="post" action="">
<form method="post" action="" id="token_form">
{% 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>
</form>
</p>

View File

@ -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":

View File

@ -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",