v1.0 - Nouvelle apparence, trombonoscope
This commit is contained in:
parent
95b748d23f
commit
05d274981b
182 changed files with 42538 additions and 8582 deletions
|
@ -1,9 +1,7 @@
|
|||
from django.contrib import admin
|
||||
from .models import Category
|
||||
|
||||
|
||||
@admin.register(Category)
|
||||
class CategoryAdmin(admin.ModelAdmin):
|
||||
list_display = ["name", "order"]
|
||||
list_editable = ["order"]
|
||||
ordering = ["order"]
|
||||
from .models import Category,PartitionSet
|
||||
|
||||
admin.site.register(Category)
|
||||
admin.site.register(PartitionSet)
|
||||
|
|
5
partitions/apps.py
Normal file
5
partitions/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class PartitionsConfig(AppConfig):
|
||||
name = 'partitions'
|
47
partitions/migrations/0003_auto_20200716_1749.py
Normal file
47
partitions/migrations/0003_auto_20200716_1749.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
# Generated by Django 2.2.14 on 2020-07-16 17:49
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.expressions
|
||||
import django.db.models.functions.text
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('partitions', '0002_category'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='category',
|
||||
options={'ordering': ('order',), 'verbose_name': 'Categorie', 'verbose_name_plural': 'Categories'},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='partition',
|
||||
options={'ordering': (django.db.models.expressions.CombinedExpression(django.db.models.expressions.Value('-'), '+', django.db.models.functions.text.Lower('nom')),), 'verbose_name': 'Morceau', 'verbose_name_plural': 'Morceaux'},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='partitionset',
|
||||
options={'ordering': (django.db.models.expressions.CombinedExpression(django.db.models.expressions.Value('-'), '+', django.db.models.functions.text.Lower('nom')),), 'verbose_name': 'Morceau', 'verbose_name_plural': 'Morceaux'},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='category',
|
||||
name='nom_en',
|
||||
field=models.CharField(blank=True, max_length=100, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='partitionset',
|
||||
name='infos_en',
|
||||
field=models.TextField(blank=True, null=True, verbose_name='Infos utiles en anglais'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='partitionset',
|
||||
name='url',
|
||||
field=models.URLField(blank=True, help_text='Dans Youtube cliquer sur partager puis importer pour récuperer la bonne adresse', null=True, verbose_name="Url d'une video youtube"),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='category',
|
||||
name='order',
|
||||
field=models.IntegerField(verbose_name='ordre'),
|
||||
),
|
||||
]
|
|
@ -2,18 +2,21 @@ import os
|
|||
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.db.models.functions import Lower
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class Category(models.Model):
|
||||
name = models.CharField(max_length=127)
|
||||
order = models.IntegerField(verbose_name="order")
|
||||
|
||||
order = models.IntegerField(verbose_name=_("ordre"))
|
||||
nom_en = models.CharField(max_length=100,null=True,blank=True)
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Meta:
|
||||
verbose_name = "catégorie"
|
||||
verbose_name_plural = "catégories"
|
||||
verbose_name = _("Categorie")
|
||||
verbose_name_plural = _("Categories")
|
||||
ordering = ('order',)
|
||||
|
||||
|
||||
class Partition(models.Model):
|
||||
|
@ -28,6 +31,11 @@ class Partition(models.Model):
|
|||
os.remove(os.path.join(settings.MEDIA_ROOT, self.part.name))
|
||||
super(Partition, self).delete(*args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Morceau')
|
||||
verbose_name_plural = _('Morceaux')
|
||||
ordering = ('-'+Lower('nom'),)
|
||||
|
||||
|
||||
class PartitionSet(models.Model):
|
||||
nom = models.CharField(max_length=100)
|
||||
|
@ -35,9 +43,15 @@ class PartitionSet(models.Model):
|
|||
category = models.ForeignKey(
|
||||
Category,
|
||||
on_delete=models.PROTECT,
|
||||
verbose_name="Type de partition"
|
||||
verbose_name=_("Type de partition")
|
||||
)
|
||||
infos = models.TextField("Infos utiles", null=True, blank=True)
|
||||
|
||||
infos = models.TextField(_("Infos utiles"), null=True, blank=True)
|
||||
infos_en = models.TextField("Infos utiles en anglais", null=True, blank=True)
|
||||
url = models.URLField(_("Url d'une video youtube"),null=True,blank=True, help_text= _("Dans Youtube cliquer sur partager puis importer pour récuperer la bonne adresse"))
|
||||
def __str__(self):
|
||||
return("%s - %s [%s]" % (self.nom, self.auteur, self.category))
|
||||
class Meta:
|
||||
verbose_name = _('Morceau')
|
||||
verbose_name_plural = _('Morceaux')
|
||||
ordering = ('-'+Lower('nom'),)
|
||||
|
|
BIN
partitions/static/images/all_repertoire.jpg
Executable file
BIN
partitions/static/images/all_repertoire.jpg
Executable file
Binary file not shown.
After Width: | Height: | Size: 341 KiB |
|
@ -1,7 +1,17 @@
|
|||
{% extends "gestion/base.html" %}
|
||||
{% block titre %}Confirmation de suppression{% endblock %}
|
||||
{% block content %}<h1>Confirmation de suppression</h1>
|
||||
<p>Voulez-vous vraiment supprimer cette partition ?</p>
|
||||
<p><a href="{% url "partitions:delete" nom auteur id %}">Oui</a></p>
|
||||
<p><a href="{% url "partitions:listepart" nom auteur %}">Retour à la liste des partitions</a></p>
|
||||
{% load i18n %}
|
||||
{% block titre %}{% trans "Confirmer supression" %}{% endblock %}
|
||||
{% block content %}
|
||||
<div id="main">
|
||||
<section class="wrapper style1">
|
||||
<div class="inner">
|
||||
|
||||
<h4>{% trans "Confirmation de suppression" %}</h4>
|
||||
<p>{% trans "Voulez-vous vraiment supprimer cette partition ?" %}"</p>
|
||||
<p><a href="{% url "partitions:delete" nom auteur id %}" class="button " >{% trans "Oui" %}</a></p>
|
||||
<p><a href="{% url "partitions:listepart" nom auteur %}" class="button alt" >{% trans "Retour à la liste des partitions" %}</a></p>
|
||||
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
{% extends "gestion/base.html" %}
|
||||
{% block titre %}Confirmation de suppression{% endblock %}
|
||||
{% block content %}<h1>Confirmation de suppression</h1>
|
||||
<p>Voulez-vous vraiment supprimer {{ nom }}-{{ auteur }} et toutes les partitions qu'il contient ?</p>
|
||||
<p><a href="{% url "partitions:delete_morc" nom auteur %}">Oui</a></p>
|
||||
<p><a href="{% url "partitions:list" %}">Retour à la liste des partitions</a></p>
|
||||
{% load i18n %}
|
||||
{% block titre %}{% trans "Confirmation de suppression" %}{% endblock %}
|
||||
{% block content %}
|
||||
<div id="main">
|
||||
<section class="wrapper style1">
|
||||
<div class="inner">
|
||||
<h4>{% trans "Confirmation de suppression :" %}</h4>
|
||||
<p>{% blocktrans with nom=nom auteur=auteur %}Voulez-vous vraiment supprimer {{ nom }}-{{ auteur }} et toutes les partitions qu'il contient ?{% endblocktrans %}</p>
|
||||
<p><a href="{% url "partitions:delete_morc" nom auteur %}" class="button">{% trans "Oui" %}</a></p>
|
||||
<p><a href="{% url "partitions:liste" %}" class="button alt">{% trans "Retour à la liste des partitions" %}</a></p>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,18 +1,32 @@
|
|||
{% extends "gestion/base.html" %}
|
||||
{% block titre %}Ajouter un morceau{% endblock %}
|
||||
{% block content %}<h1>Ajouter un morceau</h1>
|
||||
{% load i18n %}
|
||||
{% block titre %}{% trans "Ajouter un morceau" %}{% endblock %}
|
||||
{% block content %}
|
||||
<div id="main">
|
||||
<section class="wrapper style1">
|
||||
<div class="inner">
|
||||
|
||||
<h4>{% trans "Ajouter un morceau" %} :</h4>
|
||||
{% if sauvegarde %}
|
||||
<p>Morceau créé</p>
|
||||
<p>{% trans "Morceau créé" %}"</p>
|
||||
{% endif %}
|
||||
{% if error %}
|
||||
<p> {{ error }}</p>
|
||||
{% endif %}
|
||||
<p>
|
||||
<div class="row">
|
||||
<div class="6u 12u$(small)">
|
||||
<form method="post" action="">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Ajouter"/>
|
||||
<input type="submit" value="{% trans "Ajouter" %}"/>
|
||||
</form>
|
||||
</p>
|
||||
<p><a href="{% url 'partitions:list' %}">Retour à la liste</a></p>
|
||||
</div>
|
||||
</div>
|
||||
<p><a href="{% url 'partitions:liste' %}" class='button alt small'>{% trans "Retour à la liste" %}</a></p>
|
||||
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
116
partitions/templates/partitions/part.html
Normal file
116
partitions/templates/partitions/part.html
Normal file
|
@ -0,0 +1,116 @@
|
|||
{% extends "gestion/base.html" %}
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
{% block titre %}{{p}}{% endblock %}
|
||||
{% get_current_language as current_language %}
|
||||
{% load autotranslate %}
|
||||
{% block content %}
|
||||
|
||||
<!-- Main -->
|
||||
<div id="main">
|
||||
<section class="wrapper style1">
|
||||
<div class="inner">
|
||||
|
||||
|
||||
<h4>{{p.nom}} - {{p.auteur}} [{% autotranslate current_language p.category.name p.category.nom_en %}] :</h4>
|
||||
|
||||
{% if suppression %}
|
||||
<p>{{ suppression }}</p>
|
||||
{% endif %}
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="5u 12u$(small)">
|
||||
|
||||
<div class="table-wrapper">
|
||||
|
||||
<table class="default">
|
||||
<tbody>
|
||||
{% for p in part %}
|
||||
{% if user.is_authenticated and ".mscz" in p.part.url %}
|
||||
<td><p class="fichier">{{ p.nom }}</p></td>
|
||||
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
<td> <a href="{% url "partitions:download" nom auteur p.id %}" class="button icon fa-download">{% trans "Télécharger" %}</a></td>
|
||||
{% endif %}
|
||||
{% if user.profile.is_chef %} <td>
|
||||
<a href="{% url "partitions:conf_delete" nom auteur p.pk %}" class="button icon fa-deleate">{% trans "Supprimer" %}</a></td>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% for p in part %}
|
||||
{% if user.is_authenticated and not ".mscz" in p.part.url %}
|
||||
<tr>
|
||||
{% if user.is_authenticated and ".pdf" in p.part.url %}
|
||||
<td><a href="{% url "partitions:see" nom auteur p.id %}" class="fichier">{{ p.nom }}</a></td>
|
||||
{% elif user.is_authenticated and ".mp3" in p.part.url %}
|
||||
<td><a href="{% url "partitions:see" nom auteur p.id %}" class="fichier">{{ p.nom }}</a></td>
|
||||
|
||||
{% else %}
|
||||
<td><p class="fichier">{{ p.nom }}</p></td>
|
||||
{% endif %}
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
<td> <a href="{% url "partitions:download" nom auteur p.id %}" class="button icon fa-download">{% trans "Télécharger" %}</a></td>
|
||||
{% endif %}
|
||||
{% if user.profile.is_chef %} <td>
|
||||
<a href="{% url "partitions:conf_delete" nom auteur p.pk %}" class="button icon fa-deleate">{% trans "Supprimer" %}</a></td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% empty %}
|
||||
<p> {% blocktrans %}Pas de partitons pour le moment !{% endblocktrans %} </p>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% if user.profile.is_chef %}
|
||||
<p><a href="{% url "partitions:upload" p.nom p.auteur %}" class='button'>{% trans "Ajouter un média" %}</a></p>
|
||||
|
||||
{% if infos or infos_en %}
|
||||
|
||||
<h3>{% trans "Infos utiles :" %}</h3>
|
||||
|
||||
<div class="box">{% autotranslate current_language infos infos_en %}</div>
|
||||
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="1u 12u$(small)">
|
||||
<p></p>
|
||||
</div>
|
||||
<div class="6u 12u$(small)">
|
||||
{% if user.profile.is_chef %}
|
||||
<form action="{% url "partitions:listepart" nom auteur %}" id="chef-edit-form" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Enregister" />
|
||||
</form>
|
||||
{% else %}
|
||||
{% if infos or infos_en %}
|
||||
<h3>{% trans "Infos utiles :" %}</h3>
|
||||
<div class="box">{% autotranslate current_language infos infos_en %}</div>
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
{% if p.url %}
|
||||
<iframe width="560" height="315" src="{{p.url}}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<a href="{% url "partitions:liste" %}" class="button alt" >{% trans "Retour au répertoire" %}</a>
|
||||
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
99
partitions/templates/partitions/repertoire.html
Normal file
99
partitions/templates/partitions/repertoire.html
Normal file
|
@ -0,0 +1,99 @@
|
|||
{% extends "gestion/base.html" %}
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
{% load autotranslate %}
|
||||
{% load halflength %}
|
||||
{% block titre %}{% trans "L'Ernestophone : répertoire" %}{% endblock %}
|
||||
{% block content %}
|
||||
<div id="main">
|
||||
<section class="wrapper style1">
|
||||
<div class="inner">
|
||||
<span class="image fit"><img src="{% static 'images/all_repertoire.jpg' %}" alt="" /> <div style="position:absolute;z-index:1;right:0;bottom:0">
|
||||
<a href="" class="icon fa-copyright" style="color:#000000"> Lucas Gierzack</a>
|
||||
</div></span>
|
||||
{% if user.profile.is_chef %}
|
||||
<a href="{% url "partitions:ajouter_morceau" %}" class="button alt big">{% trans "Ajouter un morceau" %}</a>   <a href="{% url "partitions:download_musecores" %}" class="button alt big">{% trans "Télécharger tous les musecores actifs" %}</a>
|
||||
{% elif user.is_authenticated %}
|
||||
<a href="{% url "partitions:download_musecores" %}" class="button alt big">{% trans "Télécharger tous les musecores actifs" %}</a>
|
||||
{% endif %}
|
||||
<p></p>
|
||||
{% for o in some_list %}
|
||||
<tr class="{% cycle 'wrapper style1' 'wrapper style1' %}">
|
||||
...
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% for category in categories %}
|
||||
{%if not forloop.first %}
|
||||
|
||||
<section class="{% cycle 'wrapper style1' 'wrapper style2' %}">
|
||||
<div class="inner">
|
||||
{% endif %}
|
||||
<h4>{% autotranslate current_language category.name category.nom_en %} :</h4>
|
||||
<div class="row">
|
||||
<div class="6u 12u$(small)">
|
||||
<div class="table-wrapper">
|
||||
<table class="default">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "Morceau" %}</th>
|
||||
<th>{% trans "Compositeur" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% with rep=category.partitionset_set.all %}
|
||||
{% with rep_half_length=rep|half_length %}
|
||||
{% for partition in rep %}
|
||||
|
||||
{% if not user.is_authenticated %}
|
||||
<tr>
|
||||
<td> {{ partition.nom }} </td>
|
||||
<td> {{ partition.auteur }} </td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<td> <u><a href="{% url "partitions:listepart" partition.nom partition.auteur %}"
|
||||
class="fichier">{{ partition.nom }}</a> </td>
|
||||
<td> {{ partition.auteur }} </a></u> </td>
|
||||
{% if user.profile.is_chef %}<td>
|
||||
|
||||
<a href="{% url "partitions:conf_delete_morc" partition.nom partition.auteur %}"
|
||||
class="button small icon fa-trash">{% trans "Supprimer" %}</a></td>
|
||||
|
||||
{% endif %}
|
||||
|
||||
</tr>
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% if forloop.counter == rep_half_length %}
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="6u 12u$(small)">
|
||||
<div class="table-wrapper">
|
||||
<table class="default">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "Morceau" %}</th>
|
||||
<th>{% trans "Compositeur" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -1,19 +1,31 @@
|
|||
{% extends "gestion/base.html" %}
|
||||
{% block titre %}Ajouter une partition{% endblock %}
|
||||
{% block content %}<h1>Ajouter une partition</h1>
|
||||
{% load i18n %}
|
||||
{% block titre %}{% trans "Ajout de parties" %}{% endblock %}
|
||||
{% block content %}
|
||||
<div id="main">
|
||||
<section class="wrapper style1">
|
||||
<div class="inner">
|
||||
|
||||
<h4>{% trans "Ajouter une partition :" %} </h4>
|
||||
{% if sauvegarde %}
|
||||
<p>Partition enregistrée</p>
|
||||
{% endif %}
|
||||
{% if error %}
|
||||
<p>{{ error }}</p>
|
||||
{% endif %}
|
||||
<div class="row">
|
||||
<div class="6u 12u$(small)">
|
||||
<p>
|
||||
<form method ="post" enctype="multipart/form-data" action="{% url 'partitions:upload' nom auteur %}">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<p> <input type="submit" value="Enregistrer"/> </p>
|
||||
<p> <input type="submit" value="{% trans "Enregistrer"%}"/> </p>
|
||||
</form>
|
||||
</p>
|
||||
<p><a href="{% url "partitions:listepart" nom auteur %}">Retour aux partitions</a></p>
|
||||
|
||||
<p><a href="{% url "partitions:listepart" nom auteur %}" class="button alt">{% trans "Retour aux partitions" %}</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
3
partitions/tests.py
Normal file
3
partitions/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -2,16 +2,17 @@ from django.urls import path
|
|||
|
||||
from . import views
|
||||
|
||||
app_name = "partitions"
|
||||
app_name = 'partitions'
|
||||
urlpatterns = [
|
||||
path("", views.liste, name="list"),
|
||||
path("<str:nom>/<str:auteur>", views.listepart, name="listepart"),
|
||||
path('', views.liste, name='liste'),
|
||||
path('download', views.download_musecores, name='download_musecores'),
|
||||
path("<str:nom>/<str:auteur>/upload", views.upload, name="upload"),
|
||||
path("<str:nom>/<str:auteur>/delete", views.delete_morc, name="delete_morc"),
|
||||
path("<str:nom>/<str:auteur>/conf", views.conf_delete_morc, name="conf_delete_morc"),
|
||||
path("<str:nom>/<str:auteur>", views.listepart, name="listepart"),
|
||||
path("<str:nom>/<str:auteur>/see/<int:partition_id>", views.see, name="see"),
|
||||
path("<str:nom>/<str:auteur>/<int:partition_id>", views.download, name="download"),
|
||||
path("<str:nom>/<str:auteur>/<int:id>/delete", views.delete, name="delete"),
|
||||
path("<str:nom>/<str:auteur>/<int:id>/conf", views.conf_delete, name="conf_delete"),
|
||||
path("<str:nom>/<str:auteur>/<int:id>/delete", views.delete, name="delete"),
|
||||
path("<str:nom>/<str:auteur>/delete", views.delete_morc, name="delete_morc"),
|
||||
path("<str:nom>/<str:auteur>/conf", views.conf_delete_morc, name="conf_delete_morc"),
|
||||
path("new", views.ajouter_morceau, name="ajouter_morceau"),
|
||||
]
|
||||
|
|
|
@ -1,23 +1,75 @@
|
|||
from django.shortcuts import render, HttpResponse, get_object_or_404
|
||||
from django.shortcuts import render, HttpResponse, get_object_or_404, redirect, reverse
|
||||
from partitions.models import Category, Partition, PartitionSet
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.utils.encoding import smart_str
|
||||
from django.utils.text import slugify
|
||||
from django.forms.models import modelform_factory
|
||||
from django.core.files import File
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.http import Http404
|
||||
|
||||
import os
|
||||
|
||||
from partitions.forms import UploadFileForm, UploadMorceauForm
|
||||
from partitions.models import Partition, PartitionSet, Category
|
||||
from django.forms.models import modelform_factory
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.text import slugify
|
||||
from django.core.files import File
|
||||
from django.utils.encoding import smart_str
|
||||
from django.http import Http404
|
||||
from partitions.decorators import chef_required
|
||||
from django.conf import settings
|
||||
from django.db.models import Q
|
||||
import os
|
||||
import zipfile
|
||||
import io
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
def download_musecores(request):
|
||||
|
||||
p = Partition.objects.filter(Q(part__contains = ".mscz") & Q(Q(morceau__category__name = "Partitions actives" )|Q(morceau__category__name = "Partitions optionnelles" )))
|
||||
|
||||
|
||||
|
||||
zip_subdir = "Ernestophone_musescores"
|
||||
zip_filename = "%s.zip" % zip_subdir
|
||||
|
||||
# Open StringIO to grab in-memory ZIP contents
|
||||
s = io.BytesIO()
|
||||
|
||||
# The zip compressor
|
||||
zf = zipfile.ZipFile(s, "w")
|
||||
|
||||
for part in p :
|
||||
fpath = part.part.path
|
||||
|
||||
typ=".mscz"
|
||||
# Calculate path for file in zip
|
||||
fdir, fname = os.path.split(fpath)
|
||||
zip_path = os.path.join(zip_subdir, '%s_%s_%s.%s' % (
|
||||
slugify(part.morceau.nom), slugify(part.morceau.auteur), slugify(part.nom), typ))
|
||||
|
||||
# Add file, at correct path
|
||||
zf.write(fpath, zip_path)
|
||||
|
||||
# Must close zip for all contents to be written
|
||||
zf.close()
|
||||
# Grab ZIP file from in-memory, make response with correct MIME-type
|
||||
resp = HttpResponse(s.getvalue())
|
||||
# ..and correct content-disposition
|
||||
resp['Content-Disposition'] = 'attachment; filename=%s' % zip_filename
|
||||
|
||||
return resp
|
||||
|
||||
def liste(request):
|
||||
categories = Category.objects.prefetch_related("partitionset_set")
|
||||
return render(request, 'partitions/liste.html', {"categories": categories})
|
||||
categories = Category.objects.prefetch_related("partitionset_set").order_by("order")
|
||||
return render(request, 'partitions/repertoire.html', {"categories": categories})
|
||||
|
||||
@login_required
|
||||
def listepart(request, nom, auteur):
|
||||
p = get_object_or_404(PartitionSet, nom=nom, auteur=auteur)
|
||||
part = p.partition_set.all().order_by('nom')
|
||||
ChefEditForm = modelform_factory(PartitionSet,
|
||||
fields=("category", "infos","url","infos_en"))
|
||||
if request.method == "POST" and request.user.profile.is_chef:
|
||||
form = ChefEditForm(request.POST, instance=p)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
form = ChefEditForm(instance=p)
|
||||
infos = mark_safe(p.infos)
|
||||
infos_en = mark_safe(p.infos_en)
|
||||
return render(request, 'partitions/part.html', locals())
|
||||
|
||||
@login_required
|
||||
def upload(request, nom, auteur):
|
||||
|
@ -28,14 +80,14 @@ def upload(request, nom, auteur):
|
|||
partition.part = form.cleaned_data['file']
|
||||
partition.nom = form.cleaned_data['title']
|
||||
if '/' in partition.nom:
|
||||
error = "Le caractère / n'est pas autorisé dans le nom"
|
||||
error = _("Le caractère / n'est pas autorisé dans le nom")
|
||||
form = UploadFileForm()
|
||||
return render(request, "partitions/upload.html", locals())
|
||||
mor = get_object_or_404(PartitionSet, nom=nom, auteur=auteur)
|
||||
partition.morceau = mor
|
||||
try:
|
||||
mor.partition_set.get(nom=partition.nom)
|
||||
error = "Un morceau du même nom existe déjà"
|
||||
error = _("Un morceau du même nom existe déjà")
|
||||
except Partition.DoesNotExist:
|
||||
partition.save()
|
||||
sauvegarde = True
|
||||
|
@ -43,7 +95,6 @@ def upload(request, nom, auteur):
|
|||
form = UploadFileForm()
|
||||
return render(request, 'partitions/upload.html', locals())
|
||||
|
||||
|
||||
@login_required
|
||||
def see(request, nom, auteur, partition_id):
|
||||
partition = get_object_or_404(Partition, id=partition_id)
|
||||
|
@ -67,7 +118,75 @@ def see(request, nom, auteur, partition_id):
|
|||
else:
|
||||
p = get_object_or_404(PartitionSet, nom=nom, auteur=auteur)
|
||||
part = p.partition_set.all()
|
||||
return render(request, 'partitions/listepart.html', locals())
|
||||
return render(request, 'partitions/part.html', locals())
|
||||
@chef_required
|
||||
def delete(request, nom, auteur, id):
|
||||
p = get_object_or_404(PartitionSet, nom=nom, auteur=auteur)
|
||||
try:
|
||||
part = p.partition_set.get(id=id)
|
||||
except Partition.DoesNotExist:
|
||||
raise Http404
|
||||
part.delete()
|
||||
suppression = _("Partition supprimée")
|
||||
p.refresh_from_db()
|
||||
part = p.partition_set.all()
|
||||
return redirect('partitions:listepart',nom=nom,auteur=auteur)
|
||||
|
||||
@chef_required
|
||||
def ajouter_morceau(request):
|
||||
if request.method == "POST":
|
||||
form = UploadMorceauForm(request.POST)
|
||||
if form.is_valid():
|
||||
partitionset = PartitionSet()
|
||||
partitionset.nom = form.cleaned_data['titre']
|
||||
partitionset.auteur = form.cleaned_data['auteur']
|
||||
if '/' in partitionset.auteur or '/' in partitionset.nom:
|
||||
error = _("Le caractère / n'est pas autorisé")
|
||||
form = UploadMorceauForm()
|
||||
return render(request, 'partitions/new.html', locals())
|
||||
try:
|
||||
PartitionSet.objects.get(nom=partitionset.nom,
|
||||
auteur=partitionset.auteur)
|
||||
error = _("Un morceau du même nom existe déjà")
|
||||
except PartitionSet.DoesNotExist:
|
||||
# XXX. Hideous
|
||||
cat = Category.objects.first()
|
||||
try:
|
||||
cat = Category.objects.get(name="Partitions à venir")
|
||||
except Category.DoesNotExist:
|
||||
pass
|
||||
partitionset.category = cat
|
||||
partitionset.save()
|
||||
sauvegarde = True
|
||||
return redirect('partitions:liste')
|
||||
else:
|
||||
form = UploadMorceauForm()
|
||||
return render(request, 'partitions/new.html', locals())
|
||||
|
||||
|
||||
|
||||
|
||||
@chef_required
|
||||
def conf_delete(request, nom, auteur, id):
|
||||
part = get_object_or_404(Partition, id=id)
|
||||
return render(request, 'partitions/conf_delete.html', locals())
|
||||
|
||||
@chef_required
|
||||
def delete_morc(request, nom, auteur):
|
||||
p = get_object_or_404(PartitionSet, nom=nom, auteur=auteur)
|
||||
part = p.partition_set.all()
|
||||
for pa in part:
|
||||
pa.delete()
|
||||
p.delete()
|
||||
partitions = PartitionSet.objects.all()
|
||||
categories = Category.objects.prefetch_related("partitionset_set")
|
||||
return redirect('partitions:liste')
|
||||
|
||||
|
||||
@chef_required
|
||||
def conf_delete_morc(request, nom, auteur):
|
||||
return render(request, 'partitions/conf_delete_morc.html', locals())
|
||||
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -81,86 +200,3 @@ def download(request, nom, auteur, partition_id):
|
|||
response['Content-Disposition'] = 'attachment; filename=%s_%s_%s.%s' % (
|
||||
slugify(nom), slugify(auteur), slugify(partition.nom), typ)
|
||||
return response
|
||||
|
||||
|
||||
@login_required
|
||||
def ajouter_morceau(request):
|
||||
if request.method == "POST":
|
||||
form = UploadMorceauForm(request.POST)
|
||||
if form.is_valid():
|
||||
partitionset = PartitionSet()
|
||||
partitionset.nom = form.cleaned_data['titre']
|
||||
partitionset.auteur = form.cleaned_data['auteur']
|
||||
if '/' in partitionset.auteur or '/' in partitionset.nom:
|
||||
error = "Le caractère / n'est pas autorisé"
|
||||
form = UploadMorceauForm()
|
||||
return render(request, 'partitions/new.html', locals())
|
||||
try:
|
||||
PartitionSet.objects.get(nom=partitionset.nom,
|
||||
auteur=partitionset.auteur)
|
||||
error = "Un morceau du même nom existe déjà"
|
||||
except PartitionSet.DoesNotExist:
|
||||
# XXX. Hideous
|
||||
cat = Category.objects.first()
|
||||
try:
|
||||
cat = Category.objects.get(name="Partitions à venir")
|
||||
except Category.DoesNotExist:
|
||||
pass
|
||||
partitionset.category = cat
|
||||
partitionset.save()
|
||||
sauvegarde = True
|
||||
else:
|
||||
form = UploadMorceauForm()
|
||||
return render(request, 'partitions/new.html', locals())
|
||||
|
||||
|
||||
@chef_required
|
||||
def delete(request, nom, auteur, id):
|
||||
p = get_object_or_404(PartitionSet, nom=nom, auteur=auteur)
|
||||
try:
|
||||
part = p.partition_set.get(id=id)
|
||||
except Partition.DoesNotExist:
|
||||
raise Http404
|
||||
part.delete()
|
||||
suppression = "Partition supprimée"
|
||||
p.refresh_from_db()
|
||||
part = p.partition_set.all()
|
||||
return render(request, 'partitions/listepart.html', locals())
|
||||
|
||||
|
||||
@chef_required
|
||||
def conf_delete(request, nom, auteur, id):
|
||||
part = get_object_or_404(Partition, id=id)
|
||||
return render(request, 'partitions/conf_delete.html', locals())
|
||||
|
||||
|
||||
@chef_required
|
||||
def delete_morc(request, nom, auteur):
|
||||
p = get_object_or_404(PartitionSet, nom=nom, auteur=auteur)
|
||||
part = p.partition_set.all()
|
||||
for pa in part:
|
||||
pa.delete()
|
||||
p.delete()
|
||||
partitions = PartitionSet.objects.all()
|
||||
return render(request, "partitions/liste.html", locals())
|
||||
|
||||
|
||||
@chef_required
|
||||
def conf_delete_morc(request, nom, auteur):
|
||||
return render(request, 'partitions/conf_delete_morc.html', locals())
|
||||
|
||||
|
||||
@login_required
|
||||
def listepart(request, nom, auteur):
|
||||
p = get_object_or_404(PartitionSet, 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)
|
||||
infos = mark_safe(p.infos)
|
||||
return render(request, 'partitions/listepart.html', locals())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue