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'),
|
||||
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)
|
||||
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,
|
||||
|
|
|
@ -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<id>[^/]+)/delete/?$', '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'),
|
||||
)
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -10,15 +10,18 @@
|
|||
<p>{{ suppression }}</p>
|
||||
{% endif %}
|
||||
|
||||
<div id="category-change">
|
||||
<h4>Changer de catégorie ?</h4>
|
||||
<ul class="hbuttonlist">
|
||||
<li><a href="{% url "partitions.views.change_category" nom auteur "active" %}">Actuel</a></li>
|
||||
<li><a href="{% url "partitions.views.change_category" nom auteur "incoming" %}">À venir</a></li>
|
||||
<li><a href="{% url "partitions.views.change_category" nom auteur "old" %} ">Archives</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{% if user.profile.is_chef %}
|
||||
<form action="{% url "partitions.views.listepart" nom auteur %}" id="chef-edit-form" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Enregister" />
|
||||
</form>
|
||||
{% else %}
|
||||
{% if p.infos %}
|
||||
<h4>Infos utiles</h4>
|
||||
<p>{{ p.infos }}</p>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<ul class="filelist">
|
||||
{% for p in part %}
|
||||
|
|
Loading…
Reference in a new issue