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


Python Item.category方法代码示例

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


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

示例1: post

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import category [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

示例2: item_post

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import category [as 别名]
def item_post(id=None):
    db.session.rollback() # See comment in create_transaction()
    if id:
        itm = Item.query.get_or_404(id)
    else:
        id = make_url_safe(request.form.get('name'))
        itm = Item(id=id)
        db.session.add(itm)
        
    itm.name = request.form.get('name')
    itm.description = request.form.get('description')
    itm.count = int(request.form.get('count')) if request.form.get('count') else 1

    itm.tax_base_int = request_or_none('tax_base_int')
    itm.tax_base_edu = request_or_none('tax_base_edu')
    itm.tax_base_ext = request_or_none('tax_base_ext')
    itm.tax_int = request_or_none('tax_int')
    itm.tax_edu = request_or_none('tax_edu')
    itm.tax_ext = request_or_none('tax_ext')


    itm.related = []
    for iid in request.form.get('related').split(', '):
        if iid == '':
            continue
        i = Item.query.get(iid)
        if i is None:
            flash(u'Artikel "%s" ist nicht bekannt!' % ii )
            continue
        itm.related.append(i)

    itm.tax_period = request.form.get('tax_period')

    itm.price_buy = request_or_none('price_buy')

    itm.category = request.form.get('category')

    db.session.commit()

    # Update image if necessary
    file = request.files['image']
    if file:
        import os
        from PIL import Image as i
        filename = secure_filename(id).lower() + '.jpg'

        image = i.open(file)
        if image.mode != "RGB":
            image = image.convert("RGB")

        image.save(os.path.join(app.config['UPLOAD_FOLDER'], 'full', filename), "jpeg")

        w  = image.size[0]
        h = image.size[1]

        aspect = w / float(h)
        ideal_aspect = 1.0

        if aspect > ideal_aspect:  # Then crop the left and right edges:
            w_ = int(ideal_aspect * h)
            offset = (w - w_)/2
            resize = (offset, 0, w - offset, h)
        else:  # ... crop the top and bottom:
            h_ = int(w/ideal_aspect)
            offset = (h - h_)/2
            resize = (0, offset, w, h - offset)

        image = image.crop(resize).resize((140, 140), i.ANTIALIAS)
        image.save(os.path.join(app.config['UPLOAD_FOLDER'], filename), "jpeg")

    return redirect( url_for('item', id=id) )
开发者ID:Hobbyhobbit,项目名称:Stock,代码行数:73,代码来源:views.py

示例3: post

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import category [as 别名]
    def post(self):

        form = AddItemForm()
        item = Item()

        categories = Category.objects.all()
        licenses = License.objects.all()
        form.set_categories(categories, g.lang)
        form.set_licenses(licenses)

        if form.validate_on_submit():
            # first, the user has to share something !
            if not form.github.data and not form.files.data:
                flash('Neither a repo URL nor files has been shared, come on!',
                      category='alert')
                return render_template('items/add_item.html', form=form)

            # give that something at least one title
            if not form.ar_title.data and not form.fr_title.data and \
               not form.en_title.data:

                flash('You need to give this item at least one title, \
                       just pick one language and name it!',
                      category='alert')
                return render_template('items/add_item.html', form=form)

            # now we can proceed
            ar_title = Title()
            fr_title = Title()
            en_title = Title()

            ar_title.title = form.ar_title.data.strip()
            ar_title.lang = 'ar'

            fr_title.title = form.fr_title.data.strip()
            fr_title.lang = 'fr'

            en_title.title = form.en_title.data.strip()
            en_title.lang = 'en'

            item.titles.append(ar_title)
            item.titles.append(fr_title)
            item.titles.append(en_title)

            item.description = form.description.data
            item.tags = form.tags.data.strip().split(',')
            item.category = Category.objects.get(category_id=
                                                 int(form.category.data))

            item.submitter = User.objects.get(id=current_user.id)

            thumbnail = request.files['thumbnail']
            thumbnail_name = secure_filename(thumbnail.filename)

            if thumbnail and allowed_thumbnails(thumbnail_name):
                ext = thumbnail.mimetype.split('/')[-1]
                # use the 'thumbnail' name for all thumbnails
                filename = '.'.join(["thumbnail", ext])
                item.thumbnail.put(thumbnail.stream,
                                   content_type=thumbnail.mimetype,
                                   filename=filename)

            if form.github.data:
                item.github = form.github.data
                item.save()
                # no need to process any uploaded files
                flash('Item submitted successfully', category='success')
                return redirect(url_for('items.detail', item_id=item.item_id))
            else:
                item.license = License.objects.get(license_id=
                                                   int(form.license.data))

        else:
            flash('upload unsuccessful', category='error')
            return render_template('items/add_item.html', form=form)

        uploaded_files = request.files.getlist("files")
        for file in uploaded_files:
            # Make the filename safe, remove unsupported chars
            filename = secure_filename(file.filename)
            # Check if the file is one of the allowed types/extensions
            if file and allowed_file(filename):
                # put the file in the ListField.
                # see https://gist.github.com/tfausak/1299339
                file_ = GridFSProxy()
                file_.put(file.stream,
                          content_type=file.mimetype,
                          filename=filename)
                item.files.append(file_)
        # Save the thing
        item.save()
        flash('Item uploaded successfully', category='success')
        return redirect(url_for('items.detail', item_id=item.item_id))
开发者ID:mohamed-io,项目名称:dzlibs,代码行数:95,代码来源:views.py


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