aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorAndrea Lepori <alepori@student.ethz.ch>2020-12-10 14:01:22 +0100
committerAndrea Lepori <alepori@student.ethz.ch>2020-12-10 14:01:22 +0100
commit856ad4734e168c1b56f349244acd0cc14fcd8d78 (patch)
tree0b8551b20c7df925fd9b3b408349f66dc81cf162 /server
parentrenaming, max partecipant number, only "capi" docs (diff)
downloadscout-subs-856ad4734e168c1b56f349244acd0cc14fcd8d78.tar.gz
scout-subs-856ad4734e168c1b56f349244acd0cc14fcd8d78.zip
lazyload images
Diffstat (limited to '')
-rw-r--r--server/templates/server/doc_list.html10
-rw-r--r--server/urls.py1
-rw-r--r--server/views.py45
3 files changed, 45 insertions, 11 deletions
diff --git a/server/templates/server/doc_list.html b/server/templates/server/doc_list.html
index 2499245..f98cbd5 100644
--- a/server/templates/server/doc_list.html
+++ b/server/templates/server/doc_list.html
@@ -160,6 +160,9 @@
{% elif doc.0.status == "autosign" %}
<i class="material-icons">assignment_turned_in</i>
{% endif %}
+ {% if settings.DEBUG %}
+ {{doc.0.id}}:
+ {% endif %}
{{doc.0.document_type.name}}
<span class="badge" data-badge-caption="">{{doc.0.user.first_name}} {{doc.0.user.last_name}}</span>
</div>
@@ -416,7 +419,7 @@
<div class="col s12">
<div class="card">
<div class="card-image">
- {% if doc.5 %}<img src="data:;base64,{{ doc.5 }}">{% endif %}
+ {% if doc.5 %}<img class="lazyload" data-src="{{ doc.5 }}">{% endif %}
</div>
</div>
</div>
@@ -425,7 +428,7 @@
<div class="col s12">
<div class="card">
<div class="card-image">
- {% if doc.6 %}<img src="data:;base64,{{ doc.6 }}">{% endif %}
+ {% if doc.6 %}<img class="lazyload" data-src="{{ doc.6 }}">{% endif %}
</div>
</div>
</div>
@@ -434,7 +437,7 @@
<div class="col s12">
<div class="card">
<div class="card-image">
- {% if doc.7 %}<img src="data:;base64,{{ doc.7 }}">{% endif %}
+ {% if doc.7 %}<img class="lazyload" data-src="{{ doc.7 }}">{% endif %}
</div>
</div>
</div>
@@ -465,6 +468,7 @@ $(document).ready(function(){
update();
document.getElementById('progress_bar').className = "determinate";
{% endif %}
+ lazyload();
});
function resetModal() {
diff --git a/server/urls.py b/server/urls.py
index 3c4f66f..087e7ad 100644
--- a/server/urls.py
+++ b/server/urls.py
@@ -16,4 +16,5 @@ urlpatterns = [
path('docpreview', views.docpreview, name='docpreview'),
path('progress', views.get_progress, name='progress'),
path('request', views.data_request, name='request'),
+ path('media/<int:id>/<str:t>', views.media_request, name='media'),
]
diff --git a/server/views.py b/server/views.py
index 9ea1d3f..c7983e2 100644
--- a/server/views.py
+++ b/server/views.py
@@ -915,17 +915,13 @@ def doclist(request):
if i.medical_data:
medical = i.medical_data
if medical.vac_certificate.name:
- with open(medical.vac_certificate.name, 'rb') as image_file:
- vac_file = base64.b64encode(image_file.read()).decode()
+ vac_file = "/server/media/" + str(i.id) + "/vac_certificate"
if medical.health_care_certificate.name:
- with open(medical.health_care_certificate.name, 'rb') as image_file:
- health_file = base64.b64encode(image_file.read()).decode()
+ health_file = "/server/media/" + str(i.id) + "/health_care_certificate"
if i.signed_doc:
- with open(i.signed_doc.name, 'rb') as image_file:
- sign_doc_file = base64.b64encode(
- image_file.read()).decode()
+ sign_doc_file = "/server/media/" + str(i.id) + "/signed_doc"
doc_group = i.user.groups.values_list('name', flat=True)[0]
@@ -1139,6 +1135,10 @@ def docpreview(request):
document = Document.objects.filter(code=code)[0]
parent_group = document.user.groups.values_list('name', flat=True)[0]
+ # user has not permission to view document
+ if parent_group not in groups:
+ return
+
# prepare images in base64
vac_file = ""
health_file = ""
@@ -1183,4 +1183,33 @@ def data_request(request):
data += user.email + ", "
data = data[:-2]
context["data"] = data
- return render(request, 'server/data_request.html', context) \ No newline at end of file
+ return render(request, 'server/data_request.html', context)
+
+def media_request(request, id=0, t=""):
+ doc = Document.objects.get(id=id)
+ doc_group = doc.user.groups.values_list('name', flat=True)[0]
+
+ # check if user can view media
+ if request.user.is_staff:
+ # user is staff
+ groups = request.user.groups.values_list('name', flat=True)
+ if doc_group not in groups:
+ return
+ elif request.user.has_perm("client.staff"):
+ # user is psudo-staff
+ groups = request.user.groups.values_list('name', flat=True)[1:]
+ if doc_group not in groups:
+ return
+ else:
+ # is normal user
+ if doc.user != request.user:
+ return
+
+ if t == "health_care_certificate":
+ image_file = doc.medical_data.health_care_certificate
+ elif t == "vac_certificate":
+ image_file = doc.medical_data.vac_certificate
+ elif t == "signed_doc":
+ image_file = doc.signed_doc
+
+ return FileResponse(image_file, filename=image_file.name) \ No newline at end of file