mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 15:51:19 +00:00
Improve launderette plannings
This commit is contained in:
parent
a01fc63a82
commit
ef17e66351
@ -1,3 +1,9 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from launderette.models import *
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(Launderette)
|
||||
admin.site.register(Machine)
|
||||
admin.site.register(Token)
|
||||
admin.site.register(Slot)
|
||||
|
@ -1,47 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Launderette',
|
||||
fields=[
|
||||
('id', models.AutoField(serialize=False, auto_created=True, verbose_name='ID', primary_key=True)),
|
||||
('name', models.CharField(max_length=30, verbose_name='name')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Launderette',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Machine',
|
||||
fields=[
|
||||
('id', models.AutoField(serialize=False, auto_created=True, verbose_name='ID', primary_key=True)),
|
||||
('name', models.CharField(max_length=30, verbose_name='name')),
|
||||
('is_working', models.BooleanField(default=True, verbose_name='is working')),
|
||||
('launderette', models.ForeignKey(to='launderette.Launderette', related_name='machines', verbose_name='launderette')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Machine',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Token',
|
||||
fields=[
|
||||
('id', models.AutoField(serialize=False, auto_created=True, verbose_name='ID', primary_key=True)),
|
||||
('name', models.CharField(max_length=30, verbose_name='name')),
|
||||
('type', models.CharField(choices=[('WASHING', 'Washing'), ('DRYING', 'Drying')], max_length=10, verbose_name='type')),
|
||||
('launderette', models.ForeignKey(to='launderette.Launderette', related_name='tokens', verbose_name='launderette')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Token',
|
||||
},
|
||||
),
|
||||
]
|
@ -0,0 +1,66 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
replaces = [('launderette', '0001_initial'), ('launderette', '0002_auto_20160728_1858'), ('launderette', '0003_launderette_sellers'), ('launderette', '0004_auto_20160728_1922'), ('launderette', '0005_auto_20160729_0049'), ('launderette', '0006_auto_20160729_0050')]
|
||||
|
||||
dependencies = [
|
||||
('subscription', '0002_auto_20160718_1805'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Launderette',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, verbose_name='ID', primary_key=True, serialize=False)),
|
||||
('name', models.CharField(verbose_name='name', max_length=30)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Launderette',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Machine',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, verbose_name='ID', primary_key=True, serialize=False)),
|
||||
('name', models.CharField(verbose_name='name', max_length=30)),
|
||||
('is_working', models.BooleanField(verbose_name='is working', default=True)),
|
||||
('launderette', models.ForeignKey(related_name='machines', verbose_name='launderette', to='launderette.Launderette')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Machine',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Token',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, verbose_name='ID', primary_key=True, serialize=False)),
|
||||
('name', models.IntegerField(verbose_name='name')),
|
||||
('type', models.CharField(verbose_name='type', choices=[('WASHING', 'Washing'), ('DRYING', 'Drying')], max_length=10)),
|
||||
('launderette', models.ForeignKey(related_name='tokens', verbose_name='launderette', to='launderette.Launderette')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Token',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Slot',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, verbose_name='ID', primary_key=True, serialize=False)),
|
||||
('start_date', models.DateTimeField(verbose_name='start date')),
|
||||
('type', models.CharField(verbose_name='type', choices=[('WASHING', 'Washing'), ('DRYING', 'Drying')], max_length=10)),
|
||||
('machine', models.ForeignKey(related_name='slots', verbose_name='machine', to='launderette.Machine')),
|
||||
('token', models.ForeignKey(related_name='slots', null=True, verbose_name='token', blank=True, to='launderette.Token')),
|
||||
('user', models.ForeignKey(related_name='slots', verbose_name='user', to='subscription.Subscriber')),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='launderette',
|
||||
name='sellers',
|
||||
field=models.ManyToManyField(verbose_name='sellers', related_name='launderettes', blank=True, to='subscription.Subscriber'),
|
||||
),
|
||||
]
|
@ -1,39 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subscription', '0002_auto_20160718_1805'),
|
||||
('launderette', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Slot',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='ID', auto_created=True)),
|
||||
('start_date', models.DateTimeField(verbose_name='start date')),
|
||||
('type', models.CharField(max_length=10, verbose_name='type', choices=[('WASHING', 'Washing'), ('DRYING', 'Drying')])),
|
||||
('machine', models.ForeignKey(verbose_name='machine', related_name='slots', to='launderette.Machine')),
|
||||
],
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='token',
|
||||
name='name',
|
||||
field=models.IntegerField(verbose_name='name'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='slot',
|
||||
name='token',
|
||||
field=models.ForeignKey(verbose_name='token', related_name='slots', to='launderette.Token'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='slot',
|
||||
name='user',
|
||||
field=models.ForeignKey(verbose_name='user', related_name='slots', to='subscription.Subscriber'),
|
||||
),
|
||||
]
|
18
launderette/migrations/0002_auto_20160729_0138.py
Normal file
18
launderette/migrations/0002_auto_20160729_0138.py
Normal file
@ -0,0 +1,18 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('launderette', '0001_squashed_0006_auto_20160729_0050'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='slot',
|
||||
options={'verbose_name': 'Slot'},
|
||||
),
|
||||
]
|
@ -1,20 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subscription', '0002_auto_20160718_1805'),
|
||||
('launderette', '0002_auto_20160728_1858'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='launderette',
|
||||
name='sellers',
|
||||
field=models.ManyToManyField(to='subscription.Subscriber', verbose_name='sellers', related_name='launderettes'),
|
||||
),
|
||||
]
|
@ -1,19 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('launderette', '0003_launderette_sellers'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='launderette',
|
||||
name='sellers',
|
||||
field=models.ManyToManyField(blank=True, to='subscription.Subscriber', verbose_name='sellers', related_name='launderettes'),
|
||||
),
|
||||
]
|
@ -48,6 +48,9 @@ class Machine(models.Model):
|
||||
return True
|
||||
return False
|
||||
|
||||
def __str__(self):
|
||||
return "%s - Launderette: %s - Working: %s" % (self.name, self.launderette, self.is_working)
|
||||
|
||||
class Token(models.Model):
|
||||
name = models.IntegerField(_('name'))
|
||||
launderette = models.ForeignKey(Launderette, related_name='tokens', verbose_name=_('launderette'))
|
||||
@ -68,9 +71,16 @@ class Slot(models.Model):
|
||||
start_date = models.DateTimeField(_('start date'))
|
||||
type = models.CharField(_('type'), max_length=10, choices=[('WASHING', _('Washing')), ('DRYING', _('Drying'))])
|
||||
machine = models.ForeignKey(Machine, related_name='slots', verbose_name=_('machine'))
|
||||
token = models.ForeignKey(Token, related_name='slots', verbose_name=_('token'))
|
||||
token = models.ForeignKey(Token, related_name='slots', verbose_name=_('token'), blank=True, null=True)
|
||||
user = models.ForeignKey(Subscriber, related_name='slots', verbose_name=_('user'))
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Slot')
|
||||
|
||||
def full_clean(self):
|
||||
return super(Slot, self).full_clean()
|
||||
|
||||
def __str__(self):
|
||||
return str(self.user) + " - " + str(self.start_date)
|
||||
|
||||
|
||||
|
@ -4,13 +4,38 @@
|
||||
{% trans %}Launderette{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% macro choose(date) %}
|
||||
<form method="post" action="{{ url('launderette:book_slot', launderette_id=launderette.id) }}" class="inline" style="display:inline">
|
||||
{% csrf_token %}
|
||||
<button type="submit" name="slot" value="{{ localtime(date).isoformat() }}"> {% trans %}Choose{% endtrans %} </button>
|
||||
</form>
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
{% if request.user.is_in_group(settings.SITH_MAIN_MEMBERS_GROUP) %}
|
||||
<ul>
|
||||
{% for l in launderette_list %}
|
||||
<li><a href="{{ url('launderette:book_slot', launderette_id=l.id) }}">{{ l }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
{% for day in planning.keys() %}
|
||||
<th>{{ day|date('l') }}</th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for i in range(0, 24) %}
|
||||
<tr>
|
||||
{% for hours in planning.values() %}
|
||||
<td>
|
||||
{% if hours[i] %}
|
||||
{{ hours[i]|localtime|time(TIME_FORMAT) }} {{ choose(hours[i]) }}
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
@ -0,0 +1,21 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Launderette{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if request.user.is_in_group(settings.SITH_MAIN_MEMBERS_GROUP) %}
|
||||
<ul>
|
||||
{% for l in launderette_list %}
|
||||
<li><a href="{{ url('launderette:book_slot', launderette_id=l.id) }}">{{ l }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,14 +1,20 @@
|
||||
from datetime import datetime, timedelta
|
||||
from collections import OrderedDict
|
||||
|
||||
from django.shortcuts import render
|
||||
from django.views.generic import ListView, DetailView, RedirectView, TemplateView
|
||||
from django.views.generic.edit import UpdateView, CreateView, DeleteView, ProcessFormView, FormMixin
|
||||
from django.forms.models import modelform_factory
|
||||
from django.forms import CheckboxSelectMultiple
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.timezone import make_aware
|
||||
from django.utils import dateparse
|
||||
from django.conf import settings
|
||||
|
||||
from core.models import Page
|
||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin
|
||||
from launderette.models import Launderette, Token, Machine, Slot
|
||||
from subscription.views import get_subscriber
|
||||
|
||||
# For users
|
||||
|
||||
@ -25,14 +31,55 @@ class LaunderetteMainView(TemplateView):
|
||||
class LaunderetteBookMainView(CanViewMixin, ListView):
|
||||
"""Choose which launderette to book"""
|
||||
model = Launderette
|
||||
template_name = 'launderette/launderette_book.jinja'
|
||||
template_name = 'launderette/launderette_book_choose.jinja'
|
||||
|
||||
class LaunderetteBookView(TemplateView):
|
||||
class LaunderetteBookView(DetailView):
|
||||
"""Display the launderette schedule"""
|
||||
model = Launderette
|
||||
pk_url_kwarg = "launderette_id"
|
||||
template_name = 'launderette/launderette_book.jinja'
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
if 'slot' in request.POST.keys() and request.user.is_authenticated():
|
||||
subscriber = get_subscriber(request.user)
|
||||
if subscriber.is_subscribed():
|
||||
date = dateparse.parse_datetime(request.POST['slot'])
|
||||
for m in self.object.machines.filter(is_working=True).all():
|
||||
slot = Slot.objects.filter(start_date=date, machine=m).first()
|
||||
print(slot)
|
||||
if slot is None:
|
||||
Slot(user=subscriber, start_date=date, machine=m, type="WASHING").save()
|
||||
print("Saved")
|
||||
break
|
||||
return super(LaunderetteBookView, self).get(request, *args, **kwargs)
|
||||
|
||||
@staticmethod
|
||||
def date_iterator(startDate, endDate, delta=timedelta(days=1)):
|
||||
currentDate = startDate
|
||||
while currentDate < endDate:
|
||||
yield currentDate
|
||||
currentDate += delta
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
""" Add page to the context """
|
||||
kwargs = super(LaunderetteBookView, self).get_context_data(**kwargs)
|
||||
kwargs['planning'] = OrderedDict()
|
||||
start_date = make_aware(datetime.now().replace(hour=0, minute=0, second=0, microsecond=0))
|
||||
for date in LaunderetteBookView.date_iterator(start_date, start_date+timedelta(days=6), timedelta(days=1)):
|
||||
kwargs['planning'][date] = []
|
||||
for h in LaunderetteBookView.date_iterator(date, date+timedelta(days=1), timedelta(hours=1)):
|
||||
free = False
|
||||
for m in self.object.machines.filter(is_working=True).all():
|
||||
s = Slot.objects.filter(start_date=h, machine=m).first()
|
||||
if s is None:
|
||||
free = True
|
||||
if free and make_aware(datetime.now()) < h:
|
||||
kwargs['planning'][date].append(h)
|
||||
else:
|
||||
kwargs['planning'][date].append(None)
|
||||
print("Taken")
|
||||
return kwargs
|
||||
|
||||
# For admins
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user