本文整理汇总了Python中forms.CategoryForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python CategoryForm.save方法的具体用法?Python CategoryForm.save怎么用?Python CategoryForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.CategoryForm
的用法示例。
在下文中一共展示了CategoryForm.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_category
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import save [as 别名]
def add_category(request):
# Get the context from the request.
context = RequestContext(request)
cat_list = get_category_list()
context_dict = {}
context_dict['cat_list'] = cat_list
# A HTTP POST?
if request.method == 'POST':
form = CategoryForm(request.POST)
# Have we been provided with a valid form?
if form.is_valid():
# Save the new category to the database.
form.save(commit=True)
# Now call the index() view.
# The user will be shown the homepage.
return index(request)
else:
# The supplied form contained errors - just print them to the terminal.
print form.errors
else:
# If the request was not a POST, display the form to enter details.
form = CategoryForm()
# Bad form (or form details), no form supplied...
# Render the form with error messages (if any).
context_dict['form'] = form
return render_to_response('rango/add_category.html', context_dict, context)
示例2: add_category
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import save [as 别名]
def add_category(request):
if request.method == 'POST':
form = CategoryForm(request.POST)
if form.is_valid():
form.save(commit=True)
return index(request)
else:
print form.errors
else:
form = CategoryForm()
return render(request, 'rango/add_category.html', {'form': form})
示例3: categoryAdd
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import save [as 别名]
def categoryAdd(request):
if request.method == "POST":
cf = CategoryForm(request.POST, prefix="category")
if cf.is_valid():
cf.save()
messages.success(request,
_('Category Added.'))
return HttpResponseRedirect(reverse("pageCategoryAdd"))
else:
cf = CategoryForm(prefix="category")
return render(request, 'categoryadd.html', dict(categoryForm=cf))
示例4: add_category
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import save [as 别名]
def add_category(request):
if request.method == "POST":
form = CategoryForm(request.POST)
if form.is_valid():
form.save()
return index(request)
else:
print form.errors
else:
form = CategoryForm()
return render(request, "rango/add_category.html", {"form": form})
示例5: frontend
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import save [as 别名]
def frontend(request):
uform = UserForm(request.POST or None)
cform = CategoryForm(data=request.POST or None)
if request.method=='POST' and uform.is_valid() and cform.is_valid():
user_obj = uform.save(commit=False)
user_obj.save()
cform.save(user_obj)
messages.success(request, 'You are signed-up for the selected notifications')
return redirect(user_obj.get_edit_url())
return render_to_response('notification.html',
locals(),
RequestContext(request))
示例6: create
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import save [as 别名]
def create(request):
if request.POST:
form = CategoryForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return HttpResponseRedirect('/categories/all')
else:
form = CategoryForm()
args = {}
args.update(csrf(request))
args['form'] = form
return render_to_response('create_category.html', args)
示例7: category_edit
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import save [as 别名]
def category_edit(request, id):
category = get_object_or_404(Category, id=id)
if request.method == 'GET':
form = CategoryForm(instance=category)
else:
form = CategoryForm(request.POST, instance=category)
if form.is_valid():
form.save()
return redirect('category_list', id=id)
data = {
'form': form,
'category': category,
}
return render_to_response('category_edit.html', data, context_instance=RequestContext(request))
示例8: add_category
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import save [as 别名]
def add_category(request):
context = RequestContext(request)
cat_list = get_category_list()
if request.method == 'POST':
form = CategoryForm(request.POST)
if form.is_valid():
form.save(commit=True)
return index(request)
else:
print form.errors
else:
form = CategoryForm()
return render_to_response('rango/add_category.html', {'form': form, 'cat_list':cat_list}, context)
示例9: add_category
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import save [as 别名]
def add_category(request):
context = RequestContext(request)
if request.method == 'POST':
form = CategoryForm(request.POST)
if form.is_valid():
form.save(commit=True)
url = reverse(index)
return HttpResponseRedirect(url)
else:
print form.errors
else:
form=CategoryForm()
return render_to_response('rango/add_category.html',{'form': form}, context)
示例10: add_category
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import save [as 别名]
def add_category(request):
"""
Either show a form or create a new instance of one.
"""
# Is request HTTP POST or GET?
if request.method == "POST":
form = CategoryForm(request.POST)
if form.is_valid():
category = form.save(commit=False)
setattr(category,"url", Category._encode_url_name(category.name))
category.save()
# now call the index() view
# user redirected to home page
return index(request)
else:
# Uh oh, supplied form contains error - print out to console
print form.errors
else:
# request not a POST, display the form to enter details
form = CategoryForm()
# Bad form (or form details), no form supplied...
# Render the form with error messages (if any).
return _process_request(request, {"form": form}, "rango/add_category.html")
示例11: frontend_user
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import save [as 别名]
def frontend_user(request,uhash):
userinfo = get_object_or_404(UserInfo,userhash=uhash)
uform = UserDispForm(instance=userinfo,data=request.POST or None)
cform = CategoryForm(user_instance=userinfo,data=request.POST or None)
if uform.is_valid() and uform.has_changed():
uform.save()
print 'Uform saved'
if cform.is_valid() and cform.has_changed():
cform.save(userinfo)
if request.method=='POST':
if (uform.has_changed() or cform.has_changed()):
messages.success(request, 'Changes saved successfully!')
return redirect(".")
else:
messages.info(request, 'No changes made!')
return redirect(".")
return render_to_response('notification.html',
locals(),
RequestContext(request))
示例12: add_category
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import save [as 别名]
def add_category(request):
if request.method == 'POST':
form = CategoryForm(request.POST)
print type(form)
if form.is_valid():
""" func doc::
Returns True if the form has no errors. Otherwise, False. If errors are
being ignored, returns False.
"""
print 'form will save'
form.save(commit=True)
else:
print 'form err'
print form.errors
else:
form = CategoryForm()
return render(request, 'blog/add_category.html', {'form': form})
示例13: category_edit
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import save [as 别名]
def category_edit(request, id):
category = get_object_or_404(Category, id=id)
category_titles = CategoryTitle.objects.filter(category=category)
category_titles_langs = {}
for lang in settings.LANGUAGES:
category_titles_langs[lang] = None
for category_title in category_titles:
category_titles_langs[category_title.lang] = category_title
if request.method == 'POST':
category_form = CategoryForm(request.POST,prefix='category_form', instance=category)
category_title_forms = []
for lang in settings.LANGUAGES:
category_title_forms.append({
'form':CategoryTitleForm(request.POST,prefix='category_title_' + lang[0]),
'lang':lang[0]
})
if category_form.is_valid():
category = category_form.save(commit=False)
category.parent = parent
category.save()
valid = False
for category_title_form in category_title_forms:
valid = category_title_form['form'].is_valid()
if not valid:
break
# print 'valid', valid
if valid:
for category_title_form in category_title_forms:
category_title = category_title_form['form'].save(commit=False)
category_title.lang = category_title_form['lang']
category_title.category = category
category_title.save()
return redirect('ask_librarian:administration:categories_list')
else:
category_form = CategoryForm(prefix="category_form")
category_title_forms = []
for lang in settings.LANGUAGES:
category_title_forms.append({
'form':CategoryTitleForm(prefix='category_title_' + lang[0]),
'lang':lang[0]
})
return render(request, 'ask_librarian/administration/create_category.html', {
'category_form': category_form,
'category_title_forms': category_title_forms,
})
示例14: category_add
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import save [as 别名]
def category_add(request):
if request.method == 'GET':
form = CategoryForm()
else:
form = CategoryForm(request.POST)
if form.is_valid():
category = form.save()
return redirect('homepage')
data = {
'form':form,
}
return render_to_response('category_add.html', data, context_instance=RequestContext(request))
示例15: create_category_submit
# 需要导入模块: from forms import CategoryForm [as 别名]
# 或者: from forms.CategoryForm import save [as 别名]
def create_category_submit(request):
category = Category(user=request._user, name="DEFAULT")
data = CategoryForm(data=request.POST, instance=category)
if data.is_valid():
entity = data.save(commit=False)
entity.put()
return HttpResponseRedirect("/")
return render_to_response('home/create_category.html',
{
'category_form' : data
})