Commits

Benjamin Klüglein committed ecd0f5d

retrieving files by id

  • Participants
  • Parent commits 78e9be5

Comments (0)

Files changed (2)

File upload/models.py

     description = models.TextField(max_length=512)
     created_at = models.DateTimeField("Created at")
     file_on_fs = models.FileField(upload_to="uploads")
-    download_password = models.CharField(max_length=64, blank=True, null=True)
+    download_password = models.CharField(max_length=64, blank=True)
+
+    def is_password_protected(self):
+        return any(self.download_password )
     

File upload/views.py

 from Datenaustausch.upload.models import File
 from django.http import HttpResponse, Http404
 
+from os import path
+
 def download(request, download_id):
     try:
         f = File.objects.get(pk=download_id)
     except File.DoesNotExist:
         raise Http404
         
-    return HttpResponse(f.file_on_fs)
+    return HttpResponse(path.basename(f.file_on_fs.name))