def handle_uploaded_file(f, author): photo = Photo() extra = PhotoExtended() photo.title = u"%s %s" % (author, time_slug_string()) photo.slug = u"%s-%s" % (author, slugify(time_slug_string())) photo.image = f photo.save() extra.photo = photo extra.author = author extra.save() return photo
def handle_url_file(url, author): photo = Photo() extra = PhotoExtended() photo.title = u"%s %s" % (author, time_slug_string()) photo.slug = u"%s-%s" % (slugify(author), slugify(time_slug_string())) img_name = photo.slug + url[url.rfind(".") :] photo.image.save(img_name, ContentFile(urllib2.urlopen(url).read())) photo.save() extra.photo = photo extra.author = author extra.save() return photo