v1.1
This commit is contained in:
parent
7a7979c91a
commit
5d1d3f8eff
29 changed files with 756 additions and 138 deletions
37
partitions/migrations/0004_auto_20210331_1350.py
Normal file
37
partitions/migrations/0004_auto_20210331_1350.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
# Generated by Django 2.2.17 on 2021-03-31 13:50
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.functions.text
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('partitions', '0003_auto_20200716_1749'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='partition',
|
||||
options={'ordering': (django.db.models.functions.text.Lower('nom'),), 'verbose_name': 'Morceau', 'verbose_name_plural': 'Morceaux'},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='partitionset',
|
||||
options={'ordering': (django.db.models.functions.text.Lower('nom'),), 'verbose_name': 'Morceau', 'verbose_name_plural': 'Morceaux'},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='partitionset',
|
||||
name='download_unlogged',
|
||||
field=models.CharField(choices=[('n', 'Non'), ('o', 'Oui')], default='n', max_length=1, verbose_name='Téléchargeable non connecté ?'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='partitionset',
|
||||
name='infos',
|
||||
field=models.TextField(blank=True, default='', verbose_name='Infos utiles'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='partitionset',
|
||||
name='infos_en',
|
||||
field=models.TextField(blank=True, default='', verbose_name='Infos utiles en anglais'),
|
||||
),
|
||||
]
|
|
@ -2,10 +2,12 @@ import os
|
|||
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from colorful.fields import RGBColorField
|
||||
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=_("ordre"))
|
||||
|
@ -45,9 +47,9 @@ class PartitionSet(models.Model):
|
|||
on_delete=models.PROTECT,
|
||||
verbose_name=_("Type de partition")
|
||||
)
|
||||
|
||||
infos = models.TextField(_("Infos utiles"), null=True, blank=True)
|
||||
infos_en = models.TextField("Infos utiles en anglais", null=True, blank=True)
|
||||
download_unlogged = models.CharField(_("Téléchargeable non connecté ?"),default='n',choices = [('n',_('Non')),('o',_('Oui'))],max_length=1)
|
||||
infos = models.TextField(_("Infos utiles"), null=False, blank=True,default="")
|
||||
infos_en = models.TextField("Infos utiles en anglais", null=False, blank=True,default="")
|
||||
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))
|
||||
|
|
|
@ -8,8 +8,20 @@
|
|||
<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>
|
||||
|
||||
<span class="image fit">
|
||||
{% if photo %}
|
||||
<img src="{{photo.image.url}}" alt="" /> <div style="position:absolute;z-index:1;right:0;bottom:0">
|
||||
{% if photo.url %}
|
||||
<a href="{{photo.url}}" target="_blank" class="icon fa-copyright" style="color: {{photo.color}}"> {% if photo.auteur %}{{photo.auteur}}{%endif%}</a>
|
||||
{% elif photo.auteur %}
|
||||
<div class="icon fa-copyright" style="color: {{photo.color}}" > {{photo.auteur}}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
<img src="{% static 'images/all_repertoire.jpg' %}" alt="" /> <div style="position:absolute;z-index:1;right:0;bottom:0">
|
||||
<div class="icon fa-copyright" style="color:#000000"> Lucas Gierzack</div>
|
||||
{% endif %}
|
||||
</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>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from django.shortcuts import render, HttpResponse, get_object_or_404, redirect, reverse
|
||||
from partitions.models import Category, Partition, PartitionSet
|
||||
from gestion.models import Photo
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from partitions.forms import UploadFileForm, UploadMorceauForm
|
||||
from django.forms.models import modelform_factory
|
||||
|
@ -54,14 +55,15 @@ def download_musecores(request):
|
|||
|
||||
def liste(request):
|
||||
categories = Category.objects.prefetch_related("partitionset_set").order_by("order")
|
||||
return render(request, 'partitions/repertoire.html', {"categories": categories})
|
||||
photo = Photo.objects.filter(cat='part').order_by('?').first()
|
||||
return render(request, 'partitions/repertoire.html', {"categories": categories,"photo":photo})
|
||||
|
||||
@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"))
|
||||
fields=("category","download_unlogged", "infos","url","infos_en"))
|
||||
if request.method == "POST" and request.user.profile.is_chef:
|
||||
form = ChefEditForm(request.POST, instance=p)
|
||||
if form.is_valid():
|
||||
|
@ -95,30 +97,35 @@ 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)
|
||||
_, extension = os.path.splitext(partition.part.path)
|
||||
if ".pdf" == extension:
|
||||
with open(partition.part.path, 'rb') as f:
|
||||
myfile = File(f)
|
||||
response = HttpResponse(content=myfile.read())
|
||||
response["Content-Type"] = "application/pdf"
|
||||
response["Content-Disposition"] = "inline; filename=%s_%s_%s.pdf" % (
|
||||
slugify(nom), slugify(auteur), slugify(partition.nom))
|
||||
return response
|
||||
elif ".mp3" == extension:
|
||||
with open(partition.part.path, 'rb') as f:
|
||||
myfile = File(f)
|
||||
response = HttpResponse()
|
||||
response.write(myfile.read())
|
||||
response["Content-Type"] = "audio/mp3"
|
||||
response["Content-Length"] = myfile.size
|
||||
return response
|
||||
else:
|
||||
p = get_object_or_404(PartitionSet, nom=nom, auteur=auteur)
|
||||
part = p.partition_set.all()
|
||||
return render(request, 'partitions/part.html', locals())
|
||||
download_unlogged = partition.morceau.download_unlogged
|
||||
if(download_unlogged == 'o' or request.user.is_authenticated):
|
||||
if ".pdf" == extension:
|
||||
with open(partition.part.path, 'rb') as f:
|
||||
myfile = File(f)
|
||||
response = HttpResponse(content=myfile.read())
|
||||
response["Content-Type"] = "application/pdf"
|
||||
response["Content-Disposition"] = "inline; filename=%s_%s_%s.pdf" % (
|
||||
slugify(nom), slugify(auteur), slugify(partition.nom))
|
||||
return response
|
||||
elif ".mp3" == extension:
|
||||
with open(partition.part.path, 'rb') as f:
|
||||
myfile = File(f)
|
||||
response = HttpResponse()
|
||||
response.write(myfile.read())
|
||||
response["Content-Type"] = "audio/mp3"
|
||||
response["Content-Length"] = myfile.size
|
||||
return response
|
||||
else:
|
||||
p = get_object_or_404(PartitionSet, nom=nom, auteur=auteur)
|
||||
part = p.partition_set.all()
|
||||
return render(request, 'partitions/part.html', locals())
|
||||
else :
|
||||
return redirect('login')
|
||||
|
||||
@chef_required
|
||||
def delete(request, nom, auteur, id):
|
||||
p = get_object_or_404(PartitionSet, nom=nom, auteur=auteur)
|
||||
|
@ -189,14 +196,19 @@ def conf_delete_morc(request, nom, auteur):
|
|||
|
||||
|
||||
|
||||
@login_required
|
||||
|
||||
def download(request, nom, auteur, partition_id):
|
||||
|
||||
partition = get_object_or_404(Partition, id=partition_id)
|
||||
with open(partition.part.path, 'rb') as f:
|
||||
myfile = File(f)
|
||||
response = HttpResponse(content=myfile.read())
|
||||
typ = os.path.splitext(myfile.name)[1][1:]
|
||||
response['Content-Type'] = 'application/%s' % (typ, )
|
||||
response['Content-Disposition'] = 'attachment; filename=%s_%s_%s.%s' % (
|
||||
slugify(nom), slugify(auteur), slugify(partition.nom), typ)
|
||||
return response
|
||||
download_unlogged = partition.morceau.download_unlogged
|
||||
if(download_unlogged == 'o' or request.user.is_authenticated):
|
||||
with open(partition.part.path, 'rb') as f:
|
||||
myfile = File(f)
|
||||
response = HttpResponse(content=myfile.read())
|
||||
typ = os.path.splitext(myfile.name)[1][1:]
|
||||
response['Content-Type'] = 'application/%s' % (typ, )
|
||||
response['Content-Disposition'] = 'attachment; filename=%s_%s_%s.%s' % (
|
||||
slugify(nom), slugify(auteur), slugify(partition.nom), typ)
|
||||
return response
|
||||
else :
|
||||
return redirect('login')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue