Ajout des infos utiles dans les PartitionSet
- On utilise désormais un formulaire pour changer la categorie et let infos utiles d'une partition. - Pas de CSS : à faire
This commit is contained in:
parent
78a473b468
commit
99a77851d1
6 changed files with 31 additions and 42 deletions
|
@ -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'),
|
field=models.CharField(choices=[('active', 'Actif'), ('incoming', 'À venir'), ('old', 'Archive')], max_length=8, verbose_name='Types de partitions', default='incoming'),
|
||||||
preserve_default=True,
|
preserve_default=True,
|
||||||
),
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='partitionset',
|
||||||
|
name='infos',
|
||||||
|
field=models.TextField(null=True, verbose_name='Infos utiles'),
|
||||||
|
preserve_default=True,
|
||||||
|
),
|
||||||
]
|
]
|
|
@ -26,6 +26,7 @@ class PartitionSet(models.Model):
|
||||||
auteur = models.CharField(max_length=100)
|
auteur = models.CharField(max_length=100)
|
||||||
category = models.CharField('Types de partitions', max_length=8,
|
category = models.CharField('Types de partitions', max_length=8,
|
||||||
choices=PARTITION_TYPES, default="incoming")
|
choices=PARTITION_TYPES, default="incoming")
|
||||||
|
infos = models.TextField("Infos utiles", null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return("%s - %s [%s]" % (self.nom, self.auteur,
|
return("%s - %s [%s]" % (self.nom, self.auteur,
|
||||||
|
|
|
@ -10,7 +10,5 @@ urlpatterns = patterns('partitions.views',
|
||||||
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/(?P<file_name>[^/]+)/$', 'download'),
|
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/(?P<file_name>[^/]+)/$', 'download'),
|
||||||
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/(?P<id>[^/]+)/delete/?$', 'delete'),
|
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/(?P<id>[^/]+)/delete/?$', 'delete'),
|
||||||
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/(?P<id>[^/]+)/conf/?$', 'conf_delete'),
|
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/(?P<id>[^/]+)/conf/?$', 'conf_delete'),
|
||||||
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/(?P<categorie>[a-z]+)/change-category/?$',
|
|
||||||
'change_category'),
|
|
||||||
url(r'^new/?$', 'ajouter_morceau'),
|
url(r'^new/?$', 'ajouter_morceau'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,6 +2,7 @@ from django.shortcuts import render, redirect, HttpResponse, render_to_response,
|
||||||
get_object_or_404
|
get_object_or_404
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.encoding import smart_str
|
from django.utils.encoding import smart_str
|
||||||
|
from django.forms.models import modelform_factory
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -133,21 +134,12 @@ def conf_delete_morc(request, nom, auteur):
|
||||||
def listepart(request, nom, auteur):
|
def listepart(request, nom, auteur):
|
||||||
p = PartitionSet.objects.get(nom=nom, auteur=auteur)
|
p = PartitionSet.objects.get(nom=nom, auteur=auteur)
|
||||||
part = p.partition_set.all()
|
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())
|
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)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -191,17 +191,6 @@ form p {
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hbuttonlist {
|
#chef-edit-div {
|
||||||
text-align: center;
|
|
||||||
padding-left: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hbuttonlist li {
|
|
||||||
display: inline-block;
|
|
||||||
margin-left: 5px;
|
|
||||||
margin-right: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#category-change {
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,15 +10,18 @@
|
||||||
<p>{{ suppression }}</p>
|
<p>{{ suppression }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div id="category-change">
|
{% if user.profile.is_chef %}
|
||||||
<h4>Changer de catégorie ?</h4>
|
<form action="{% url "partitions.views.listepart" nom auteur %}" id="chef-edit-form" method="post">
|
||||||
<ul class="hbuttonlist">
|
{% csrf_token %}
|
||||||
<li><a href="{% url "partitions.views.change_category" nom auteur "active" %}">Actuel</a></li>
|
{{ form.as_p }}
|
||||||
<li><a href="{% url "partitions.views.change_category" nom auteur "incoming" %}">À venir</a></li>
|
<input type="submit" value="Enregister" />
|
||||||
<li><a href="{% url "partitions.views.change_category" nom auteur "old" %} ">Archives</a></li>
|
</form>
|
||||||
</ul>
|
{% else %}
|
||||||
</div>
|
{% if p.infos %}
|
||||||
|
<h4>Infos utiles</h4>
|
||||||
|
<p>{{ p.infos }}</p>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<ul class="filelist">
|
<ul class="filelist">
|
||||||
{% for p in part %}
|
{% for p in part %}
|
||||||
|
|
Loading…
Reference in a new issue