diff --git a/partitions/models.py b/partitions/models.py index 82fa4f2..18ac967 100644 --- a/partitions/models.py +++ b/partitions/models.py @@ -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 diff --git a/partitions/urls.py b/partitions/urls.py index 092c8d3..c10c948 100644 --- a/partitions/urls.py +++ b/partitions/urls.py @@ -10,5 +10,7 @@ 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 609b64f..de76334 100644 --- a/partitions/views.py +++ b/partitions/views.py @@ -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) + + diff --git a/static/css/ernesto.css b/static/css/ernesto.css index ee8a2a8..d552759 100644 --- a/static/css/ernesto.css +++ b/static/css/ernesto.css @@ -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; +} diff --git a/templates/partitions/liste.html b/templates/partitions/liste.html index e58248b..c46415a 100644 --- a/templates/partitions/liste.html +++ b/templates/partitions/liste.html @@ -12,7 +12,7 @@ {% endif %} -

Partitions actuelles

+

Partitions actives

{% for part in active_partitions %}
    {% include "partitions/liste_item.html" with part=part %} diff --git a/templates/partitions/listepart.html b/templates/partitions/listepart.html index c1f0823..f5ee9ab 100644 --- a/templates/partitions/listepart.html +++ b/templates/partitions/listepart.html @@ -1,27 +1,48 @@ {% extends "base.html" %} {% load urls_extra %} -{% block titre %}{{ nom }}-{{ auteur }}{% endblock %} + +{% block titre %}{{ p }}{% endblock %} + {% block content %} -

    {{ p.nom }} - {{ p.auteur }}

    -{% if suppression %} -

    {{ suppression }}

    -{% endif %} -
      -{% for p in part %} -{% if user.is_authenticated and ".pdf" in p.part.url %} -
    • {{ p.nom }} -{% elif user.is_authenticated and ".mp3" in p.part.url %} -
    • {{ p.nom }} -{% else %}
    • {{ p.nom }} -{% endif %} -{% if user.is_authenticated %}Télécharger{% endif %} -{% if user.profile.is_chef %} -Supprimer -{% endif %} -
    • -{% empty %} -

      Pas de partitions pour le moment

      -{% endfor %} -
    -

    Ajouter un média

    +

    {{ p }}

    + + {% if suppression %} +

    {{ suppression }}

    + {% endif %} + +
    +

    Changer de catégorie ?

    + +
    + + +
      + {% for p in part %} + {% if user.is_authenticated and ".pdf" in p.part.url %} +
    • {{ p.nom }} + {% elif user.is_authenticated and ".mp3" in p.part.url %} +
    • {{ p.nom }} + {% else %} +
    • {{ p.nom }} + {% endif %} + + {% if user.is_authenticated %} + Télécharger + {% endif %} + + {% if user.profile.is_chef %} + Supprimer + {% endif %} + +
    • + {% empty %} +

      Pas de partitions pour le moment

      + {% endfor %} +
    + +

    Ajouter un média

    {% endblock %}