diff --git a/core/management/commands/populate.py b/core/management/commands/populate.py index 2cf0bbeb..25b21c63 100644 --- a/core/management/commands/populate.py +++ b/core/management/commands/populate.py @@ -44,6 +44,10 @@ class Command(BaseCommand): bar_club = Club(name=settings.SITH_BAR_MANAGER['name'], unix_name=settings.SITH_BAR_MANAGER['unix_name'], address=settings.SITH_BAR_MANAGER['address']) bar_club.save() + launderette_club = Club(name=settings.SITH_LAUNDERETTE_MANAGER['name'], + unix_name=settings.SITH_LAUNDERETTE_MANAGER['unix_name'], + address=settings.SITH_LAUNDERETTE_MANAGER['address']) + launderette_club.save() for b in settings.SITH_COUNTER_BARS: g = Group(name=b[1]+" admin") g.save() @@ -63,6 +67,12 @@ class Command(BaseCommand): Welcome to the wiki page! """).save() + p = Page(name="launderette") + p.set_lock(root) + p.save() + p.set_lock(root) + PageRev(page=p, title="", author=root, content="").save() + # Here we add a lot of test datas, that are not necessary for the Sith, but that provide a basic development environment if not options['prod']: # Adding user Skia diff --git a/core/views/page.py b/core/views/page.py index fc164047..b8d91bf1 100644 --- a/core/views/page.py +++ b/core/views/page.py @@ -86,7 +86,6 @@ class PageCreateView(CanEditPropMixin, CreateView): def get_context_data(self, **kwargs): context = super(PageCreateView, self).get_context_data(**kwargs) - print(context) context['new_page'] = True return context diff --git a/counter/migrations/0011_counter_sellers.py b/counter/migrations/0011_counter_sellers.py new file mode 100644 index 00000000..bbba821a --- /dev/null +++ b/counter/migrations/0011_counter_sellers.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('subscription', '0002_auto_20160718_1805'), + ('counter', '0010_auto_20160728_1820'), + ] + + operations = [ + migrations.AddField( + model_name='counter', + name='sellers', + field=models.ManyToManyField(verbose_name='sellers', to='subscription.Subscriber', related_name='counters', blank=True), + ), + ] diff --git a/counter/models.py b/counter/models.py index 18196aa4..ad556bd3 100644 --- a/counter/models.py +++ b/counter/models.py @@ -10,6 +10,8 @@ from random import randrange from club.models import Club from accounting.models import CurrencyField from core.models import Group, User +from subscription.models import Subscriber +from subscription.views import get_subscriber class Customer(models.Model): """ @@ -94,6 +96,7 @@ class Counter(models.Model): type = models.CharField(_('subscription type'), max_length=255, choices=[('BAR',_('Bar')), ('OFFICE',_('Office')), ('EBOUTIC',_('Eboutic'))]) + sellers = models.ManyToManyField(Subscriber, verbose_name=_('sellers'), related_name='counters', blank=True) edit_groups = models.ManyToManyField(Group, related_name="editable_counters", blank=True) view_groups = models.ManyToManyField(Group, related_name="viewable_counters", blank=True) barmen_session = {} @@ -102,8 +105,8 @@ class Counter(models.Model): verbose_name = _('counter') def __getattribute__(self, name): - if name == "owner_group": - return Group.objects.filter(name=self.club.unix_name+settings.SITH_BOARD_SUFFIX).first() + if name == "edit_groups": + return Group.objects.filter(name=self.club.unix_name+settings.SITH_BOARD_SUFFIX).all() return object.__getattribute__(self, name) def __str__(self): @@ -114,11 +117,14 @@ class Counter(models.Model): return reverse('eboutic:main') return reverse('counter:details', kwargs={'counter_id': self.id}) - def can_be_edited_by(self, user): + def is_owned_by(self, user): return user.is_in_group(settings.SITH_GROUPS['counter-admin']['name']) def can_be_viewed_by(self, user): - return user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) + if self.type == "BAR" or self.type == "EBOUTIC": + return True + sub = get_subscriber(request.user) + return user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or sub in self.sellers def add_barman(counter_id, user_id): """ diff --git a/counter/templates/counter/counter_click.jinja b/counter/templates/counter/counter_click.jinja index 317a1b36..36e2cb46 100644 --- a/counter/templates/counter/counter_click.jinja +++ b/counter/templates/counter/counter_click.jinja @@ -16,6 +16,10 @@ {% endmacro %} +{% block title %} +{{ counter }} +{% endblock %} + {% block content %}

{% trans %}Counter{% endtrans %}

{{ counter }}

diff --git a/counter/templates/counter/counter_main.jinja b/counter/templates/counter/counter_main.jinja index 1dcbd143..16e05c27 100644 --- a/counter/templates/counter/counter_main.jinja +++ b/counter/templates/counter/counter_main.jinja @@ -25,7 +25,7 @@ {% endif %} {% if barmen %}

{% trans %}Enter client code:{% endtrans %}

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

diff --git a/counter/views.py b/counter/views.py index f5ae2daa..f0fbebcf 100644 --- a/counter/views.py +++ b/counter/views.py @@ -322,7 +322,7 @@ class CounterListView(CanViewMixin, ListView): model = Counter template_name = 'counter/counter_list.jinja' -class CounterEditView(CanEditMixin, UpdateView): +class CounterEditView(CanEditPropMixin, UpdateView): """ Edit a counter's main informations (for the counter's admin) """ @@ -352,7 +352,7 @@ class CounterDeleteView(CanEditMixin, DeleteView): # Product management -class ProductTypeListView(CanViewMixin, ListView): +class ProductTypeListView(CanEditPropMixin, ListView): """ A list view for the admins """ @@ -376,7 +376,7 @@ class ProductTypeEditView(CanEditPropMixin, UpdateView): fields = ['name', 'description', 'icon'] pk_url_kwarg = "type_id" -class ProductListView(CanViewMixin, ListView): +class ProductListView(CanEditPropMixin, ListView): """ A list view for the admins """ diff --git a/launderette/migrations/0005_auto_20160801_1634.py b/launderette/migrations/0005_auto_20160801_1634.py new file mode 100644 index 00000000..5ab0cf54 --- /dev/null +++ b/launderette/migrations/0005_auto_20160801_1634.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('counter', '0011_counter_sellers'), + ('subscription', '0002_auto_20160718_1805'), + ('launderette', '0004_token_start_date'), + ] + + operations = [ + migrations.AlterModelOptions( + name='slot', + options={'verbose_name': 'Slot', 'ordering': ['start_date']}, + ), + migrations.RemoveField( + model_name='launderette', + name='sellers', + ), + migrations.AddField( + model_name='launderette', + name='counter', + field=models.OneToOneField(related_name='launderette', default=1, verbose_name='counter', to='counter.Counter'), + preserve_default=False, + ), + migrations.AddField( + model_name='token', + name='borrow_date', + field=models.DateTimeField(null=True, verbose_name='borrow date'), + ), + migrations.AddField( + model_name='token', + name='user', + field=models.ForeignKey(related_name='tokens', default=1, verbose_name='user', to='subscription.Subscriber'), + preserve_default=False, + ), + migrations.AlterField( + model_name='token', + name='name', + field=models.CharField(max_length=5, verbose_name='name'), + ), + migrations.AlterUniqueTogether( + name='token', + unique_together=set([('name', 'launderette', 'type')]), + ), + migrations.RemoveField( + model_name='token', + name='start_date', + ), + ] diff --git a/launderette/models.py b/launderette/models.py index 741df23f..4a9b3d33 100644 --- a/launderette/models.py +++ b/launderette/models.py @@ -4,13 +4,15 @@ from django.conf import settings from django.core.urlresolvers import reverse from core.models import User +from counter.models import Counter from subscription.models import Subscriber +from subscription.views import get_subscriber # Create your models here. class Launderette(models.Model): name = models.CharField(_('name'), max_length=30) - sellers = models.ManyToManyField(Subscriber, verbose_name=_('sellers'), related_name='launderettes', blank=True) + counter = models.OneToOneField(Counter, verbose_name=_('counter'), related_name='launderette') class Meta: verbose_name = _('Launderette') @@ -23,6 +25,10 @@ class Launderette(models.Model): return True return False + def can_be_edited_by(self, user): + sub = get_subscriber(request.user) + return sub in self.sellers.all() + def can_be_viewed_by(self, user): return user.is_in_group(settings.SITH_MAIN_MEMBERS_GROUP) @@ -56,13 +62,15 @@ class Machine(models.Model): return reverse('launderette:launderette_details', kwargs={"launderette_id": self.launderette.id}) class Token(models.Model): - name = models.IntegerField(_('name')) + name = models.CharField(_('name'), max_length=5) launderette = models.ForeignKey(Launderette, related_name='tokens', verbose_name=_('launderette')) type = models.CharField(_('type'), max_length=10, choices=[('WASHING', _('Washing')), ('DRYING', _('Drying'))]) - start_date = models.DateTimeField(_('start date')) + borrow_date = models.DateTimeField(_('borrow date'), null=True) + user = models.ForeignKey(Subscriber, related_name='tokens', verbose_name=_('user')) class Meta: verbose_name = _('Token') + unique_together = ('name', 'launderette', 'type') def is_owned_by(self, user): """ @@ -81,6 +89,7 @@ class Slot(models.Model): class Meta: verbose_name = _('Slot') + ordering = ['start_date'] def full_clean(self): return super(Slot, self).full_clean() diff --git a/launderette/templates/launderette/launderette_click.jinja b/launderette/templates/launderette/launderette_click.jinja new file mode 100644 index 00000000..810c70d0 --- /dev/null +++ b/launderette/templates/launderette/launderette_click.jinja @@ -0,0 +1,17 @@ +{% extends "core/base.jinja" %} + +{% block title %} +{{ counter }} +{% endblock %} + +{% block content %} +

{% trans counter_name=counter %}{{ counter_name }} counter{% endtrans %}

+
+ Counter: {{ counter }} + + {% csrf_token %} + {{ form.as_p() }} +

+ +
+{% endblock %} diff --git a/launderette/templates/launderette/launderette_detail.jinja b/launderette/templates/launderette/launderette_detail.jinja index b94c018b..becfdb96 100644 --- a/launderette/templates/launderette/launderette_detail.jinja +++ b/launderette/templates/launderette/launderette_detail.jinja @@ -5,6 +5,15 @@ {% endblock %} {% block content %} +

{% trans %}Selling{% endtrans %}

+

{% trans %}Sell{% endtrans %}

+

{% trans %}Tokens{% endtrans %}

+ +

{% trans %}Machines{% endtrans %}

{% trans %}New machine{% endtrans %}