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


Python Image.put方法代码示例

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


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

示例1: post

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import put [as 别名]
    def post(self):
        "Upload via a multitype POST message"

        img = self.request.get("img")
        # if we don't have image data we'll quit now
        if not img:
            self.redirect("/")
            return
        try:
            width = int(self.request.get("width"))
            hight = int(self.request.get("height"))
        except ValueError:
            image_content = img
        else:
            image_content = images.resize(img, width, height)

        original_content = img

        thumb_content = images.resize(img, 100, 100)

        image = Image()

        image.image = db.Blob(image_content)

        image.original = db.Blob(original_content)
        image.thumb = db.Blob(thumb_content)
        image.user = users.get_current_user()
        image.put()
        self.redirect("/")
开发者ID:jakobholmelund,项目名称:appengine-image-host,代码行数:31,代码来源:backend.py

示例2: test_create_image

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import put [as 别名]
 def test_create_image(self):
     i = Image(slug="broom", icon_set="fugue", path="icons/fugue/broom.png")
     i.put()
     self.assertEquals(i.slug, "broom")
     self.assertEquals(i.icon_set, "fugue")
     self.assertEquals(i.path, "icons/fugue/broom.png")
     self.assertEquals(i.absolute_url(), "/images/icons/fugue/broom.png")
开发者ID:JohnMurray,项目名称:stashboard,代码行数:9,代码来源:test_images.py

示例3: post

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import put [as 别名]
    def post(self, user, account, group_id):
        group = get_image_group_or_404(self, group_id)

        # FIXME: admins!
        if group.owner.key() != account.key():
            return render_json_response(self, {"error": "access-denied"})

        file_name = self.request.headers["X-File-Name"]
        data = self.request.body

        mime_type = mimetypes.guess_type(file_name)[0]
        if not mime_type.startswith("image/"):
            return render_json_response(self, {"error": "wrong-file-type"})

        img = images.Image(data)

        imgdata = ImageData(data=data)
        imgdata.put()

        image = Image(
            file_name=file_name,
            width=img.width,
            height=img.height,
            mime_type=mime_type,
            group=group,
            data=imgdata,
            digest=hashlib.sha1(data).hexdigest(),
        )
        image.put()

        memcache.delete(group.memcache_key())

        return render_json_response(self, {"name": image.file_name})
开发者ID:andreyvit,项目名称:mockko,代码行数:35,代码来源:handlers.py

示例4: upload

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import put [as 别名]
def upload():
    with open('data.csv') as f:
        reader = csv.DictReader(f)
        for row in reader:
            try:
                s = Store()
                
                print row['name'], row['images'], row['types']
                if re.search("\[.*\]", row['reference']):
                    row['place_id'] = row['scope']
                    row['scope'] = row['latlng']
                    row['latlng'] = row['address']
                    row['address'] = row['photos']
                    row['photos'] = row['reference']

            

                print row['name'], row['images'], row['types']
                s.tags = json.loads(row['types'])
                s.point = db.GeoPt(*eval(row['latlng']))
                s.reference = row['reference'] and row['reference'][0] or ""
                s.address = row['address']
                s.name = row['name']

                
                for img in eval(row['images']):
                    image = Image()
                    image.image = img
                    image.put()
                    s.imgs.append(image)
            except Exception as e:
                pass
            finally:
                s.put()
开发者ID:georgefs,项目名称:ezselector,代码行数:36,代码来源:scripts.py

示例5: setUp

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import put [as 别名]
 def setUp(self):
     super(StatusInstanceTest, self).setUp()
     image = Image(icon_set="fugue", slug="cross-circle",
                   path="fugue/cross-circle.png")
     image.put()
     self.status = Status(name="Foo", slug="foo", description="bar", 
         image="cross-circle")
     self.status.put()
开发者ID:2do,项目名称:stashboard,代码行数:10,代码来源:test_rest_status.py

示例6: execute

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import put [as 别名]
    def execute(self):
        image = Image()
        image.image_key = self.image_key
        image.put()

        invite = Invite.get_by_unique_id(self.unique_id)
        invite.poster_picture = image.key
        invite.put()
        return invite.poster_picture.urlsafe()
开发者ID:xplot,项目名称:imeet,代码行数:11,代码来源:UpdateInviteCoverImageCommand.py

示例7: post

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import put [as 别名]
    def post(self):
        album_key = ndb.Key(urlsafe=self.request.get('key'))
        upload_files = self.get_uploads()  # 'file' is file upload field in the form
        blob_info = upload_files[0]
        photo = Image(parent=album_key, image_blob=blob_info.key(), index=1)
        photo.populate(serving_url=images.get_serving_url(blob_info.key()))
        photo.put()

        self.redirect('/add-album?key=%s' % album_key.urlsafe())
开发者ID:IanChilds,项目名称:ButtonsAndLace,代码行数:11,代码来源:add_photo.py

示例8: SaveAndPackImage

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import put [as 别名]
def SaveAndPackImage(response, data, recipe=None):
    img = Image()
    img.data = db.Blob(data)
    if recipe != None:
        img.recipe = recipe
    img.put()

    response.headers["Content-Type"] = "text/javascript"
    response.out.write(simplejson.dumps(img.to_dict()))
开发者ID:ben,项目名称:magrecipes,代码行数:11,代码来源:ImageHandler.py

示例9: post

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import put [as 别名]
    def post(self):
      "Upload via a multitype POST message"
      if self.request.get('img'):
        try:
          # check we have numerical width and height values
          width = int(self.request.get("width"))
          height = int(self.request.get("height"))
        except ValueError:
          # if we don't have valid width and height values
          # then just use the original image
          image_content = google.appengine.api.images.resize(self.request.get("img"), 
          IMAGE_WIDTH, IMAGE_HEIGHT)
          thumb_content = google.appengine.api.images.resize(self.request.get("img"), 100, 100)
        else:
            # if we have valid width and height values
            # then resize according to those values
            image_content = google.appengine.api.images.resize(self.request.get("img"), width, height)
            # always generate a thumbnail for use on the admin page
            thumb_content = google.appengine.api.images.resize(self.request.get("img"), 100, 100)
      else:
        image_content = None
        if not self.request.get('key'):
          logging.critical('No key and no image! Cannot save image.')
          return self.redirect('/admin')

      # check if image is being edited
      if self.request.get('key'):
        image = db.get(self.request.get("key"))
        if self.request.get('position'):
          import datetime
          position = int(self.request.get('position'))
          images = imageQuery().fetch(100)
          offset_image = images.pop(position- 1)
          if position == 1: 
            time_offset = -datetime.timedelta(milliseconds=10)
          else:
            time_offset = datetime.timedelta(milliseconds=10)
          if not offset_image.key() == image.key(): 
            image.date = offset_image.date + time_offset
                
      else:
      # create the image object
        image = Image()
        image.user = users.get_current_user()
      image.title = self.request.get('title')
      if image_content:
      # and set the properties to the relevant values
        image.image = db.Blob(image_content)
        # we always store the original here in case of errors
        # although it's currently not exposed via the frontend
        image.thumb = db.Blob(thumb_content) 
              
      # store the image in the datasore
      image.put()
      # and redirect back to the admin page
      self.redirect('/admin')
开发者ID:jamslevy,项目名称:portfolio,代码行数:58,代码来源:admin.py

示例10: post

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import put [as 别名]
    def post(self):
        " Post to blobstore, create Image object and redirect to info URL. "
        upload_files = self.get_uploads("file")
        blob_info = upload_files[0]

        img = Image(title=self.request.POST.get("title", ""), image=blob_info)
        img.put()

        upload_url = urllib.quote(blobstore.create_upload_url("/%s/upload" % IMAGE_APP_PATH))
        self.response.set_status(303)
        self.redirect("/%s/upload?key=%s&newurl=%s" % (IMAGE_APP_PATH, urllib.quote(str(img.key())), upload_url))
开发者ID:mentat,项目名称:imageapp,代码行数:13,代码来源:views.py

示例11: put_image

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import put [as 别名]
 def put_image(self, submitter, url, tags):
     DEBUG('put_image: %s (%s)' % (url, tags))
     exists = self.get_image_by_url(url)
     ltags = [tag.lower() for tag in tags]
     if exists:
         DEBUG('found existing %s' % img)
         for image in exists:
             image.tags.extend([tag for tag in ltags if tag not in image.tags])
             image.put()
     else:
         image = Image(url=url, tags=ltags, submitter=submitter)
         image.put()
开发者ID:dforsyth,项目名称:gif-wrappy,代码行数:14,代码来源:wrappy.py

示例12: post

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import put [as 别名]
 def post(self,subdomain=None):
     product_id=self.request.get("product_id")
     upload_files = self.get_uploads('file')  # 'file' is file upload field in the form
     blob_info = upload_files[0]  
     for i in range(0,5):
         count = Image.gql("WHERE __key__=KEY('Image','%s-%s') LIMIT 1" % (product_id,i)).count()
         if count == 0:
             image = Image(blob_key=str(blob_info.key()),key_name='%s-%s' %(product_id, i),user=subdomain)
             image.put()
             self.redirect('/serve/%s-%s' % (product_id,i))
             break;
     self.response.out.write('Maximum number of images for this product id, please delete one before uploading.'),
开发者ID:itaogit,项目名称:shopapp,代码行数:14,代码来源:handlers.py

示例13: post

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import put [as 别名]
 def post(self):
     "Upload via a multitype POST message"
     
     try:
         # check we have numerical width and height values
         width = int(self.request.get("width"))
         height = int(self.request.get("height"))
     except ValueError:
         # if we don't have valid width and height values
         # then just use the original image
         image_content = self.request.get("img")
     else:
         # if we have valid width and height values
         # then resize according to those values
         image_content = images.resize(self.request.get("img"), width, height)
     
     # get the image data from the form
     original_content = self.request.get("img")
     # always generate a thumbnail for use on the admin page
     thumb_content = images.resize(self.request.get("img"), 100, 100)
     
     # create the image object
     image = Image()
     # Try and create an s3 connection
     if len(awskeys.AWS_ACCESS_KEY_ID) > 0 and len(awskeys.AWS_SECRET_ACCESS_KEY) > 0:
         s3 = GoogleS3.AWSAuthConnection(awskeys.AWS_ACCESS_KEY_ID, awskeys.AWS_SECRET_ACCESS_KEY)
     else:
         s3 = None
     
     # and set the properties to the relevant values
     image.image = db.Blob(image_content)
     image.user = users.get_current_user()
     
     if s3 is None:
         # we always store the original here in case of errors
         # although it's currently not exposed via the frontend
         image.original = db.Blob(original_content)
         image.thumb = db.Blob(thumb_content)
         # store the image in the datasore
         image.put()
     else:
         # we want to store in S3, so store the data and use the key
         image.put()
         # Put the 3 different images
         s3.put(awskeys.BUCKET_NAME,str(image.key()) + "_original",original_content)
         s3.put(awskeys.BUCKET_NAME,str(image.key()) + "_thumb",thumb_content)
         s3.put(awskeys.BUCKET_NAME,str(image.key()) + "_image",image_content)
             
     
     # and redirect back to the admin page
     self.redirect('/')
开发者ID:saratpediredla,项目名称:appengine-image-host,代码行数:53,代码来源:backend.py

示例14: sendmessage

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import put [as 别名]
def sendmessage():
    """
    phones = Phone.all()
    regIds = [phone.phone_id for phone in phones]
    data = dict()
    data['title'] = 'me'
    data['post'] = '123'
    dataToSend = dict()
    dataToSend['registration_ids'] = regIds
    dataToSend['data'] = data
    response = Response(json.dumps(dataToSend),mimetype='application/json')
    response.headers.add('Content-Type','application/json')
    response.headers.add('Authorization','key=AIzaSyBsBuZuPlRkt45QstSJ_qaHC7_e1NFEIZU')
    #return response

    headers = MultiDict()
    headers['Content-Type'] = 'application/json'
    headers['Authorization'] = "key=AIzaSyBsBuZuPlRkt45QstSJ_qaHC7_e1NFEIZU"
    req = urllib2.Request("https://android.googleapis.com/gcm/send", json.dumps(dataToSend), headers)
    f = urllib2.urlopen(req)
    responseMsg = f.read()
    f.close()
    return responseMsg;
    return json.dumps(dataToSend, sort_keys=True, indent=4)
    """
    data = MultiDict()
    f = request.form
    for key in f.keys():
        data[key] = f[key]

    files = request.files.getlist('upload')

    titleMsgHash = data['title'] + data['post']# + chr(random.randrange(97,97+26+1))
    titleMsgHash = getHash(titleMsgHash)

    currentPost = Post(key_name=titleMsgHash,title=data['title'],msg=data['post'])
    currentPost.put()
    base64Strings = []
    i = 0
    for file in files:
        #file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))
        fileString = file.read()
        image64String = fileString.encode("base64")
        imageKeyName = data['title']+data['post']+'image'+str(i)
        tmpImage = Image(key_name=getHash(imageKeyName),encoded_string=image64String,post_id=currentPost.key())
        tmpImage.put()
        i = i+1

    logging.debug('reached end')
    return jsonify(data)
开发者ID:lolyzor,项目名称:pushnotifications-server,代码行数:52,代码来源:main.py

示例15: post

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import put [as 别名]
    def post(self, album_id):
        """POST handler for a gallery image.

        URL pattern: /albums/${album_id}/images
        POST data must be of type multipart/form and contain image as 'file'.
        POST data must also contain image metadata: 'name'.
        Image filename must include an extension.

        Returns 201 CREATED with JSON data structure describing new image.
        Returns Content-type: application/json.
        Also returns Location header pointing to API URL for image details.

        Include 'wrapjson' parameter in POST to wrap returns JSON in
        a <textarea>. This also changes the returned Content-type to text/html.

        If album doesn't exist, returns 404 NOT FOUND.
        If request is poorly formatted returns 400 BAD REQUEST.

        Returns 401 UNAUTHORIZED to all calls if authorization fails.
        """
        q = Album.all().filter('album_id =', album_id)
        album = q.get()
        if not album:
            return self.error(404)

        try:
            data = dict(((str(k), v) for k, v in self.request.POST.items()))
            if 'file' in data:
                data['extension'] = data['file'].filename.split('.')[-1].lower()
                if data['extension'] == data['file'].filename:
                    data['extension'] = ''
                else:
                    data['extension'] = '.' + data['extension']
                data['image_data'] = data['file'].file.read()

            image = Image(image_id=config.IMAGE_ID_GENERATOR(),
                          album=album,
                          **data)
        except:
            data = {}
            self.error(400)
        else:
            if not config.DEMO_MODE:
                image.put()

            data = image.to_dict()
            self.response.headers['Location'] = data['url']
            self.response.set_status(201)

        write_json(self, data, wrapjson='wrapjson' in self.request.POST)
开发者ID:chosak,项目名称:restful-gallery,代码行数:52,代码来源:app.py


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