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


Python ItemForm.save方法代码示例

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


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

示例1: edit_item

# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import save [as 别名]
def edit_item(request, item_id, cat_id):
    message = ""
    item = Item.objects.get(ref=item_id, category__id=cat_id)
    FieldSet = inlineformset_factory(Item, Field, form=FieldForm, fields=('key','value','modified'), can_delete=False, extra=0)
    if request.method == 'POST':
        item_form = ItemForm(request.POST, instance=item)
        form = FieldSet(request.POST, instance = item)
        if item_form.is_valid() and form.is_valid():
            item_form.save()
            form.save()
            # Re-make the form with the item from the database so
            # that `modified` is set if it was changed
            item = Item.objects.get(ref=item_id, category__id=cat_id)
            form = FieldSet(instance=item)
            item_form = ItemForm(instance=item)
            message = "Item successfully saved."
            if item.verified and item.category.source_file_type and item.category.collection:
                if item.fields.filter(key="name").exists():
                    name = item.fields.get(key="name").value
                else:
                    name = item.ref
                document = docserver_create_document(item.category.collection.collectionid,
                                                     item.ref,
                                                     name)
                docserver_upload_and_save_file(document.id,
                                               item.category.source_file_type.id,
                                               ContentFile(item.to_json()))
                message += " SourceFile uploaded."
    else:
        item_form = ItemForm(instance=item)
        form = FieldSet(instance = item)
    return render(request, 'kvedit/edit.html', {'item_form':item_form, 'form': form, 'item': item, "message": message})
开发者ID:frixid,项目名称:dunya,代码行数:34,代码来源:views.py

示例2: create_stories

# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import save [as 别名]
def create_stories(request):
	if request.POST:
		for f in request.FILES.getlist('i_path'):
			print request.FILES
			form = ItemForm(request.POST, {'i_path': f})
			if form.is_valid():
				form.save()
		
		return HttpRespondeRedirect('/complete')
	else:
		form = ItemForm()
		args = {}
		args.update(csrf(request))
		args['form'] = form
		return render(request,"create_stories.html",args)
开发者ID:valehelle,项目名称:venv,代码行数:17,代码来源:views.py

示例3: item_add

# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import save [as 别名]
def item_add(request):
    if request.method == 'POST':
        form = ItemForm(request, request.POST, request.FILES, prefix="item")
        if form.is_valid():
            item = form.save(commit=False)
            item.shop = request.shop
            item.save()
            item.update_latest_item()
            for img in request.FILES.getlist('file'):
                image = ImageItem()
                image.item = item
                image.image.save(img.name,img)
            request.flash['message'] = unicode(_("Item successfully added."))
            request.flash['severity'] = "success"
            return HttpResponseRedirect(reverse('inventory_items'))
    else:
        form = ItemForm(request, prefix="item")
    form_category = MarketCategoryForm(prefix="category")
    form_sub_category = MarketSubCategoryForm(request, prefix="sub_category")
    form_session = AuctionSessionForm(prefix="session")
    sessions = AuctionSession.objects.filter(shop = request.shop)
    return render_to_response('store_admin/inventory/item_add.html', 
                              {'form': form,
                               'form_category': form_category,
                               'form_sub_category': form_sub_category,
                               'form_session': form_session,
                               'sessions': sessions,
                               },
                              RequestContext(request))
开发者ID:MechanisM,项目名称:CollectorCity-Market-Place,代码行数:31,代码来源:views.py

示例4: createItem

# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import save [as 别名]
def createItem(request):
    if request.POST:
        form = ItemForm(request.POST, request.FILES)
        if form.is_valid():
            # do not save yet, and add in default owners_id
            obj = form.save(commit=False)
            # add in the creator's id
            obj.owners = request.user
            # add item status
            obj.status = "Not Sold"
            # save data
            obj.save()

            return HttpResponseRedirect("/web/main/")
    else:
        form = ItemForm()

    args = {}
    args.update(csrf(request))

    args["form"] = form
    args["notifications"] = Notifications.objects.filter(requestedTo=request.user, state="Pending")
    args["notifications_count"] = args["notifications"].count()
    args["transactions"] = Notifications.objects.filter(requestedFrom=request.user).order_by("item", "-bid")
    args["transactions_count"] = args["transactions"].count()
    args["online_user"] = request.user

    return render_to_response("createItem.html", args)
开发者ID:sachaudh,项目名称:Destiny,代码行数:30,代码来源:views.py

示例5: create_item

# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import save [as 别名]
def create_item(request):
    """
    @param request:
    @param id:
    @return: JSON for account for added Inventory Item
    """
    item = Item(purchase_account=Account.objects.get(name='Purchase', company=request.company),
                sales_account=Account.objects.get(name='Sales', company=request.company),
                purchase_tax_scheme=TaxScheme.objects.get(name='No Tax', company=request.company),
                sales_tax_scheme=TaxScheme.objects.get(name='No Tax', company=request.company))
    scenario = 'Create'
    for query in request.GET:
        setattr(item, query, request.GET[query])
    if request.POST:
        form = ItemForm(data=request.POST, instance=item, company=request.company)
        if form.is_valid():
            item = form.save(commit=False)
            item.company = request.company
            item.save()
            if request.is_ajax():
                return render(request, 'callback.html', {'obj': InventoryAccountSerializer(item.account).data})
            return redirect('/inventory/items/')
    else:
        form = ItemForm(instance=item, company=request.company)
        form.hide_field(request)
    if request.is_ajax():
        base_template = 'modal.html'
    else:
        base_template = 'dashboard.html'
    return render(request, 'item_form.html', {
        'scenario': scenario,
        'form': form,
        'base_template': base_template,
    })
开发者ID:xtranophilist,项目名称:awecounting,代码行数:36,代码来源:views.py

示例6: item_form

# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import save [as 别名]
def item_form(request, id=None):
    if id:
        item = get_object_or_404(Item, id=id, company=request.company)
        scenario = 'Update'
    else:
        item = Item(purchase_account=Account.objects.get(name='Purchase', company=request.company),
                    sales_account=Account.objects.get(name='Sales', company=request.company),
                    purchase_tax_scheme=TaxScheme.objects.get(name='No Tax', company=request.company),
                    sales_tax_scheme=TaxScheme.objects.get(name='No Tax', company=request.company))
        scenario = 'Create'
    if request.POST:
        form = ItemForm(data=request.POST, instance=item, company=request.company)
        if form.is_valid():
            item = form.save(commit=False)
            item.company = request.company
            item.save()
            if request.is_ajax():
                return render(request, 'callback.html', {'obj': ItemSerializer(item).data})
            return redirect('/inventory/items/')
    else:
        form = ItemForm(instance=item, company=request.company)
    if request.is_ajax():
        base_template = 'modal.html'
    else:
        base_template = 'dashboard.html'
    return render(request, 'item_form.html', {
        'scenario': scenario,
        'form': form,
        'base_template': base_template,
    })
开发者ID:xtranophilist,项目名称:awecounting,代码行数:32,代码来源:views.py

示例7: item_edit

# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import save [as 别名]
def item_edit(request, item_id, response_format='html'):
    "Item edit page"
    item = get_object_or_404(Item, pk=item_id)
    if not request.user.profile.has_permission(item, mode="w"):
        return user_denied(request, message="You don't have write access to this Item",
                           response_format=response_format)

    if request.POST:
        if 'cancel' not in request.POST:
            form = ItemForm(request.user.profile, item.item_type, request.POST,
                            files=request.FILES, instance=item)
            if form.is_valid():
                item = form.save(request)
                return HttpResponseRedirect(reverse('infrastructure_item_view', args=[item.id]))
        else:
            return HttpResponseRedirect(reverse('infrastructure_item_view', args=[item.id]))
    else:
        form = ItemForm(
            request.user.profile, item.item_type, instance=item)

    context = _get_default_context(request)
    context.update({'item': item,
                    'form': form})

    return render_to_response('infrastructure/item_edit', context,
                              context_instance=RequestContext(request), response_format=response_format)
开发者ID:tovmeod,项目名称:anaf,代码行数:28,代码来源:views.py

示例8: item_add_typed

# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import save [as 别名]
def item_add_typed(request, type_id, response_format='html'):
    "Item add with preselected type"

    item_type = get_object_or_404(ItemType, pk=type_id)
    if not request.user.profile.has_permission(item_type, mode='x'):
        return user_denied(request, message="You don't have access to create " + unicode(item_type),
                           response_format=response_format)

    if request.POST:
        if 'cancel' not in request.POST:
            form = ItemForm(
                request.user.profile, item_type, request.POST, files=request.FILES)
            if form.is_valid():
                item = form.save(request)
                return HttpResponseRedirect(reverse('infrastructure_item_view', args=[item.id]))
        else:
            return HttpResponseRedirect(reverse('infrastructure_index'))
    else:
        form = ItemForm(request.user.profile, item_type)

    context = _get_default_context(request)
    context.update({'item_type': item_type,
                    'form': form})

    return render_to_response('infrastructure/item_add_typed', context,
                              context_instance=RequestContext(request), response_format=response_format)
开发者ID:tovmeod,项目名称:anaf,代码行数:28,代码来源:views.py

示例9: item_add_edit

# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import save [as 别名]
def item_add_edit(request, id=None):

    item = get_object_or_404(Item, pk=id) if id else None

    if request.method == "POST":
        form = ItemForm(request.POST, instance=item)
        if form.is_valid():
            item = form.save()

            # Let them know it was saved properly!
            messages.success(request, "Successfully saved item %d x %s." % (item.quantity, item.sku))

            # If they ask to add again, give them to this page
            if request.POST.get("add_and_add", None):
                return HttpResponseRedirect(reverse("item_add"))

            # Else return them to home page
            return HttpResponseRedirect(reverse("home"))
        else:
            # Let them know there is an error
            messages.error(request, "There was an error.")
    else:
        form = ItemForm(instance=item)

    return render(request, "inventory/item_add_edit.html", {"item_form": form, "item": item})
开发者ID:albrnick,项目名称:quickinv,代码行数:27,代码来源:views.py

示例10: item_edit

# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import save [as 别名]
def item_edit(request, pk):
    item = get_object_or_404(Item, pk=pk)

    if request.method == 'POST':
        form = ItemForm(request.POST, instance=item)
        if form.is_valid():
            form.save(commit=True)
            messages.success(request, _("Saved"))
            return redirect('/')
    else:
        form = ItemForm(instance=item)

    data = {
        'form': form
    }

    return render_to_response('new.html', data,
                              context_instance=RequestContext(request))
开发者ID:pokorny,项目名称:wishlist-app,代码行数:20,代码来源:views.py

示例11: add_item

# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import save [as 别名]
def add_item(request):
    if request.method == 'POST': # If the form has been submitted
        
        submit = request.POST.get('cancel', None)
        item = Item(inventory = request.user.get_profile().inventory)
        
        if submit: #if cancel button was clicked
            return HttpResponseRedirect('/my/profile')
        
        else:
            form = ItemForm(request.POST, instance=item) # A form bound to the POST data
            if form.is_valid(): # All validation rules pass
                form.save()               
                return HttpResponseRedirect('/my/profile') # Redirect after POST
    else:
        form = ItemForm() # An unbound form

    return render(request, 'add_item.html', {
        'form': form,
    })
开发者ID:camreon,项目名称:seedbay,代码行数:22,代码来源:views.py

示例12: item

# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import save [as 别名]
def item(request):
    if request.user.is_superuser:
        return HttpResponseRedirect('/admin')
    user = request.user
    if user.check_password(settings.DEFAULT_PASSWORD):
        return HttpResponseRedirect('/accounts/password/change/')    
    if user.profile.has_address():
        if request.method == 'POST':
            form = ItemForm(user, request.POST)
            if form.is_valid():
                form.save()
                when = date.today()
                year = when.strftime("%Y")
                month = when.strftime("%m")
                return monthly(request, year, month)
        else:
            form = ItemForm(user)
        return render_to_response('item.html', {'form': form,}, context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect('/profile/address/edit/')
开发者ID:mmrs151,项目名称:iflatshare,代码行数:22,代码来源:views.py

示例13: add_item

# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import save [as 别名]
def add_item(request, topicid):
    '''Add a new item to this topic

    Sadly, we have no way of detecting near-duplicates. Oh well'''
    t = get_object_or_404(Topic, pk=topicid)
    iform = None
    if request.method == 'POST':
        iform = ItemForm(request.POST)
        if iform.is_valid():
            iform.save()
            'If item added successfully, go back to topic page'
            return goto_topic(t, 'New option added to topic')

    if not iform:
        iform = ItemForm(initial=dict(topic=t.pk))

    return render_to_response('dovote/item.html',
                              dict(topic=t,
                                   iform=iform),
                              context_instance=RequestContext(request))
开发者ID:ngkabra,项目名称:DoVote,代码行数:22,代码来源:views.py

示例14: item_edit

# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import save [as 别名]
def item_edit(request, pk):
    item = get_object_or_404(Item, pk=pk)

    if item.user.pk != request.user.pk:
        raise Http404

    if request.method == 'POST':
        form = ItemForm(request.POST, instance=item)
        if form.is_valid():
            form.save(commit=True)
            messages.success(request, _("Saved"))
            return redirect('/')
    else:
        form = ItemForm(instance=item)

    data = {
        'form': form,
        'edit': True
    }

    return render(request, 'new.html', data)
开发者ID:honza,项目名称:wishlist-app,代码行数:23,代码来源:views.py

示例15: item_detail

# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import save [as 别名]
def item_detail(request, item_code):
    from forms import ItemForm

    item = get_object_or_404(Item, code=item_code)
    if request.method == "POST":
        item_form = ItemForm(instance=item, data=request.POST)
        if item_form.is_valid():
            item = item_form.save()
            return redirect(item)
    else:
        item_form = ItemForm(instance=item)

    payload = {"item": item, "item_form": item_form}
    return _render("warehouse/item/detail.html", payload, request)
开发者ID:birchroad,项目名称:django-warehouse,代码行数:16,代码来源:views.py


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