diff --git a/gestion/forms.py b/gestion/forms.py index 287e029..9954440 100644 --- a/gestion/forms.py +++ b/gestion/forms.py @@ -9,8 +9,7 @@ class RegistrationFormUser(UserCreationForm): fields = ('username', 'first_name', 'last_name', 'password1', 'password2', 'email',) class InscriptionMembreForm(forms.ModelForm): - validation = forms.CharField(max_length=100) - + validation = forms.CharField(max_length=100, widget=forms.PasswordInput) class Meta: model = ErnestoUser fields = ("phone", "instru", ) diff --git a/partitions/urls.py b/partitions/urls.py index c80f182..092c8d3 100644 --- a/partitions/urls.py +++ b/partitions/urls.py @@ -6,6 +6,7 @@ urlpatterns = patterns('partitions.views', url(r'^(?P[^/]+)/(?P[^/]+)/upload/?$', 'upload'), url(r'^(?P[^/]+)/(?P[^/]+)/delete/?$', 'delete_morc'), url(r'^(?P[^/]+)/(?P[^/]+)/conf/?$', 'conf_delete_morc'), + url(r'^(?P[^/]+)/(?P[^/]+)/see/(?P[^/]+)/?$', 'see'), url(r'^(?P[^/]+)/(?P[^/]+)/(?P[^/]+)/$', 'download'), url(r'^(?P[^/]+)/(?P[^/]+)/(?P[^/]+)/delete/?$', 'delete'), url(r'^(?P[^/]+)/(?P[^/]+)/(?P[^/]+)/conf/?$', 'conf_delete'), diff --git a/partitions/views.py b/partitions/views.py index 861fe6c..a2b502e 100644 --- a/partitions/views.py +++ b/partitions/views.py @@ -1,8 +1,10 @@ -from django.shortcuts import render, redirect, HttpResponse +from django.shortcuts import render, redirect, HttpResponse, render_to_response from django.contrib.auth.decorators import login_required from django.utils.encoding import smart_str import os +from reportlab.pdfgen import canvas + from partitions.forms import UploadFileForm, UploadMorceauForm from partitions.models import Partition, PartitionSet @@ -38,16 +40,30 @@ def upload(request, nom, auteur): form = UploadFileForm() return render(request, 'partitions/upload.html', locals()) +@login_required +def see(request, nom, auteur, file_name): + if ".pdf" in file_name: + abspath=open('/home/rikm/Projets/Ernesto/media/partitions/' + file_name, 'rb') + response=HttpResponse(content=abspath.read()) + response["Content-Type"]="application/pdf" + response["Content-Disposition"]="inline; filename= %s" % (nom +'-'+ auteur +'-' + smart_str(file_name)) + abspath.close() + return response + else: + partitions = PartitionSet.objects.get(nom=nom, auteur=auteur) + part = partitions.partition_set.all() + return render(request, 'partitions/listepart.html', locals()) @login_required def download(request, nom, auteur, file_name): - abspath=open('/home/rikm/Projets/Ernestophone/media/partitions/' + file_name, 'rb') + abspath=open('/home/rikm/Projets/Ernesto/media/partitions/' + file_name, 'rb') response = HttpResponse(content=abspath.read()) typ = file_name.split(".") n = len(typ) typ = typ[n-1] response['Content-Type'] = 'application/' + typ response['Content-Disposition'] = 'attachment; filename= %s ' % (nom +'-'+ auteur + '-' + smart_str(file_name)) + abspath.close() return response @login_required diff --git a/templates/partitions/listepart.html b/templates/partitions/listepart.html index 1d5e9dd..4420eec 100644 --- a/templates/partitions/listepart.html +++ b/templates/partitions/listepart.html @@ -7,7 +7,11 @@

{{ suppression }}

{% endif %} {% for p in part %} -

{{ p.nom }} {% if user.is_authenticated %}Télécharger{% endif %}

+{% if user.is_authenticated and ".pdf" 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 %}