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_photo_file(f, title): """ """ photo = Photo() photo.title = u'%s %s' % (time_slug_string(), title) photo.title_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 uploadimagejson(request): p = Photo() if request.user.is_authenticated(): if request.method == 'POST': pt = codegenerator()+codegenerator() p.image = request.FILES['file'] p.title = pt p.title_slug = slugify(pt) #+codegenerator() p.save() # template = loader.get_template('redactorimageupload.html') params = { 'photo' : p } # context = RequestContext(request, params) return render_to_response('redactorimageupload.html',params,context_instance = RequestContext(request))
def uploadimagejson(request): p = Photo() if request.user.is_authenticated(): if request.method == 'POST': pt = codegenerator() + codegenerator() p.image = request.FILES['file'] p.title = pt p.title_slug = slugify(pt) #+codegenerator() p.save() # template = loader.get_template('redactorimageupload.html') params = {'photo': p} # context = RequestContext(request, params) return render_to_response('redactorimageupload.html', params, context_instance=RequestContext(request))
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 clean_photo(self): cleaned_data = self.cleaned_data cleaned_data['id_photo'] = self.data['id_photo'] photo = cleaned_data.get('photo') if isinstance(photo, long): try: cleaned_data['photo'] = Photo.objects.get(pk=photo) except Photo.DoesNotExist: raise forms.ValidationError(_('Photo does not exist')) elif isinstance(photo, InMemoryUploadedFile): new_photo = Photo(title=photo.name, image=photo, is_gallery_thumbnail=True) cleaned_data['photo'] = new_photo try: new_photo.save() except IntegrityError: new_photo.title = new_photo.get_avaliable_title() new_photo.save() return cleaned_data['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
def upload_data(): with open(TEST_FILENAME) as f: data = json.loads(f.read()) user = User.objects.all()[0] skipped = 0 for i, point in enumerate(data): try: photo_file_url = point['photo_file_url'] photo_title = point['photo_title'][:30] photo_location = Point(point['latitude'], point['longitude']) photo_filename = '{}.jpg'.format(slugify(photo_title)) photo_file = URLopener().retrieve(photo_file_url, os.path.join('public/media', photo_filename)) photo = Photo(image=File(open(photo_file[0]))) unique_slugify(photo, photo_title) photo.title = photo.slug photo.save() poi = POI() poi.location = photo_location poi.name = photo_title poi.description = get_description( point['latitude'], point['longitude'], photo_title) poi.user = user poi.photo = photo poi.save() print i, photo_title, 'Saved.' except Exception: print traceback.format_exc() skipped += 1 print skipped, 'POIs were skipped.'
def loadUrlImage(url='', title='', tags='', format='jpg'): """ """ if not url: url = 'http://ahotsak.com/files/Proiektuak/beasain.jpg' title = 'Beasain' tags = 'proiektua beasain' slug = slugify(title)[:50] image = _getUrlImage(url) if not image: return 0 if Photo.objects.filter(title_slug=slug): for i in range(1,1000): new_slug = '%s-%d' % (slug,i) new_title = '%s (%d)' % (title,i) if not Photo.objects.filter(title_slug=new_slug): slug = new_slug title = new_title break photo = Photo() photo.title = title photo.tags = tags photo.title_slug = slug photo.image.save('%s.%s' % (slug,format), ContentFile(image.read())) try: photo.save() except: print 'Errorea irudi honekin', photo.title """ photo.title_slug = photo.title_slug + '_2' photo.save() """ return photo
def handle(self, *args, **options): if len(args) != 2: raise CommandError("This command takes exactly two arguments") galleries_filename, pictures_filename = args with open(galleries_filename, 'r') as gh: galleries = json.load(gh) galleries_result = {} paths = {} for gallery in galleries: paths[gallery['gid']] = gallery['path'] kwargs = { 'title': gallery['title'], 'title_slug': gallery['slug'], 'description': gallery['galdesc'], } try: new_gallery = Gallery.objects.get(title_slug=gallery['slug']) for key, value in kwargs.items(): setattr(new_gallery, key, value) except Gallery.DoesNotExist: new_gallery = Gallery(**kwargs) new_gallery.save() galleries_result[gallery['gid']] = new_gallery with open(pictures_filename, 'r') as ph: pictures = json.load(ph) result = [] for picture in pictures: path = paths[picture['galleryid']] kwargs = { 'title': picture['alttext'], 'title_slug': picture['image_slug'], 'date_taken': datetime(*time.strptime(picture['imagedate'], "%Y-%m-%d %H:%M:%S")[0:6]), 'image': os.path.join('/'.join(path.split('/')[1:]), picture['filename']), 'caption': picture['description'], 'is_public': not bool(picture['exclude']), } d = 0 try: new_photo = Photo.objects.get(title_slug=picture['image_slug']) for key, value in kwargs.items(): setattr(new_gallery, key, value) except Photo.DoesNotExist: new_photo = Photo(**kwargs) while True: try: if d: title = new_photo.title + (' %d' % d) else: title = new_photo.title Photo.objects.get(title=title) d+=1 except Photo.DoesNotExist: new_photo.title = title break gallery = galleries_result[picture['galleryid']] new_photo.save() gallery.photos.add(new_photo)