Commit 8b8e7a85 authored by Charlie Jacomme's avatar Charlie Jacomme

[club] Gestion des imprimeurs pour cableurs

parent 33fc3569
......@@ -11,7 +11,8 @@
<footer>
<div class="row">
<div class="six columns">
<a href="{% url 'club:index' %}" class="button-cancel">Retour à la liste des clubs</a>
<a href="{% if not cablage %}{% url 'club:index' %}
{% else %} {% url 'club:index' cid %}{% endif %}" class="button-cancel">Retour à la liste des clubs</a>
<input class="button-add" type="submit" value="Ajouter cet imprimeur">
</div>
</div>
......
......@@ -11,7 +11,8 @@
<footer>
<div class="row">
<div class="six columns">
<a href="{% url 'club:index' %}" class="button-cancel">Retour à la liste des clubs</a>
<a href="{% if not cablage %}{% url 'club:index' %}
{% else %} {% url 'club:index' cid %}{% endif %}" class="button-cancel">Retour à la liste des clubs</a>
<input class="button-del" type="submit" value="Retirer ces imprimeurs">
</div>
</div>
......
......@@ -17,9 +17,22 @@
</ul>
Responsable : {{club.responsable}}
<footer>
<a href="{% url 'club:imprimeur_add' cid=club.cid %}"><button class="button-add">Ajouter un imprimeur</button></a>
<a href="
{% if not cablage %}
{% url 'club:imprimeur_add' cid=club.cid %}
{% else %}
{% url 'club:imprimeur_add' cid=club.cid cablage='cablage'%}
{% endif %}
"><button class="button-add">Ajouter un imprimeur</button></a>
{% if club.imprimeurs %}
<a href="{% url 'club:imprimeur_del' cid=club.cid %}"><button class="button-del">Retirer un imprimeur</button></a>
<a href="
{% if not cablage %}
{% url 'club:imprimeur_del' cid=club.cid %}
{% else %}
{% url 'club:imprimeur_del' cid=club.cid cablage='cablage'%}
{% endif %}
"><button class="button-del">Retirer un imprimeur</button></a>
{% endif %}
</footer>
</div>
......
......@@ -7,4 +7,6 @@ urlpatterns = [
url('^liste/(?P<cid>[0-9]+)/$', views.IndexView.as_view(), name='index'),
url('^(?P<cid>[0-9]+)/imprimeur/ajouter$', views.ImprimeurAddView.as_view(), name='imprimeur_add'),
url('^(?P<cid>[0-9]+)/imprimeur/retirer$', views.ImprimeurDelView.as_view(), name='imprimeur_del'),
url('^(?P<cid>[0-9]+)/imprimeur/ajouter/(?P<cablage>cablage)$', views.ImprimeurAddView.as_view(), name='imprimeur_add'),
url('^(?P<cid>[0-9]+)/imprimeur/retirer/(?P<cablage>cablage)$', views.ImprimeurDelView.as_view(), name='imprimeur_del'),
]
......@@ -51,21 +51,31 @@ class IndexView(TemplateView):
def dispatch(self, *args, **kwargs):
return super(IndexView, self).dispatch(*args, **kwargs)
class ImprimeurView(FormView):
class EditClubView(FormView):
success_url = reverse_lazy('club:index')
def get_context_data(self, *args, **kwargs):
context = super(EditClubView, self).get_context_data(*args, **kwargs)
if 'cablage' in self.kwargs:
context.update({'cablage':True,'cid':self.cid})
return context
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
self.cid = int(self.kwargs['cid'])
for club_name, club in get_clubs_for_user(self.request.user):
if int(club['cid'][0]) == self.cid:
break
else: # Ce else est pour le for et non pour le if
messages.error(self.request, "Vous n'avez pas le droit de modifier ce club !")
return redirect('club:index')
return super(ImprimeurView, self).dispatch(*args, **kwargs)
class ImprimeurAddView(ImprimeurView):
if 'cablage' in self.kwargs:
self.success_url = reverse_lazy('club:index', args=[(self.cid)])
if not self.request.user.has_perm('auth.crans_cableur'):
for club_name, club in get_clubs_for_user(self.request.user):
if int(club['cid'][0]) == self.cid:
break
else: # Ce else est pour le for et non pour le if
messages.error(self.request, "Vous n'avez pas le droit de modifier ce club !")
return redirect('club:index')
return super(EditClubView, self).dispatch(*args, **kwargs)
class ImprimeurAddView(EditClubView):
template_name = 'club/imprimeur_add.html'
form_class = ImprimeurAddForm
......@@ -88,7 +98,7 @@ class ImprimeurAddView(ImprimeurView):
return redirect(self.request.path)
return super(ImprimeurAddView, self).form_valid(form)
class ImprimeurDelView(ImprimeurView):
class ImprimeurDelView(EditClubView):
template_name = 'club/imprimeur_del.html'
form_class = ImprimeurDelForm
......
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