def handle_uploaded_file(f,title): """ """ photo = Photo() photo.title = u'%s %s' % (time_slug_string(), title) photo.slug = time_slug_string() photo.image = f photo.save() return photo
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
def save(self): data = self.cleaned_data photo = Photo() photo.title = data.get('title') photo.slug = re.sub(' +', '_', photo.title) photo.caption = data.get('caption') if (data.get('image') is not None): img_file = data.get('image') photo.image.save('%s' % (img_file.name), img_file, save=True) photo.save() galleries = data.get('galleries') if galleries is not None: for gallery in galleries: gallery.photos.add(photo) gallery.save() return photo
def loadUrlImage(url='', title='', tags='', format='jpg', slug=''): """ """ if not url: url = 'http://irudiak.argazkiak.org/1d3023545b4051907e533648e66329f8_c.jpg' title = 'Kakalardoa' tags = 'test argazkiak' if not slug: slug = time_slug() if Photo.objects.filter(slug=slug): slug = time_slug_long() title = title[:99] if Photo.objects.filter(title=title): title = '%s %s' % (slug, title)[:90] image = _getUrlImage(url) if not image: return None photo = Photo() photo.title = title[:100] photo.tags = tags photo.slug = slug try: image_t = Image.open(ContentFile(image.read())) image_t = image_t.convert("RGB") f=StringIO() image_t.save(f,"JPEG") f.seek(0) photo.image.save('%s.%s' % (slug,format), ContentFile(f.read())) except Exception: print('Errorea irudi honekin RGB', photo.slug) return photo try: photo.save() except: print('Errorea irudi honekin', photo.slug) return photo
def loadUrlImage(url='', title='', tags='', format='jpg', slug=''): """ """ if not url: url = 'http://irudiak.argazkiak.org/1d3023545b4051907e533648e66329f8_c.jpg' title = 'Kakalardoa' tags = 'test argazkiak' if not slug: slug = time_slug() if Photo.objects.filter(slug=slug): slug = time_slug_long() title = title[:99] if Photo.objects.filter(title=title): title = '%s %s' % (slug, title)[:90] image = _getUrlImage(url) if not image: return None photo = Photo() photo.title = title[:100] photo.tags = tags photo.slug = slug try: image_t = Image.open(ContentFile(image.read())) image_t = image_t.convert("RGB") f=StringIO() image_t.save(f,"JPEG") f.seek(0) photo.image.save('%s.%s' % (slug,format), ContentFile(f.read())) except Exception, e: print 'Errorea irudi honekin RGB', photo.slug, e return photo