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


Python Item.name方法代码示例

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


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

示例1: commit_item_changes

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import name [as 别名]
 def commit_item_changes(self,item=None):
     creation=not(item)
     if not item: item=Item(parent=self.current_user.key())
     item_name=self.request.get('name')
     item_price=self.request.get('price')
     item_description=rich_text.from_style_runs(self.request.get('description'))
     item_picture=self.request.get('picture_512')
     errors=[]
     if item_name=="": errors.append("The item name must not be blank.")
     if item_description=="": errors.append("The item description must not be blank.")
     try:
         item_price=float(item_price)
     except ValueError:
         errors.append("The price must be a number.")
     if item_price <=0: errors.append("The price must be greater than zero.")
     if len(errors):
         self.render_template('items/form.html',title="Add an Item",item_picture_data=item_picture,item_picture=("data:image/png;base64,%s"%item_picture if item_picture or creation else item.url(named=False,action="picture")),errors=errors,item_expiry=datetime.now()+Item.EXPIRATION_DELTA,item_name=item_name,item_description=item_description,item_price=item_price)
     else:
         item.name=item_name
         item.price=item_price
         item.description=item_description
         if item_picture: item.picture=base64.b64decode(item_picture)
         item.put()
         self.log("item %s"%("created" if creation else "edited"))
         self.flash("'%s' was %s!"%(item_name,"created" if creation else "edited"))
         self.redirect(self.current_user.url())
开发者ID:maz,项目名称:saviors-of-middle-earth,代码行数:28,代码来源:items_controller.py

示例2: setUp

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import name [as 别名]
    def setUp(self):
        super(ItemApiTest, self).setUp()

        # Create a user.
        self.username = 'test_user'
        self.password = 'test_pass'
        self.user = User.objects.create_user(self.username, '[email protected]', self.password)
        
        # Create another user
        self.username2 = 'test_user2'
        self.password2 = 'test_pass2'
        self.user2 = User.objects.create_user(self.username2, '[email protected]', self.password2)

        item = Item()
        item.name = "Test Item #1"
        item.user = self.user
        item.notes = "testing..."
        item.save()
        self.item = item

        # Build a URI for the item
        self.detail_uri = '/api/v1/todo/{0}/'.format(self.item.pk)
        
        # ...as well as a URI to list all items
        self.list_uri = '/api/v1/todo/'

        # ...and URIs for each user
        self.user_uri = '/api/v1/user/{0}/'.format(self.user.pk)
        self.user2_uri = '/api/v1/user/{0}/'.format(self.user2.pk)

        # The data we'll send on POST requests.
        self.post_data = {
            'user': self.user_uri,
            'name': 'Test Item #2'
        }
        
        self.post_data2 = {
            'user': self.user2_uri,
            'name': 'Test Item #3'
        }
        

        # Expected test item JSON from server
        self.test_item_json = {
            'name': 'Test Item #1',
            'created': str(self.item.created),
            'notes': 'testing...',
            'due': None,
            'priority': 0,
            'done': False,
            'user': self.user_uri,
            'id': str(self.item.pk),
            'resource_uri': self.detail_uri 
        }
开发者ID:varunnaik,项目名称:Django-Test-Todolist,代码行数:56,代码来源:tests.py

示例3: add_item

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import name [as 别名]
def add_item(request):
    if request.POST:
        item = Item()
        item.name = request.POST['item_name']
        item.description = request.POST['description']
        item.seller = request.user
        item.save()
      #  url = reverse('add_auction', kwargs={ 'item_id': item.id })

        return HttpResponseRedirect(reverse('auction:add_auction', args=(item.id,)))
    return render(request, 'add_item.html', {})
开发者ID:kielejocain,项目名称:AM_2015_06_15,代码行数:13,代码来源:views.py

示例4: new_item

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import name [as 别名]
def new_item(category_id):
    """ Route that renders the page to add a new item.

    This method validate that the user is logged in.
    The item is associated with the current logged in user.

    Args:
        category_id: The id of the category of the item to be added.

    Raises:
        If an error occurs the application will redirect to index page and a flash message
        will be displayed with the proper Exception message.
    """
    try:
        logged_in = 'username' in login_session
        if not logged_in:
            flash("You must be logged to perform this operation", category="error")
            return redirect(url_for('index'))
        form = ItemForm()
        item = Item()
        item.name = "New item"
        if form.validate_on_submit():
            form.populate_obj(item)
            item.user_id = login_session["user_id"]
            db_session.add(item)
            if len(secure_filename(form.photo.data.filename)) > 0:
                db_session.flush()
                filename = 'images/uploads/' + str(item.id) + '/' + \
                           secure_filename(form.photo.data.filename)
                ensure_dir('static/' + filename)
                form.photo.data.save('static/' + filename)
                item.image_path = filename
                db_session.add(item)
            db_session.commit()
            flash("Item '{}' successfully added".format(item.name))
            return redirect(url_for('get_item_by_category', category_id=item.category_id,
                                    item_id=item.id))
        else:
            categories = db_session.query(Category).order_by(Category.name).all()
            return render_template('new_item.html', categories=categories,
                                   active_category=int(category_id), item=item, form=form,
                                   logged_in=logged_in, login_session=login_session)
    except Exception as e:
        flash('An error has occurred: {}'.format(str(e)), 'error')
        return redirect(url_for('index'))
开发者ID:aristoteles-nunez,项目名称:Item-Catalog,代码行数:47,代码来源:app.py

示例5: add_item

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import name [as 别名]
def add_item(listid):
    new_item = Item()
    dit = parse_amz(request.form['link'])
    print dit
    new_item.name = request.form['name']
    new_item.image_url = dit['image_url']
    new_item.amazon_link = request.form['link']
    new_item.note = request.form['notes']
    new_item.description = dit['description']
    s_list = mongo.db.lists.find_one({'_id': listid})
    item_count = s_list['item_count']
    new_item.id = item_count
    if item_count == 0:
        mongo.db.lists.update({'_id': listid}, {'$set': {'default_image': new_item.image_url}})
    item_count += 1
    mongo.db.lists.update({'_id': listid}, {'$push': {'items': new_item.__dict__}})
    mongo.db.lists.update({'_id': listid}, {'$set': {'item_count': item_count}})
    return redirect(url_for('get_list', listid=listid))
开发者ID:J-Katzen,项目名称:LV_Hack_List,代码行数:20,代码来源:visilist.py

示例6: newitem

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import name [as 别名]
def newitem(req):
    if req.method == "POST":
        ni = ItemForm(req.POST)
        if ni.is_valid():
            # 获取表单信息
            name = ni.cleaned_data['name']
            description = ni.cleaned_data['description']
            # 写入数据库
            item = Item()
            uid = req.session['user_id']
            item.name = name
            item.description = description
            item.uid = uid
            item.save()
            return HttpResponseRedirect('/online/index/')
    else:
        ni = ItemForm()
        return render_to_response('home.html', {'ni': ni}, context_instance=RequestContext(req))
开发者ID:sweetlipa,项目名称:album,代码行数:20,代码来源:views.py

示例7: save

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import name [as 别名]
    def save(self, request):
        "Process form and create DB objects as required"

        if self.instance:
            item = self.instance
        else:
            item = Item()
            item.item_type = self.item_type

        item.name = unicode(self.cleaned_data['name'])
        item.parent = self.cleaned_data['parent']
        item.status = self.cleaned_data['status']
        item.manufacturer = self.cleaned_data['manufacturer']
        item.supplier = self.cleaned_data['supplier']
        item.owner = self.cleaned_data['owner']
        item.location = self.cleaned_data['location']
        item.asset = self.cleaned_data['asset']

        if not item.id:
            item.set_user_from_request(request)
        item.save()
        if self.instance:
            item.itemvalue_set.all().delete()
        for field in item.item_type.fields.all():
            for form_name in self.cleaned_data:
                if re.match(str("^" + field.name + "___\d+$"), form_name):
                    value = None
                    if isinstance(self.fields[form_name], forms.FileField):
                        value = ItemValue(field=field, item=item,
                                          value=self._handle_uploaded_file(form_name))
                        if isinstance(self.fields[form_name], forms.ImageField):
                            self._image_resize(value.value)
                    else:
                        if field.field_type == 'picture' and isinstance(self.fields[form_name], forms.ChoiceField) and\
                                        self.cleaned_data[form_name] != 'delete':
                            value = ItemValue(field=field, item=item, value=self.cleaned_data[form_name])
                        else:
                            value = ItemValue(field=field, item=item, value=self.cleaned_data[form_name])
                    if value:
                        if not value.value:
                            value.value = ''
                        value.save()

        return item
开发者ID:tovmeod,项目名称:anaf,代码行数:46,代码来源:forms.py

示例8: add_inventory_item_html

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import name [as 别名]
def add_inventory_item_html(form):
    name = form.name.data.strip()
    description = form.description.data.strip()
    quantity = form.quantity.data
    price = form.price.data

    item = Item.query.filter_by(name=name).first()
    if item is None:
        item = Item(name=name, description=description, quantity=quantity,
                    price=price)
        db.session.add(item)
    else:
        item.name = name
        item.quantity = quantity
        item.price = price
        if description != "":
            item.description = description
    db.session.commit()
    return True
开发者ID:deveshj4,项目名称:tol,代码行数:21,代码来源:inventory_helper.py

示例9: add_inventory_item_json

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import name [as 别名]
def add_inventory_item_json(data):
    name = data['name']
    description = data['description']
    quantity = int(data['quantity'])
    price = int(data['price'])

    item = Item.query.filter_by(name=name).first()
    if item is None:
        item = Item(name=name, description=description, quantity=quantity,
                    price=price)
        db.session.add(item)
    else:
        item.name = name
        item.quantity = quantity
        item.price = price
        if description != "":
            item.description = description
    db.session.commit()
    return jsonify(status="success")
开发者ID:deveshj4,项目名称:tol,代码行数:21,代码来源:inventory_helper.py

示例10: item_edit

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import name [as 别名]
def item_edit(id=None):
    if id:
        item = Item.query.get_or_404(id)
        related = ', '.join(i.id for i in item.related)
        if not related == '':
            related += ', '

    else:
        item = Item()
        # The following attributes are needed to show this dummy-item
        item.count = 1
        item.name = ''
        related = ''

    itemlist = Item.query.all()
    itemlist = ' '.join(i.id for i in itemlist)

    # Require form
    if request.method == 'GET':
        return pjax('create_item.html', item=item, itemlist=itemlist, related=related)
开发者ID:Hobbyhobbit,项目名称:Stock,代码行数:22,代码来源:views.py

示例11: post

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import name [as 别名]
	def post(self):
		#Getting Inputs
		itemname=self.request.get("item_name")
		itemtype=self.request.get("item_type")
		itemdescription=self.request.get("item_description")
		itemprice=self.request.get("item_price")
		itemstock=self.request.get("item_stock")
		
		
		#Placing data in model
		item=Item()
		item.name=itemname
		item.type=itemtype
		item.description=itemdescription
		item.price=itemprice
		item.stock=itemstock
		item.owner=users.get_current_user().email()
		
		item.put()
		self.redirect('success')
开发者ID:Joshdsommers,项目名称:TeamZero,代码行数:22,代码来源:item_input.py

示例12: test_todo_item

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import name [as 别名]
 def test_todo_item(self):
     """Tests the todo item model"""
     # Does validation fail on an invalid item?
     item = Item()
     validatedSuccessfully = False
     try:
         item.full_clean()
     except ValidationError:
         validatedSuccessfully = True
         
     self.assertEquals(validatedSuccessfully, True)
     
     # Does validation pass on a valid item?
     item.name = "test"
     item.user = self.user
     validatedSuccessfully = True
     try:
         item.full_clean()
     except ValidationError:
         validatedSuccessfully = False
         
     self.assertEquals(validatedSuccessfully, True)
开发者ID:varunnaik,项目名称:Django-Test-Todolist,代码行数:24,代码来源:tests.py

示例13: create_hunt

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import name [as 别名]
def create_hunt(context):
    hunt = Hunt()
    hunt.name = uuid.uuid4().hex

    participant = Participant()
    participant.email = email()
    db.session.add(participant)
    db.session.commit()

    hunt.participants = [participant]

    item = Item()
    item.name = uuid.uuid4().hex
    db.session.add(item)
    db.session.commit()

    hunt.items = [item]
    hunt.admin_id = 1  # fresh db for each scenario

    db.session.add(hunt)
    db.session.commit()

    context.hunt = hunt
开发者ID:Saltbox,项目名称:mobile-scavenger-hunt,代码行数:25,代码来源:hunts.py

示例14: item_post

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


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