Skip to content

Commit d7aafd0

Browse files
Merge pull request #4 from tinpan-io/dev
Production hotfixes, new signals
2 parents 75f1098 + 7ba9a43 commit d7aafd0

File tree

7 files changed

+29
-6
lines changed

7 files changed

+29
-6
lines changed

README.rst

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

3434
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.)
3535

36+
When deploying to production, you'll need to run the ``collectstatic`` admin command.
37+
3638
Finally, in the terminal, run busker's migrations from the top level of the Django project::
3739

3840
python manage.my migrate busker
@@ -52,7 +54,7 @@ Represents an artist/creator.
5254
DownloadableWork
5355
----------------
5456

55-
Represents an item that will be accessible to people with valid download codes; for example, an music album or EP.
57+
Represents an item that will be accessible to people with valid download codes; for example, a zip file containing an album of music. (Or, several zip files of the same album in different formats.)
5658

5759
File
5860
----
@@ -68,3 +70,13 @@ DownloadCode
6870
------------
6971

7072
DownloadCode objects represent the actual codes users can use to access files. They're generally auto-created when a new Batch is saved. Note the 'export csv' option in the DownloadCode admin view.
73+
74+
Signals
75+
=======
76+
Busker provides the following signals which may be useful:
77+
78+
``busker.signals.code_post_redeem(sender, request, code)``
79+
This signal is sent whenever a DownloadCode is redeemed, *after* its ``times_used`` and ``last_used_date`` fields have been updated but *before* the user is presented with the download page. It sends the `request` object and the `DownloadCode` object being redeemed.
80+
81+
``busker.signals.file_pre_download(sender, request, file)``
82+
This signal is sent whenever a user clicks on a link to download a file, *after* the File object has been loaded but *before* the file is actually sent to the client. It sends the `request` object and the `File` object being redeemed.

busker/manage.py

100755100644
File mode changed.

busker/models.py

100755100644
File mode changed.

busker/signals.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from django.dispatch import Signal
2+
3+
code_post_redeem = Signal(providing_args=["request", "code"])
4+
file_pre_download = Signal(providing_args=["request", "file"])

busker/templates/busker/confirm_form.html

+8-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ <h2>Code Expired</h2>
99
<h2>Redeem Code</h2>
1010
{% endif %}
1111
{% if code.batch.work.image %}
12-
<div class="busker-thumbnail">
13-
<img src="{{ code.batch.work.thumbnail.url }}" alt="{{ code.batch.work.title }}">
12+
<div class="busker-thumbnail">
13+
<img src="{{ code.batch.work.thumbnail.url }}" alt="{{ code.batch.work.title }}">
1414
</div>
1515
{% endif %}
1616
<form action="{% url 'busker:redeem' form.code.value %}" method="POST">
@@ -20,9 +20,13 @@ <h2>Redeem Code</h2>
2020
{% elif code.remaining_uses > 0 %}
2121
<p>This code has {{ code.remaining_uses }} use{{ code.remaining_uses|pluralize }} left.</p>
2222
{{ form.as_p }}
23-
<input type="submit" value="Continue">
23+
{% if code.batch.public_message %}
24+
{{ code.batch.public_message_rendered|safe }}
25+
{% endif %}
26+
27+
<input type="submit" value="Continue">
2428
{% else %}
2529
This code has already been used.
2630
{% endif %}
2731
</form>
28-
{% endblock %}
32+
{% endblock %}

busker/views.py

100755100644
+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import magic
1111
from .forms import RedeemCodeForm, ConfirmForm
1212
from .models import DownloadCode, File, validate_code
13+
from .signals import code_post_redeem, file_pre_download
1314
from .util import log_activity
1415

1516
# TODO custom 404 view using base.html for this app https://stackoverflow.com/a/35110595/3280582
@@ -57,6 +58,7 @@ def form_valid(self, form):
5758
log_activity(logger, code, "Code Redeemed", self.request)
5859
context = self.get_context_data()
5960
context['code'] = code
61+
code_post_redeem.send(sender=self.__class__, request=self.request, code=code)
6062
return render(self.request, 'busker/file_list.html', context=context)
6163

6264

@@ -75,6 +77,7 @@ def get(self, request, *args, **kwargs):
7577

7678
mime = magic.Magic(mime=True)
7779
filename = os.path.basename(file.file.path)
80+
file_pre_download.send(sender=self.__class__, request=self.request, file=file)
7881
response = HttpResponse(file.file, content_type=mime.from_file(file.file.path))
7982
response['Content-Disposition'] = f'attachment; filename="{filename}"'
8083
response['Content-Length'] = file.file.size

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = django-busker
3-
version = 0.5.2
3+
version = 0.6.0
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

0 commit comments

Comments
 (0)