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
|
import Ernestophone.settings
|
||||||
|
|
||||||
PARTITION_TYPES = (
|
PARTITION_TYPES = (
|
||||||
("active", "Actif"),
|
("active", "Actif"),
|
||||||
("incoming", "À venir"),
|
("incoming", "À venir"),
|
||||||
("old", "Archive")
|
("old", "Archive"),
|
||||||
)
|
)
|
||||||
|
|
||||||
class Partition(models.Model):
|
class Partition(models.Model):
|
||||||
|
@ -28,5 +28,9 @@ class PartitionSet(models.Model):
|
||||||
choices=PARTITION_TYPES, default="incoming")
|
choices=PARTITION_TYPES, default="incoming")
|
||||||
|
|
||||||
def __str__(self):
|
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<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'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -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.contrib.auth.decorators import login_required
|
||||||
from django.utils.encoding import smart_str
|
from django.utils.encoding import smart_str
|
||||||
|
|
||||||
|
@ -6,14 +7,14 @@ import os
|
||||||
|
|
||||||
|
|
||||||
from partitions.forms import UploadFileForm, UploadMorceauForm
|
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
|
from partitions.decorators import chef_required
|
||||||
|
|
||||||
def liste(request):
|
def liste(request):
|
||||||
partitions = PartitionSet.objects.order_by("nom")
|
partitions = PartitionSet.objects.order_by("nom")
|
||||||
context = {
|
context = {
|
||||||
"request": request,
|
"request": request,
|
||||||
"active_partitions": partitions.filter(category="old").all(),
|
"active_partitions": partitions.filter(category="active").all(),
|
||||||
"incoming_partitions": partitions.filter(category="incoming").all(),
|
"incoming_partitions": partitions.filter(category="incoming").all(),
|
||||||
"old_partitions": partitions.filter(category="old").all()
|
"old_partitions": partitions.filter(category="old").all()
|
||||||
}
|
}
|
||||||
|
@ -98,7 +99,6 @@ def ajouter_morceau(request):
|
||||||
else:
|
else:
|
||||||
form = UploadMorceauForm()
|
form = UploadMorceauForm()
|
||||||
return render(request, 'partitions/new.html', locals())
|
return render(request, 'partitions/new.html', locals())
|
||||||
# Create your views here.
|
|
||||||
|
|
||||||
@chef_required
|
@chef_required
|
||||||
def delete(request, nom, auteur, id):
|
def delete(request, nom, auteur, id):
|
||||||
|
@ -135,3 +135,19 @@ def listepart(request, nom, auteur):
|
||||||
part = p.partition_set.all()
|
part = p.partition_set.all()
|
||||||
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -190,3 +190,18 @@ form p {
|
||||||
#doodle table {
|
#doodle table {
|
||||||
margin-bottom: 10px;
|
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 %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
<h3>Partitions actuelles</h3>
|
<h3>Partitions actives</h3>
|
||||||
{% for part in active_partitions %}
|
{% for part in active_partitions %}
|
||||||
<ul class="filelist">
|
<ul class="filelist">
|
||||||
{% include "partitions/liste_item.html" with part=part %}
|
{% include "partitions/liste_item.html" with part=part %}
|
||||||
|
|
|
@ -1,27 +1,48 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load urls_extra %}
|
{% load urls_extra %}
|
||||||
{% block titre %}{{ nom }}-{{ auteur }}{% endblock %}
|
|
||||||
|
{% block titre %}{{ p }}{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{{ p.nom }} - {{ p.auteur }}</h1>
|
<h1>{{ p }}</h1>
|
||||||
{% if suppression %}
|
|
||||||
<p>{{ suppression }}</p>
|
{% if suppression %}
|
||||||
{% endif %}
|
<p>{{ suppression }}</p>
|
||||||
<ul class="filelist">
|
{% endif %}
|
||||||
{% for p in part %}
|
|
||||||
{% if user.is_authenticated and ".pdf" in p.part.url %}
|
<div id="category-change">
|
||||||
<li><a href="{% url "partitions.views.see" nom auteur p.part.url|cuturl %}" class="fichier">{{ p.nom }}</a>
|
<h4>Changer de catégorie ?</h4>
|
||||||
{% elif user.is_authenticated and ".mp3" in p.part.url %}
|
<ul class="hbuttonlist">
|
||||||
<li><a href="{% url "partitions.views.see" nom auteur p.part.url|cuturl %}" class="fichier">{{ p.nom }}</a>
|
<li><a href="{% url "partitions.views.change_category" nom auteur "active" %}">Actuel</a></li>
|
||||||
{% else %}<li>{{ p.nom }}
|
<li><a href="{% url "partitions.views.change_category" nom auteur "incoming" %}">À venir</a></li>
|
||||||
{% endif %}
|
<li><a href="{% url "partitions.views.change_category" nom auteur "old" %} ">Archives</a></li>
|
||||||
{% if user.is_authenticated %}<a href="{% url "partitions.views.download" nom auteur p.part.url|cuturl %}" class="telecharger">Télécharger</a>{% endif %}
|
</ul>
|
||||||
{% if user.profile.is_chef %}
|
</div>
|
||||||
<a href="{% url "partitions.views.conf_delete" nom auteur p.pk %}" class="supprimer">Supprimer</a>
|
|
||||||
{% endif %}
|
|
||||||
</li>
|
<ul class="filelist">
|
||||||
{% empty %}
|
{% for p in part %}
|
||||||
<p> Pas de partitions pour le moment </p>
|
{% if user.is_authenticated and ".pdf" in p.part.url %}
|
||||||
{% endfor %}
|
<li><a href="{% url "partitions.views.see" nom auteur p.part.url|cuturl %}" class="fichier">{{ p.nom }}</a>
|
||||||
</ul>
|
{% elif user.is_authenticated and ".mp3" in p.part.url %}
|
||||||
<p><a href="{% url "partitions.views.upload" p.nom p.auteur %}">Ajouter un média</a></p>
|
<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 %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue