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


Python models.Photo类代码示例

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


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

示例1: form_valid

	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,代码行数:31,代码来源:views.py

示例2: _convert

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,代码行数:25,代码来源:convert_videos.py

示例3: save_model

 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,代码行数:25,代码来源:admin.py

示例4: setUp

 def setUp(self):
     super(ImageResizeTest, self).setUp()
     self.pp = Photo(title="portrait", title_slug="portrait")
     self.pp.image.save(os.path.basename(PORTRAIT_IMAGE_PATH), ContentFile(open(PORTRAIT_IMAGE_PATH, "rb").read()))
     self.pp.save()
     self.ps = Photo(title="square", title_slug="square")
     self.ps.image.save(os.path.basename(SQUARE_IMAGE_PATH), ContentFile(open(SQUARE_IMAGE_PATH, "rb").read()))
     self.ps.save()
开发者ID:ambitone,项目名称:django-photologue,代码行数:8,代码来源:resize.py

示例5: get_image_from_url

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,代码行数:11,代码来源:serializers.py

示例6: handle_url_file

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,代码行数:13,代码来源:images.py

示例7: clean_new_image

 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,代码行数:17,代码来源:forms.py

示例8: import_folder

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,代码行数:46,代码来源:import_folder.py

示例9: question_add

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,代码行数:20,代码来源:views.py

示例10: test_quoted_url

    def test_quoted_url(self):
        """Test for issue #29 - filenames of photos are incorrectly quoted when
        building a URL."""

        # Check that a 'normal' path works ok.
        self.assertEquals(self.pl.get_testPhotoSize_url(), self.pl.cache_url() + "/test_landscape_testPhotoSize.jpg")

        # Now create a Photo with a name that needs quoting.
        self.pl2 = Photo(title="test", title_slug="test")
        self.pl2.image.save(os.path.basename(QUOTING_IMAGE_PATH), ContentFile(open(QUOTING_IMAGE_PATH, "rb").read()))
        self.pl2.save()
        self.assertEquals(self.pl2.get_testPhotoSize_url(), self.pl2.cache_url() + "/test_%26quoting_testPhotoSize.jpg")
开发者ID:rochapps,项目名称:django-photologue,代码行数:12,代码来源:photo.py

示例11: loadUrlImage

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      
开发者ID:aitzol,项目名称:gamerauntsia,代码行数:40,代码来源:images.py

示例12: upload_data

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,代码行数:39,代码来源:tests.py

示例13: upload_image

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,代码行数:39,代码来源:views.py

示例14: handle_uploaded_file

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,代码行数:8,代码来源:load_images.py

示例15: handle_uploaded_file

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,代码行数:11,代码来源:images.py


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