comparison photologue/models.py @ 94:dcd097a59223

For Django 1.5: slugify is now available in django.utils.text.
author Brian Neal <bgneal@gmail.com>
date Wed, 28 Aug 2013 19:00:43 -0500
parents e2868ad47a1e
children 762e46d0bb4a
comparison
equal deleted inserted replaced
93:388be986392e 94:dcd097a59223
1 import os 1 import os
2 import random 2 import random
3 import shutil
4 import zipfile 3 import zipfile
5 4
6 from datetime import datetime 5 from datetime import datetime
7 from inspect import isclass 6 from inspect import isclass
8 7
9 from django.db import models 8 from django.db import models
10 from django.db.models.signals import post_init 9 from django.db.models.signals import post_init
11 from django.conf import settings 10 from django.conf import settings
12 from django.core.files.base import ContentFile 11 from django.core.files.base import ContentFile
13 from django.core.urlresolvers import reverse 12 from django.core.urlresolvers import reverse
14 from django.template.defaultfilters import slugify 13 from django.utils.text import slugify
15 from django.utils.functional import curry 14 from django.utils.functional import curry
16 from django.utils.translation import ugettext_lazy as _ 15 from django.utils.translation import ugettext_lazy as _
17 16
18 # Required PIL classes may or may not be available from the root namespace 17 # Required PIL classes may or may not be available from the root namespace
19 # depending on the installation method used. 18 # depending on the installation method used.
228 while 1: 227 while 1:
229 title = ' '.join([self.title, str(count)]) 228 title = ' '.join([self.title, str(count)])
230 slug = slugify(title) 229 slug = slugify(title)
231 try: 230 try:
232 p = Photo.objects.get(title_slug=slug) 231 p = Photo.objects.get(title_slug=slug)
233 except Photo.DoesNotExist: 232 except Photo.DoesNotExist:
234 photo = Photo(title=title, title_slug=slug, 233 photo = Photo(title=title, title_slug=slug,
235 caption=self.caption, 234 caption=self.caption,
236 is_public=self.is_public, 235 is_public=self.is_public,
237 tags=self.tags) 236 tags=self.tags)
238 photo.image.save(filename, ContentFile(data)) 237 photo.image.save(filename, ContentFile(data))