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 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 import_folder(request=None, gallery_name=None): count = 0 current_site = Site.objects.get(id=settings.SITE_ID) if gallery_name: gallery = Gallery.objects.filter(slug=gallery_name) if not gallery: gallery = Gallery(title=gallery_name, slug=gallery_name) gallery.save() else: gallery = Gallery.objects.first() if not gallery: gallery = Gallery(title="MyFirstGallery", slug='MyFirstGallery') gallery.save() for filename in os.listdir(IMPORT_FOLDER): if not os.path.isfile(filename): if filename[-3:] in image_extensions: logger.debug('Reading file "{0}").'.format(filename)) full_name = os.path.join(IMPORT_FOLDER, filename) if Photo.objects.filter(title=filename).exists(): logger.debug('file already exist in system: "{0}").'.format(filename)) dst_name = os.path.join(IMPORT_CONFLICT_FOLDER, filename) shutil.move(full_name, dst_name) else: storage_path = models.get_storage_path(None, filename) dst_name = os.path.join(settings.MEDIA_ROOT, storage_path) shutil.move(full_name, dst_name) photo = Photo(title=filename, slug=slugify(filename), caption=filename, is_public=True) photo.image = storage_path photo.save() photo.sites.add(current_site) gallery.photos.add(photo) count += 1 if request: messages.success(request, _('{0} photos have been added to gallery "{1}".').format( count, gallery.title), fail_silently=True)