diff --git a/.hgignore b/.hgignore index 8c43e10..17f48b9 100644 --- a/.hgignore +++ b/.hgignore @@ -8,3 +8,4 @@ syntax: glob local_settings.py static/cache/* static/photos/* +static/drawings/* diff --git a/core/templatetags/core_tags.py b/core/templatetags/core_tags.py index d739778..e1c41ae 100644 --- a/core/templatetags/core_tags.py +++ b/core/templatetags/core_tags.py @@ -16,6 +16,14 @@ def photo_for_user(user): """ return "photos/%s" % user.id +@register.filter +def image_for_drawing(drawing): + """ + Just returns the path to the drawing's image since we can't + combined values in a template to pass to the thumbnail tag. + """ + return "drawings/%s" % drawing.id + @register.simple_tag(takes_context=True) def load_in_progress(context): """ diff --git a/core/utils.py b/core/utils.py index ab11de7..10d582f 100644 --- a/core/utils.py +++ b/core/utils.py @@ -1,4 +1,8 @@ +from os import mkdir +from os.path import join, exists + +from django.conf import settings from django.contrib.auth.models import User from redis import Redis, ConnectionPool @@ -69,6 +73,12 @@ def save(self, message): data=message[3].replace(" ", "+")) for user_id in redis.smembers(self.drawers_data_key): drawing.users.add(User.objects.get(id=user_id)) + # Save image file for thumbnailing. + path = join(settings.MEDIA_ROOT, "drawings") + if not exists(path): + mkdir(path) + with open(join(path, str(drawing.id)), "wb") as f: + f.write(drawing.data.split(",", 1)[1].decode("base64")) return False def mousedown(self, message): diff --git a/templates/list.html b/templates/list.html index 2dffb8d..ead84b2 100755 --- a/templates/list.html +++ b/templates/list.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% load pagination_tags %} +{% load thumbnail core_tags pagination_tags %} {% block body_class %}gallery{% endblock %} @@ -8,7 +8,9 @@