Fin de l'ajout du champ category
This commit is contained in:
parent
de6d3be052
commit
78a473b468
6 changed files with 90 additions and 32 deletions
|
@ -4,9 +4,9 @@ import os
|
|||
import Ernestophone.settings
|
||||
|
||||
PARTITION_TYPES = (
|
||||
("active", "Actif"),
|
||||
("incoming", "À venir"),
|
||||
("old", "Archive")
|
||||
("active", "Actif"),
|
||||
("incoming", "À venir"),
|
||||
("old", "Archive"),
|
||||
)
|
||||
|
||||
class Partition(models.Model):
|
||||
|
@ -28,5 +28,9 @@ class PartitionSet(models.Model):
|
|||
choices=PARTITION_TYPES, default="incoming")
|
||||
|
||||
def __str__(self):
|
||||
return("%s - %s [%s]" % (self.nom, self.auteur, self.category))
|
||||
return("%s - %s [%s]" % (self.nom, self.auteur,
|
||||
self.get_category_display()))
|
||||
|
||||
def get_category(self):
|
||||
return
|
||||
|
||||
|
|
|
@ -10,5 +10,7 @@ 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'),
|
||||
)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from django.shortcuts import render, redirect, HttpResponse, render_to_response
|
||||
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
|
||||
|
||||
|
@ -6,14 +7,14 @@ import os
|
|||
|
||||
|
||||
from partitions.forms import UploadFileForm, UploadMorceauForm
|
||||
from partitions.models import Partition, PartitionSet
|
||||
from partitions.models import Partition, PartitionSet, PARTITION_TYPES
|
||||
from partitions.decorators import chef_required
|
||||
|
||||
def liste(request):
|
||||
partitions = PartitionSet.objects.order_by("nom")
|
||||
context = {
|
||||
"request": request,
|
||||
"active_partitions": partitions.filter(category="old").all(),
|
||||
"active_partitions": partitions.filter(category="active").all(),
|
||||
"incoming_partitions": partitions.filter(category="incoming").all(),
|
||||
"old_partitions": partitions.filter(category="old").all()
|
||||
}
|
||||
|
@ -98,7 +99,6 @@ def ajouter_morceau(request):
|
|||
else:
|
||||
form = UploadMorceauForm()
|
||||
return render(request, 'partitions/new.html', locals())
|
||||
# Create your views here.
|
||||
|
||||
@chef_required
|
||||
def delete(request, nom, auteur, id):
|
||||
|
@ -135,3 +135,19 @@ def listepart(request, nom, 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)
|
||||
|
||||
|
||||
|
|
|
@ -190,3 +190,18 @@ form p {
|
|||
#doodle table {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.hbuttonlist {
|
||||
text-align: center;
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
.hbuttonlist li {
|
||||
display: inline-block;
|
||||
margin-left: 5px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
#category-change {
|
||||
text-align: center;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
{% endif %}
|
||||
|
||||
|
||||
<h3>Partitions actuelles</h3>
|
||||
<h3>Partitions actives</h3>
|
||||
{% for part in active_partitions %}
|
||||
<ul class="filelist">
|
||||
{% include "partitions/liste_item.html" with part=part %}
|
||||
|
|
|
@ -1,27 +1,48 @@
|
|||
{% extends "base.html" %}
|
||||
{% load urls_extra %}
|
||||
{% block titre %}{{ nom }}-{{ auteur }}{% endblock %}
|
||||
|
||||
{% block titre %}{{ p }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{{ p.nom }} - {{ p.auteur }}</h1>
|
||||
{% if suppression %}
|
||||
<p>{{ suppression }}</p>
|
||||
{% endif %}
|
||||
<ul class="filelist">
|
||||
{% for p in part %}
|
||||
{% if user.is_authenticated and ".pdf" in p.part.url %}
|
||||
<li><a href="{% url "partitions.views.see" nom auteur p.part.url|cuturl %}" class="fichier">{{ p.nom }}</a>
|
||||
{% elif user.is_authenticated and ".mp3" in p.part.url %}
|
||||
<li><a href="{% url "partitions.views.see" nom auteur p.part.url|cuturl %}" class="fichier">{{ p.nom }}</a>
|
||||
{% else %}<li>{{ p.nom }}
|
||||
{% endif %}
|
||||
{% if user.is_authenticated %}<a href="{% url "partitions.views.download" nom auteur p.part.url|cuturl %}" class="telecharger">Télécharger</a>{% endif %}
|
||||
{% if user.profile.is_chef %}
|
||||
<a href="{% url "partitions.views.conf_delete" nom auteur p.pk %}" class="supprimer">Supprimer</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% empty %}
|
||||
<p> Pas de partitions pour le moment </p>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<p><a href="{% url "partitions.views.upload" p.nom p.auteur %}">Ajouter un média</a></p>
|
||||
<h1>{{ p }}</h1>
|
||||
|
||||
{% if suppression %}
|
||||
<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>
|
||||
|
||||
|
||||
<ul class="filelist">
|
||||
{% for p in part %}
|
||||
{% if user.is_authenticated and ".pdf" in p.part.url %}
|
||||
<li><a href="{% url "partitions.views.see" nom auteur p.part.url|cuturl %}" class="fichier">{{ p.nom }}</a>
|
||||
{% elif user.is_authenticated and ".mp3" in p.part.url %}
|
||||
<li><a href="{% url "partitions.views.see" nom auteur p.part.url|cuturl %}" class="fichier">{{ p.nom }}</a>
|
||||
{% else %}
|
||||
<li>{{ p.nom }}
|
||||
{% endif %}
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
<a href="{% url "partitions.views.download" nom auteur p.part.url|cuturl %}" class="telecharger">Télécharger</a>
|
||||
{% endif %}
|
||||
|
||||
{% if user.profile.is_chef %}
|
||||
<a href="{% url "partitions.views.conf_delete" nom auteur p.pk %}" class="supprimer">Supprimer</a>
|
||||
{% endif %}
|
||||
|
||||
</li>
|
||||
{% empty %}
|
||||
<p> Pas de partitions pour le moment </p>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<p><a href="{% url "partitions.views.upload" p.nom p.auteur %}">Ajouter un média</a></p>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue