diff --git a/partitions/migrations/0006_partitionset_category.py b/partitions/migrations/0006_partitionset_category_and_infos.py similarity index 72% rename from partitions/migrations/0006_partitionset_category.py rename to partitions/migrations/0006_partitionset_category_and_infos.py index 369aa6d..68c0756 100644 --- a/partitions/migrations/0006_partitionset_category.py +++ b/partitions/migrations/0006_partitionset_category_and_infos.py @@ -17,4 +17,10 @@ class Migration(migrations.Migration): field=models.CharField(choices=[('active', 'Actif'), ('incoming', 'À venir'), ('old', 'Archive')], max_length=8, verbose_name='Types de partitions', default='incoming'), preserve_default=True, ), + migrations.AddField( + model_name='partitionset', + name='infos', + field=models.TextField(null=True, verbose_name='Infos utiles'), + preserve_default=True, + ), ] diff --git a/partitions/models.py b/partitions/models.py index 18ac967..7b536e8 100644 --- a/partitions/models.py +++ b/partitions/models.py @@ -26,6 +26,7 @@ class PartitionSet(models.Model): auteur = models.CharField(max_length=100) category = models.CharField('Types de partitions', max_length=8, choices=PARTITION_TYPES, default="incoming") + infos = models.TextField("Infos utiles", null=True) def __str__(self): return("%s - %s [%s]" % (self.nom, self.auteur, diff --git a/partitions/urls.py b/partitions/urls.py index c10c948..092c8d3 100644 --- a/partitions/urls.py +++ b/partitions/urls.py @@ -10,7 +10,5 @@ urlpatterns = patterns('partitions.views', url(r'^(?P[^/]+)/(?P[^/]+)/(?P[^/]+)/$', 'download'), url(r'^(?P[^/]+)/(?P[^/]+)/(?P[^/]+)/delete/?$', 'delete'), url(r'^(?P[^/]+)/(?P[^/]+)/(?P[^/]+)/conf/?$', 'conf_delete'), - url(r'^(?P[^/]+)/(?P[^/]+)/(?P[a-z]+)/change-category/?$', - 'change_category'), url(r'^new/?$', 'ajouter_morceau'), ) diff --git a/partitions/views.py b/partitions/views.py index de76334..a1950b7 100644 --- a/partitions/views.py +++ b/partitions/views.py @@ -2,6 +2,7 @@ from django.shortcuts import render, redirect, HttpResponse, render_to_response, get_object_or_404 from django.contrib.auth.decorators import login_required from django.utils.encoding import smart_str +from django.forms.models import modelform_factory import os @@ -131,23 +132,14 @@ def conf_delete_morc(request, nom, auteur): @login_required def listepart(request, nom, auteur): - p = PartitionSet.objects.get(nom=nom, auteur=auteur) - part = p.partition_set.all() - return render(request, 'partitions/listepart.html', locals()) - -@chef_required -def change_category(request, nom, auteur, categorie): - part_set = get_object_or_404(PartitionSet, nom=nom, auteur=auteur) - part = part_set.partition_set.all() - context = { - 'nom': nom, - 'auteur': auteur, - 'p': part_set, - 'part': part, - } - if categorie in [id for (id, alias) in PARTITION_TYPES]: - part_set.category = categorie - part_set.save() - return render(request, 'partitions/listepart.html', context) - + p = PartitionSet.objects.get(nom=nom, auteur=auteur) + part = p.partition_set.all() + ChefEditForm = modelform_factory(PartitionSet, fields=("category", "infos")) + if request.method == "POST" and request.user.profile.is_chef: + form = ChefEditForm(request.POST, instance=p) + if form.is_valid(): + form.save() + else: + form = ChefEditForm(instance=p) + return render(request, 'partitions/listepart.html', locals()) diff --git a/static/css/ernesto.css b/static/css/ernesto.css index d552759..be94df8 100644 --- a/static/css/ernesto.css +++ b/static/css/ernesto.css @@ -191,17 +191,6 @@ form p { margin-bottom: 10px; } -.hbuttonlist { - text-align: center; - padding-left: 0; -} - -.hbuttonlist li { - display: inline-block; - margin-left: 5px; - margin-right: 5px; -} - -#category-change { +#chef-edit-div { text-align: center; } diff --git a/templates/partitions/listepart.html b/templates/partitions/listepart.html index f5ee9ab..d5989fb 100644 --- a/templates/partitions/listepart.html +++ b/templates/partitions/listepart.html @@ -10,15 +10,18 @@

{{ suppression }}

{% endif %} -
-

Changer de catégorie ?

- -
- + {% if user.profile.is_chef %} +
+ {% csrf_token %} + {{ form.as_p }} + +
+ {% else %} + {% if p.infos %} +

Infos utiles

+

{{ p.infos }}

+ {% endif %} + {% endif %}
    {% for p in part %}