本文整理汇总了Python中forms.PageForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python PageForm.save方法的具体用法?Python PageForm.save怎么用?Python PageForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.PageForm
的用法示例。
在下文中一共展示了PageForm.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_page
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import save [as 别名]
def edit_page(request, id):
langs = []
for lang in settings.LANGUAGES:
langs.append({
'code': lang[0],
'title': _(lang[1])
})
page = get_object_or_404(Page, id=id)
if request.method == 'POST':
page_form = PageForm(request.POST, prefix='page_form', instance=page)
if page_form.is_valid():
page_form.save()
return redirect('pages:administration:pages_list')
else:
page_form = PageForm(prefix='page_form', instance=page)
return render(request, 'pages/administration/edit_page.html', {
'page': page,
'langs': langs,
'page_form': page_form,
})
示例2: add_page
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import save [as 别名]
def add_page(request, category_name_url):
context = RequestContext(request)
cat_list = get_category_list()
category_name = decode_url(category_name_url)
if request.method == 'POST':
form = PageForm(request.POST)
if form.is_valid():
page = form.save(commit=False)
try:
cat = Category.objects.get(name=category_name)
page.category = cat
except Category.DoesNotExit:
return render_to_response('rango/add_category.html', {}, context)
page.views = 0
form.save(commit=True)
page.save()
return category(request, category_name_url)
else:
print form.errors
else:
form = PageForm()
return render_to_response('rango/add_page.html', {'category_name_url': category_name_url, 'category_name': category_name, 'cat_list':cat_list, 'form': form}, context)
示例3: test_merge_conflict
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import save [as 别名]
def test_merge_conflict(self):
p = Page()
p.content = '<p>old content</p>'
p.name = 'Front Page'
p.save()
a = PageForm(instance=p)
b = PageForm(instance=p)
b_post = b.initial
b_post['content'] = '<p>b content</p>'
b = PageForm(b_post, instance=p)
self.failUnless(b.is_valid())
b.save()
p = Page.objects.get(pk=p.pk)
a_post = a.initial
a_post['content'] = '<p>a content</p>'
a = PageForm(a_post, instance=p)
self.failIf(a.is_valid())
self.failUnless(PageForm.conflict_error in str(a.errors))
a_post = a.data
a = PageForm(a_post, instance=p)
self.failUnless(a.is_valid())
a.save()
p = Page.objects.get(pk=p.pk)
self.failUnless('Edit conflict!' in p.content)
示例4: add_page
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import save [as 别名]
def add_page(request, category_name_slug):
try:
cat = Category.objects.get(slug=category_name_slug)
except Category.DoesNotExist:
cat = None
if request.method == 'POST':
form = PageForm(request.POST)
if form.is_valid():
if cat:
page = form.save(commit=False)
page.category = cat
page.views = 0
page.save()
# probably better to use a redirect here.
return category(request, category_name_slug)
else:
print form.errors
else:
form = PageForm()
context_dict = {'form':form, 'category': cat}
return render(request, 'rango/add_page.html', context_dict)
示例5: add_page
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import save [as 别名]
def add_page(request, category_name_url):
print 'add_page called'
context = RequestContext(request)
category_name = decode_url(category_name_url)
if request.method == 'POST':
form = PageForm(request.POST)
if form.is_valid():
page = form.save(commit = False)
cat = Category.objects.get(name = category_name)
page.category = cat
page.views = 0
page.save()
return category(request, category_name_url)
else:
print form.errors
else:
form = PageForm()
return render_to_response('rango/add_page.html',
{'category_name_url': category_name_url,
'category_name': category_name, 'form':form},
context)
示例6: page_edit_static
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import save [as 别名]
def page_edit_static(request, id):
shop = request.shop
page = get_object_or_404(Page, pk=id)
static_pages = Page.objects.filter(shop=shop)
dynamic_pages = DynamicPageContent.objects.filter(shop=shop)
form = PageForm(shop, request.POST or None, instance=page)
if request.method == "POST":
if form.is_valid():
form.save()
request.flash['message'] = unicode(_("Page successfully edited."))
request.flash['severity'] = "success"
return HttpResponseRedirect(reverse('page_edit_static', args=[id]))
return render_to_response('store_admin/web_store/pages_edit_static_page.html', {
'form': form,
'page': page,
'static_pages': static_pages,
'dynamic_pages': dynamic_pages
},
RequestContext(request))
示例7: page_add
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import save [as 别名]
def page_add(request, response_format='html'):
"Static Page add"
if request.POST:
form = PageForm(request.POST)
if form.is_valid():
page = form.save()
return HttpResponseRedirect(reverse('core_admin_page_view', args=[page.id]))
else:
form = PageForm()
return render_to_response('core/administration/page_add',
{'form': form},
context_instance=RequestContext(request), response_format=response_format)
示例8: page_edit
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import save [as 别名]
def page_edit(request, page_id, response_format='html'):
"Static Page edit"
page = get_object_or_404(Page, pk=page_id)
if request.POST:
form = PageForm(request.POST, instance=page)
if form.is_valid():
page = form.save()
return HttpResponseRedirect(reverse('core_admin_page_view', args=[page.id]))
else:
form = PageForm(instance=page)
return render_to_response('core/administration/page_edit',
{'page': page, 'form': form},
context_instance=RequestContext(request), response_format=response_format)
示例9: add_page
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import save [as 别名]
def add_page(request, category_name_url):
context = RequestContext(request)
category_name = decode_url(category_name_url)
if request.method == 'POST':
form = PageForm(request.POST)
if form.is_valid():
# This time we cannot commit straight away.
# Not all fields are automatically populated!
page = form.save(commit=False)
# Retrieve the associated Category object so we can add it.
# Wrap the code in a try block - check if the category actually exists!
try:
cat = Category.objects.get(name=category_name)
page.category = cat
except Category.DoesNotExist:
# If we get here, the category does not exist.
# We render the add_page.html template without a context dictionary.
# This will trigger the red text to appear in the template!
return render_to_response('rango/add_page.html', {'category_name': category_name}, context)
# Also, create a default value for the number of views.
page.views = 0
# With this, we can then save our new model instance.
page.save()
action.send(request.user, verb='added page', action_object=page, target=cat)
# Now that the page is saved, display the category instead.
return category(request, category_name_url)
else:
print form.errors
else:
try:
cat = Category.objects.get(name=category_name)
except Category.DoesNotExist:
# If we get here, the category does not exist.
# We render the add_page.html template without a context dictionary.
# This will trigger the red text to appear in the template!
return render_to_response('rango/add_page.html', {'category_name': category_name}, context)
form = PageForm()
return render_to_response('rango/add_page.html',
{'category_name_url': category_name_url,
'category_name': category_name, 'form': form},
context)
示例10: add_page
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import save [as 别名]
def add_page(request, category_name_url):
context = RequestContext(request)
cat_list = get_category_list()
context_dict = {}
context_dict['cat_list'] = cat_list
category_name = decode_url(category_name_url)
if request.method == 'POST':
form = PageForm(request.POST)
if form.is_valid():
# This time we cannot commit straight away.
# Not all fields are automatically populated!
page = form.save(commit=False)
# Retrieve the associated Category object so we can add it.
try:
cat = Category.objects.get(name=category_name)
page.category = cat
except Category.DoesNotExist:
return render_to_response('rango/add_page.html',
context_dict,
context)
# Also, create a default value for the number of views.
page.views = 0
# With this, we can then save our new model instance.
page.save()
# Now that the page is saved, display the category instead.
return category(request, category_name_url)
else:
print form.errors
else:
form = PageForm()
context_dict['category_name_url'] = category_name_url
context_dict['category_name'] = category_name
context_dict['form'] = form
return render_to_response('rango/add_page.html',
context_dict,
context)
示例11: create
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import save [as 别名]
def create(request):
if request.method == 'POST':
form = PageForm(request.POST)
if form.is_valid():
page = form.save()
#page = get_object_or_404(Page, id=form.pk)
view_page_groups_ids = form.cleaned_data['view_page_groups']
assign_perm_for_groups_id('pages.view_page', page, view_page_groups_ids)
return HttpResponseRedirect(reverse('administration_pages_index'))
else:
form = PageForm()
return direct_to_template(request, 'pages/administration/pages_create.html',
{'form': form,
'groups'
'active_module': 'pages', })
示例12: add_page
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import save [as 别名]
def add_page(request, category_slug):
context_dict = {}
cat = Category.objects.get(slug=category_slug)
context_dict["category"] = cat
if request.method == "POST":
form = PageForm(request.POST)
if form.is_valid():
if cat:
page = form.save(commit=False)
page.category = cat
page.views = 0
page.save()
return category(request, category_slug)
else:
print form.errors
else:
form = PageForm()
context_dict["form"] = form
return render(request, "rango/add_page.html", context_dict)
示例13: create_page
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import save [as 别名]
def create_page(request, parent=None):
if parent:
parent = get_object_or_404(Page, id=parent)
if request.method == 'POST':
page_form = PageForm(request.POST, prefix='page_form')
if page_form.is_valid():
page = page_form.save(commit=False)
if parent:
page.parent = parent
page.save()
return redirect('pages:administration:create_page_content', page_id=page.id)
else:
page_form = PageForm(prefix='page_form')
return render(request, 'pages/administration/create_page.html', {
'parent': parent,
'page_form': page_form,
})
示例14: page_create
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import save [as 别名]
def page_create(request):
shop = request.shop
static_pages = Page.objects.filter(shop=shop)
dynamic_pages = DynamicPageContent.objects.filter(shop=shop)
form = PageForm(shop, request.POST or None)
if form.is_valid():
page = form.save(commit = False)
page.shop = shop
page.save()
request.flash['message'] = unicode(_("Page successfully saved."))
request.flash['severity'] = "success"
return HttpResponseRedirect(reverse('web_store_pages'))
return render_to_response('store_admin/web_store/pages_page_create.html',
{
'form': form,
'static_pages': static_pages,
'dynamic_pages': dynamic_pages,
},
RequestContext(request))
示例15: add_page
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import save [as 别名]
def add_page(request, category_name_url):
"""
Add page to category if it doesn't exist,
:param request
:param category_name_url
"""
category_name = Category._encode_url_name(category_name_url, Category._url_decode_rules_dict)
# category_name = "ooops"
cat = None
if request.method == "POST":
form = PageForm(request.POST)
if form.is_valid():
# Cannot commit straight away, not all fields automatically populated
page = form.save(commit=False)
# Retrieve the associated Category object so we can add it
# Handle exception for Model.DoesNotExist, Go back and render the add category form
try:
cat = Category.objects.get(url=category_name_url)
page.category = cat
except Category.DoesNotExist:
# Category does not exist, Go back and the render the add_category form
return _process_request(request, {}, "rango/add_category.html")
# set default value for number of views, and save new model instance
page.views = 0
page.save()
# Now that the page is saved, display the category instead.
return category(request, category_name_url)
else:
print form.errors
else:
form = PageForm()
context_dict = {
"category_name_url": category_name_url,
"category_name": category_name,
"form": form,
}
return _process_request(request, context_dict, "rango/add_page.html")