当前位置: 首页>>代码示例>>Python>>正文


Python Photo.save方法代码示例

本文整理汇总了Python中photologue.models.Photo.save方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.save方法的具体用法?Python Photo.save怎么用?Python Photo.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在photologue.models.Photo的用法示例。


在下文中一共展示了Photo.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _convert

# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import save [as 别名]
def _convert(track, fileext):
    filename =  track.title_slug
    input = track.original_track.file.name
    print 'Original: ' + input
    print call('ffmpeg -i %s -sameq %s.%s' % (input, filename, fileext), shell=True)
    #Open the file and put it in a friendly format for image save
    f = open('%s.%s' % (filename, fileext), 'r')
    filecontent = ContentFile(f.read())
    track.__getattribute__("track_" + fileext).save('%s.%s' % (filename, fileext), filecontent , save=True)
    f.close()
    if track.image:
        pass
    else:
        print call('ffmpeg -i %s.%s -vframes 1 -ss 30 -sameq %s%sd.png' % (filename, fileext, filename, '%'), shell=True)
        f = open('%s1.png' % filename, 'r')
        filecontent = ContentFile(f.read())
        image = Photo(title=filename, title_slug=filename)
        image.image.save('%s.png' % filename, filecontent , save=True)
        image.save()
        track.image = image
    #Clean the flv and png files left around
    #call("find . -maxdepth 1 -type f -name '*." + fileext + "' -o -name '*.png' | xargs rm", shell=True)
    call("rm *." + fileext + " *.png *.stt", shell=True)
    track.save()
    print 'Converted' + track.__getattribute__("track_" + fileext).file.name
开发者ID:Fandekasp,项目名称:piano-maestoso,代码行数:27,代码来源:convert_videos.py

示例2: form_valid

# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import save [as 别名]
	def form_valid(self, form):

		f = self.request.FILES.get('file')
		file_type =  f.content_type.split('/')[0]
		self.object = form.save(commit=False)

		if file_type == 'image':
			self.object.type='image'
			p=Photo(image=f, title=f.name)
			p.save()
			self.object.photo=p
		elif file_type == 'audio':
			self.object.type='audio'
		elif file_type == 'video':
			self.object.type='video'
		else:
			self.object.type='other'
		
		self.object.slug=f.name
		# logger=getlogger()
		# logger.debug(file_type)	
		# logger.debug('-----------------------------------------------------------------------------------------------------------------')
		# logger.debug("type:" + form.fields['type'])	
		# logger.debug('-----------------------------------------------------------------------------------------------------------------')
		# logger.debug(file_type)
		
		self.object.realsave()
		# logger.debug()	

		data = [{'name': f.name, 'url': self.object.url, 'thumbnail_url': self.object.thumb_url, 'delete_url': reverse('upload-delete', args=[f.name]), 'delete_type': "DELETE"}]
		return JSONResponse(data)
开发者ID:zischwartz,项目名称:guidesly,代码行数:33,代码来源:views.py

示例3: save_model

# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import save [as 别名]
 def save_model(self, request, obj, form, change):
     files = {}
     if 'zipfile' in request.FILES :
         photolist = load_zip_file(request.FILES['zipfile'])
         files = photolist
     obj.save()
     photos = []
     for photo_name in files:
         if not verify_image(files[photo_name]):
             continue
         title = self.get_title(obj, photo_name)
         slug = self.get_slug(obj, photo_name)
         tags = self.get_tags(photo_name)
         photo = Photo(title=title,
            title_slug=slug,
            caption=title,
            is_public=obj.is_public,
            tags=tags)
         photo.image.save(photo_name, ContentFile(files[photo_name]))
         photo.save()
         photos.append(photo)
     cleaned_data = self.form.clean(form)
     for photo in photos:
         cleaned_data['photos'].append(photo)
     return obj
开发者ID:funvisis,项目名称:fvisgallery,代码行数:27,代码来源:admin.py

示例4: handle_uploaded_file

# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import save [as 别名]
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    
开发者ID:codesyntax,项目名称:cssocialprofile,代码行数:10,代码来源:load_images.py

示例5: handle_uploaded_file

# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import save [as 别名]
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
开发者ID:codesyntax,项目名称:bitakora,代码行数:13,代码来源:images.py

示例6: get_image_from_url

# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import save [as 别名]
def get_image_from_url(data):
    try:
        image = Photo.objects.get(slug=data['slug'])
    except Photo.DoesNotExist:
        url = data.pop('image', None)
        name, file = get_serialized_image(url)
        del data['sites']
        image = Photo(**data)
        image.image.save(name, file, save=True)
        image.save()
    return image
开发者ID:portalop,项目名称:django-opress,代码行数:13,代码来源:serializers.py

示例7: handle_url_file

# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import save [as 别名]
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
开发者ID:codesyntax,项目名称:bitakora,代码行数:15,代码来源:images.py

示例8: uploadimagejson

# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import save [as 别名]
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))
开发者ID:emakarov,项目名称:blog-wl-school,代码行数:15,代码来源:views.py

示例9: clean_new_image

# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import save [as 别名]
 def clean_new_image(self):
     """Let's take the uploaded image, create a new photo and bind to 
     the image field in model"""
     rand_int = random.randint(1,99)
     if self.cleaned_data['image']:
         image = self.cleaned_data['image']
         if self.cleaned_data['new_image']:                
             image.image = self.cleaned_data['new_image']
             image.save()
         self.cleaned_data['image'] = image
     else:
         new_photo = Photo(image=self.cleaned_data['new_image'],
                       title= "%s %s %s" %(self.cleaned_data['title'], self.cleaned_data['seller'].user.username, rand_int),
                       title_slug = "%s_%s" %(self.cleaned_data['slug_url'], rand_int))
         new_photo.save()
         self.cleaned_data['image'] = new_photo
     return self.cleaned_data['image']
开发者ID:rasiel,项目名称:mibooklist,代码行数:19,代码来源:forms.py

示例10: import_folder

# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import save [as 别名]
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)
开发者ID:chenyi1976,项目名称:django-photologue,代码行数:48,代码来源:import_folder.py

示例11: clean_photo

# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import save [as 别名]
 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']
开发者ID:ygneo,项目名称:daguerro,代码行数:20,代码来源:forms.py

示例12: question_add

# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import save [as 别名]
def question_add(request):
    form = QuestionForm()

    if request.method == 'POST':
        file_photo = request.FILES['photo']
        form = QuestionForm(request.POST, request.FILES)
        photo = Photo(image=handle_uploaded_file(file_photo),
                      title=file_photo.name,
                      title_slug=slugify(file_photo.name),)
        photo.save()
        form.photo = photo
        if form.is_valid():
            form.user = request.user
            question = form.save()
            return redirect(question)

    return render_to_response(
                'question_add.html',
                {'form': form},
                context_instance=RequestContext(request))
开发者ID:amourino-sp,项目名称:django-poll,代码行数:22,代码来源:views.py

示例13: upload_image

# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import save [as 别名]
def upload_image(request, upload_path=None):
    form = ImageForm(request.POST, request.FILES)
    if form.is_valid():
        image = form.cleaned_data['file']
        if image.content_type not in ['image/png', 'image/jpg', 'image/jpeg', 'image/pjpeg']:
            return HttpResponse('Bad image format')

        try:
          gallery = Gallery.objects.get(title_slug='pages_photos')
        except:
          gallery = Gallery(
                title = 'Site Pages Photos',
                title_slug = 'pages_photos',
                is_public = False,
                description = 'System album for holding images added directly to the pages',
              )
          gallery.save()


        image_name, extension = os.path.splitext(image.name)
        m = md5.new(smart_str(image_name))
        image_name = '{0}{1}'.format(m.hexdigest(), extension)

        try:
          photo = Photo(image=image, title=image_name, title_slug = slugify(image_name), caption='')
        except:
          photo = Photo(image=image_name, title_slug = slugify(image_name), caption='')

        photo.save()
        gallery.photos.add(photo)
        image_url = photo.get_display_url()

        # Original Code
        m = md5.new(smart_str(image_name))
        hashed_name = '{0}{1}'.format(m.hexdigest(), extension)
        image_path = default_storage.save(os.path.join(upload_path or UPLOAD_PATH, hashed_name), image)
       # image_url = default_storage.url(image_path)
        return HttpResponse(json.dumps({'filelink': image_url}))
    return HttpResponseForbidden()
开发者ID:simmol,项目名称:motus_website,代码行数:41,代码来源:views.py

示例14: upload_data

# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import save [as 别名]
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.'
开发者ID:shoreward,项目名称:EventPOI,代码行数:41,代码来源:tests.py

示例15: loadUrlImage

# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import save [as 别名]
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
开发者ID:aitzol,项目名称:csnews,代码行数:39,代码来源:load_images.py


注:本文中的photologue.models.Photo.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。