Skip to content

Commit 5631ea6

Browse files
Merge pull request #2 from tinpan-io/dev
Dev
2 parents 8c17616 + f7a5d9b commit 5631ea6

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

README.rst

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Next, add busker's URLs to your Django project's main ``urls.py`` module::
3131

3232
(The first argument to ``path()`` can be whatever you like, but make sure ``namespace`` is set to ``'busker'``.
3333

34+
For uploaded images to display correctly you also will need ``MEDIA_ROOT`` and ``MEDIA_URL`` configured in your ``settings.py`` module. (See <https://docs.djangoproject.com/en/3.1/howto/static-files/> for a way to tweak your project ``urls.py`` to serve media when developing locally.)
35+
3436
Finally, in the terminal, run busker's migrations from the top level of the Django project::
3537

3638
python manage.my migrate busker

busker/models.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from uuid import uuid4
55

66
from django.contrib.auth.models import User
7-
from django.core.exceptions import ValidationError
87
from django.db import models
98
from django.db.models.signals import post_save
109
from django.dispatch import receiver
@@ -111,7 +110,7 @@ def filename(self):
111110
return os.path.basename(self.file.name)
112111

113112
def __str__(self):
114-
return self.file.name
113+
return os.path.basename(self.file.name)
115114

116115

117116
class Batch(BuskerModel):

busker/views.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime
2+
import os
23
from secrets import token_hex
34

45
from django.http import HttpResponse, Http404
@@ -58,8 +59,9 @@ def form_valid(self, form):
5859

5960

6061
class DownloadView(View):
61-
# TODO document requirement of 'django.core.context_processors.request' middleware
62-
62+
"""
63+
Handles the actual downloading of files.
64+
"""
6365
def get(self, request, *args, **kwargs):
6466
if 'busker_download_token' not in request.session \
6567
or request.GET.get('t') != request.session['busker_download_token']:
@@ -68,9 +70,10 @@ def get(self, request, *args, **kwargs):
6870

6971
file = File.objects.get(id=kwargs['file_id'])
7072
mime = magic.Magic(mime=True)
73+
filename = os.path.basename(file.file.path)
7174

7275
response = HttpResponse(file.file, content_type=mime.from_file(file.file.path))
73-
response['Content-Disposition'] = f'attachment; filename="{file.file.name}"'
76+
response['Content-Disposition'] = f'attachment; filename="{filename}"'
7477
response['Content-Length'] = file.file.size
7578
return response
7679

setup.cfg

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = django-busker
3-
version = 0.5.0
3+
version = 0.5.1
44
description = A Django app to manage download codes for digital assets.
55
long_description = file: README.rst
66
url = https://github.com/tinpan-io/django-busker
@@ -22,6 +22,7 @@ classifiers =
2222
Programming Language :: Python :: 3.8
2323
Topic :: Internet :: WWW/HTTP
2424
Topic :: Internet :: WWW/HTTP :: Dynamic Content
25+
Topic :: Multimedia
2526

2627
[options]
2728
include_package_data = true

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
setup(
44
install_requires=[
55
'python-magic==0.4.18',
6+
'Pillow==7.2.0',
67
'django-markdownfield==0.8.0',
78
'django-queryset-csv==1.1.0',
89
'django-imagekit==4.0.2',

0 commit comments

Comments
 (0)