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


Python Item.get_by_id方法代码示例

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


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

示例1: admin_item_edit

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import get_by_id [as 别名]
def admin_item_edit(request, id=None):
    item = id and Item.get_by_id(int(id)) or None

    if request.POST:
        form = FormItem(request.POST, files=request.FILES, instance=item)

        if form.is_valid():
            item = form.save(False)
            
            if form.cleaned_data.get('file_to_upload', None):
                # Get image to field file
                img = db.Blob(form.cleaned_data['file_to_upload'].read())
                item.file = img

                # Builds image thumbnail
                item.thumb = images.resize(img, 120, 120)

                item.mimetype = form.cleaned_data['file_to_upload'].content_type

            item.save()

            return HttpResponseRedirect(item.get_absolute_url())
    else:
        form = FormItem(instance=item)

    return locals()
开发者ID:BrianPainter,项目名称:geraldo,代码行数:28,代码来源:views.py

示例2: post

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import get_by_id [as 别名]
    def post(self):
        key = int(self.request.get('key'))
        owner = int(self.request.get('owner'))
        cur_votes = int(self.request.get('cur_votes'))

        ret = increase_vote(Item.get_by_id(key), owner, cur_votes)

        self.response.out.write(ret)
开发者ID:ronhuang,项目名称:adieu,代码行数:10,代码来源:vote.py

示例3: admin_item_delete

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import get_by_id [as 别名]
def admin_item_delete(request, id=None):
    item = id and Item.get_by_id(int(id)) or None

    if not item:
        raise Http404

    item.delete()

    post_message(request, 'Item deleted.')

    return HttpResponseRedirect(reverse('gallery.views.admin_index'))
开发者ID:BrianPainter,项目名称:geraldo,代码行数:13,代码来源:views.py

示例4: get

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import get_by_id [as 别名]
 def get(self, item_key):
     food_key = int(item_key)
     item = Item.get_by_id(food_key)
     if item == None:
         self.response.out.write(simplejson.dumps({'result': 'not_exist', 'key': food_key}))
     else:
         food = {'key': food_key,
                 'title': item.title,
                 'description': item.description,
                 'owner': item.owner,
                 'date': item.date.strftime('%s'),
                 'votes': item.vote_set.count()}
         self.response.out.write(simplejson.dumps({'result': 'success', 'food': food}))
开发者ID:ronhuang,项目名称:adieu,代码行数:15,代码来源:item.py

示例5: post

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import get_by_id [as 别名]
  def post(self):
    url = urlfetch.fetch(self.request.get('content'))
    doc = lxml.html.fromstring(url.content)

    for sku in doc.cssselect('span'):
      if sku.get('id') == 'displaySkuCode':
        item_id = sku.text

    registry_item = Item.get_by_id(item_id)
    if registry_item is None:
      registry_item = Item(id=item_id, parent=ndb.Key("Website", self.request.get('website')))

    for tag in doc.cssselect('title'):
      registry_item.title = tag.text.encode('utf-8')

    for img in doc.cssselect('link'):
      if img.get('rel') == 'image_src':
        registry_item.img = img.get('href')

    for price in doc.cssselect('div'):
      if price.get('class') == 'sale-price':
        for savings in price.cssselect('strong'):
          registry_item.sale = savings.text.encode('utf-8')
      if price.get('class') == 'reg-price':
        registry_item.price = price.text.encode('utf-8').replace("Reg.", "")
    
    registry_item.category = self.request.get('category')
    registry_item.for_who = self.request.get('for_who')
    registry_item.put()

    link = URL.get_by_id(item_id)
    if link is None:
      link = URL(id=item_id, parent=ndb.Key("Website", self.request.get('website')))
    link.url = self.request.get('content')
    link.last_scrape = datetime.datetime.now()
    link.put()

    self.redirect('/listings')
开发者ID:tonycorp,项目名称:marinaregistry,代码行数:40,代码来源:scraper.py

示例6: get_item_from_rank

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import get_by_id [as 别名]
def get_item_from_rank():
    resp = Resp()
    rank_id = request.args.get("rank_id", None)
    tag_name = request.args.get("tag_name", None)

    item_ids_from_rank = ItemRank.query.with_entities("item_id").filter_by(
        rank_id=rank_id
    ).all()
    if tag_name:
        tag = Tag.get_by_name(tag_name).first()
    if tag:
        item_ids_from_tag = ItemTag.query.with_entities("item_id").filter_by(
            tag_id=tag.id
        ).all()
    else:
        item_ids_from_tag = []
    item_ids = list(set(item_ids_from_rank) & set(item_ids_from_tag))
    result = []
    for item_id in item_ids:
        item = Item.get_by_id(item_id)
        result.append(item)
    resp.data = result
    return resp
开发者ID:i19,项目名称:tagger,代码行数:25,代码来源:web.py


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