Added decision viewer with protected pdf server

This commit is contained in:
Zak Timson 2017-09-05 23:28:52 -04:00
parent 2dec223f8b
commit cc8f5750a8
4 changed files with 31 additions and 2 deletions

View File

@ -1,9 +1,10 @@
import os
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls import url
from django.contrib import admin
from django.contrib.auth.decorators import login_required
from django.shortcuts import Http404
from django.views.static import serve
import main.views
@ -14,6 +15,8 @@ import newsletters.views
@login_required
def protected_serve(request, path, document_root=None, show_indexes=False):
if not request.user.has_perm('view_pdf'):
return Http404()
return serve(request, path, document_root, show_indexes)

View File

@ -9,6 +9,12 @@ class Subtitle(models.Model):
class Decision(models.Model):
class Meta(object):
permissions = (
('view_pdf', 'Can view PDF'),
)
date = models.DateField()
headers = models.ManyToManyField(Subtitle)
pdf = models.FileField(upload_to='secure')

View File

@ -0,0 +1,19 @@
{% extends 'base.html' %}
{% load static %}
{% block head %}
{% endblock %}
{% block body %}
<div class="container-fluid bg-light-blue py-3">
<div class="container">
<h1>Synopsis</h1>
<h6 class="text-muted">Date: {{ decision.date }}</h6>
<p>{{ decision.synopsis | linebreaks }}</p>
{% if perms.case_law.view_pdf %}
<a href="/media/{{ decision.pdf }}">View PDF</a>
{% endif %}
</div>
</div>
{% endblock %}

View File

@ -38,4 +38,5 @@ def browser(request):
def case(request, id):
return render(request)
decision = Decision.objects.get(id=id)
return render(request, 'decision.html', {'decision': decision})