Standards drucken

This commit is contained in:
holger.trampe 2020-12-16 22:18:46 +01:00
parent 6e8c7ba9e0
commit 7e1ea6d634
9 changed files with 242 additions and 1 deletions

88
final.pdf Normal file

File diff suppressed because one or more lines are too long

88
standard.pdf Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,12 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>TITEL</title>
<style type="text/css">
</style>
</head>
<body>
{{content}}
</body>
</html>

View File

@ -222,10 +222,17 @@
{% endif %} {% endif %}
</div> </div>
<div class="mt-2"> <div class="mt-2">
<a href="{% url 'ajax-standardpdf' standard.pk %}" target="_blank" class="btn btn-primary btn-sm mr-2" onclick="javascript:printStandard()">
<i class="fas fa-print"></i>
</a>
<small> <small>
{% if not standard.created_standard_by %} Erstellt von gelöschtem Mitarbeiter {% else %} Erstellt durch <a href="{% url 'orga-single' standard.created_standard_by.pk %}">{{standard.created_standard_by.first_name}} {{standard.created_standard_by.last_name}}</a> {% endif %} am {{standard.created_standard_date}} | {% if not standard.last_modified_by %} Zuletzt bearbeitet von gelöschtem Benutzer {% else %} Zuletzt bearbeitet von <a href="{% url 'orga-single' standard.last_modified_by.pk %}">{{ standard.last_modified_by.first_name}} {{ standard.last_modified_by.last_name}}</a>{% endif %} am {{ standard.last_modified_on}} {% if not standard.created_standard_by %} Erstellt von gelöschtem Mitarbeiter {% else %} Erstellt durch <a href="{% url 'orga-single' standard.created_standard_by.pk %}">{{standard.created_standard_by.first_name}} {{standard.created_standard_by.last_name}}</a> {% endif %} am {{standard.created_standard_date}} | {% if not standard.last_modified_by %} Zuletzt bearbeitet von gelöschtem Benutzer {% else %} Zuletzt bearbeitet von <a href="{% url 'orga-single' standard.last_modified_by.pk %}">{{ standard.last_modified_by.first_name}} {{ standard.last_modified_by.last_name}}</a>{% endif %} am {{ standard.last_modified_on}}
</small> </small>
<!-- PRINT -->
</div> </div>
</div> </div>
@ -314,6 +321,7 @@
<script type="text/javascript"> <script type="text/javascript">
function goToStandardMain(){ function goToStandardMain(){
localStorage.setItem('activeTab', ""); localStorage.setItem('activeTab', "");
location.href = "{% url 'standards' %}"; location.href = "{% url 'standards' %}";

View File

@ -0,0 +1,9 @@
<div class="content-section col-12">
<h2>{{standard_name}}
</h2>
<hr>
{{standard_content}}
</div>

View File

@ -13,6 +13,7 @@ urlpatterns = [
path('standardadd/<int:id>', views.StandardAdd, name='standard-add'), path('standardadd/<int:id>', views.StandardAdd, name='standard-add'),
#path('standardupdate/<int:id>', views.StandardUpdate, name='standard-update'), #path('standardupdate/<int:id>', views.StandardUpdate, name='standard-update'),
path('ajax/loadtasks/', views.load_tasks, name='ajax_loadtasks'), path('ajax/loadtasks/', views.load_tasks, name='ajax_loadtasks'),
path('pdf/<int:pk>', views.getStandardPDF, name="ajax-standardpdf"),
path('ajups/<int:pk>', views.updatesbyajax, name='update_standard_by_ajax'), path('ajups/<int:pk>', views.updatesbyajax, name='update_standard_by_ajax'),
path('ajupsagn/<int:pk>', views.updatesbyajax_agn, name='update_standard_by_ajax_agn'), path('ajupsagn/<int:pk>', views.updatesbyajax_agn, name='update_standard_by_ajax_agn'),
path('standards/<int:pk>/delete', StandardDeleteView.as_view(), name='standard-delete'), path('standards/<int:pk>/delete', StandardDeleteView.as_view(), name='standard-delete'),

View File

@ -844,6 +844,42 @@ def updatesbyajax(request, pk):
return JsonResponse({"success" : success}) return JsonResponse({"success" : success})
# CREATE PDF FROM STANDARD
from io import BytesIO
from xhtml2pdf import pisa
# Utility function
def convert_html_to_pdf(source_html, output_filename):
result = BytesIO()
pdf = pisa.pisaDocument(BytesIO(source_html.encode("ISO-8859-1")), result)
if not pdf.err:
return HttpResponse(result.getvalue(), content_type='application/pdf')
return None
@login_required
def getStandardPDF(request, pk):
standard = Standards.objects.get(pk=pk)
# CHECK IF USER HAS RIGHTS TO SEE THIS Standard
groupsofstandard = Standards.objects.get(pk=pk, agency=request.user.profile.agency)
userisingroup = False
if len(groupsofstandard.visibleby.all()) == 0:
userisingroup = True
else:
for ag in groupsofstandard.visibleby.all():
if ag.group in request.user.groups.all():
userisingroup = True
if userisingroup:
pdf = convert_html_to_pdf(standard.content, "final.pdf")
return HttpResponse(pdf, content_type='application/pdf')
else:
messages.warning(request, f'Diesen Standard dürfen Sie nicht sehen!')
return redirect('standards')
@login_required @login_required
def StandardFromAgn(request, pk): def StandardFromAgn(request, pk):
try: try:

View File

@ -27,7 +27,6 @@ def loadingFreeDays(plz):
# Getting land # Getting land
file_path = os.path.join(settings.STATIC_ROOT, 'users/extra/plz_short.csv') file_path = os.path.join(settings.STATIC_ROOT, 'users/extra/plz_short.csv')
land = False land = False
with open(file_path, 'rt') as csvfile: with open(file_path, 'rt') as csvfile: