Visualisation des pdf en ligne

This commit is contained in:
R1kM 2015-03-29 17:50:31 +02:00
parent 2140fcc7ee
commit c0af60eedb
4 changed files with 25 additions and 5 deletions

View file

@ -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", )

View file

@ -6,6 +6,7 @@ urlpatterns = patterns('partitions.views',
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/upload/?$', 'upload'),
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/delete/?$', 'delete_morc'),
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/conf/?$', 'conf_delete_morc'),
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/see/(?P<file_name>[^/]+)/?$', 'see'),
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>[^/]+)/conf/?$', 'conf_delete'),

View file

@ -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

View file

@ -7,7 +7,11 @@
<p>{{ suppression }}</p>
{% endif %}
{% for p in part %}
<p>{{ p.nom }} {% if user.is_authenticated %}<a href="{% url "partitions.views.download" nom auteur p.part.url|cuturl %}">Télécharger</a>{% endif %} </p>
{% if user.is_authenticated and ".pdf" in p.part.url %}
<p><a href="{% url "partitions.views.see" nom auteur p.part.url|cuturl %}">{{ p.nom }}</a>
{% else %}<p>{{ p.nom }}
{% endif %}
{% if user.is_authenticated %}<a href="{% url "partitions.views.download" nom auteur p.part.url|cuturl %}">Télécharger</a>{% endif %} </p>
{% if user.profile.is_chef %}
<p><a href="{% url "partitions.views.conf_delete" nom auteur p.pk %}">Supprimer</a> </p>
{% endif %}