本文整理汇总了Python中forms.PageForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python PageForm.is_valid方法的具体用法?Python PageForm.is_valid怎么用?Python PageForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.PageForm
的用法示例。
在下文中一共展示了PageForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_merge_conflict
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import is_valid [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)
示例2: add_page
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import is_valid [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)
示例3: edit
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import is_valid [as 别名]
def edit(request, name):
"""Allows users to edit wiki pages."""
try:
page = Page.objects.get(name=name)
except Page.DoesNotExist:
page = None
if request.method == 'POST':
form = PageForm(request.POST)
if form.is_valid():
if not page:
page = Page()
page.name = form.cleaned_data['name']
page.save()
revision = Revision()
revision.page = page
revision.content = form.cleaned_data['content']
if request.user.is_authenticated():
revision.editor = request.user
revision.save()
return HttpResponseRedirect(page.get_absolute_url())
else:
if page:
revision = page.get_latest_revision()
form = PageForm(initial={'name': page.name, 'content': revision.content})
else:
form = PageForm(initial={'name': name})
ctx = { 'form': form }
return render_to_response('wiki/edit.html', ctx, context_instance=RequestContext(request))
示例4: add_page
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import is_valid [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)
示例5: submiteditedpage
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import is_valid [as 别名]
def submiteditedpage(request, pageid):
if request.user.is_authenticated() and request.method == "POST":
page = findPage(pageid)
if not page:
return go404()
if request.user.is_staff or page.author == findUser(request.user):
if request.FILES:
files = request.FILES
elif page.illustration:
files = {'illustration': page.illustration}
else:
files = {}
form = PageForm(request.POST, files)
if form.is_valid():
page.short_desc = form.cleaned_data['short_desc']
page.illustration = files.get('illustration')
page.long_desc = form.cleaned_data['long_desc']
if request.FILES.get('video'):
page.video = 'https://player.vimeo.com' + (
Vimeo_Upload(request.FILES.get('video'))
)
page.save()
return HttpResponseRedirect("/page:"+str(page.id)+"/")
else:
return render_to_response("editingapage.html", {'form': form, 'page': page}, context_instance=RequestContext(request))
return goHome()
示例6: edit_page
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import is_valid [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,
})
示例7: edit
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import is_valid [as 别名]
def edit(request, name):
"""Allows users to edit wiki pages."""
try:
page = Page.objects.get(name=name)
except Page.DoesNotExist:
page = None
if request.method == 'POST':
form = PageForm(request.POST)
if form.is_valid():
if not page:
page = Page()
page.name = form.cleaned_data['name']
page.content = form.cleaned_data['content']
page.save()
return redirect(view, name=page.name)
else:
if page:
form = PageForm(initial=page.__dict__)
else:
form = PageForm(initial={'name': name})
context = {
'form': form,
}
return render_to_response('wiki/edit.html',
RequestContext(request, context))
示例8: submitnewpage
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import is_valid [as 别名]
def submitnewpage(request, parentid, book):
if request.user.is_authenticated() and request.method == "POST":
if (not parentid and user.is_staff()) or parentid:
form = PageForm(request.POST, request.FILES)
if form.is_valid():
page = Page()
if int(parentid):
page.parent = Page.objects.all().get(id=parentid)
else:
page.parent = None
page.author = request.user
page.short_desc = form.cleaned_data['short_desc']
if request.FILES.get('video'):
page.video = 'https://player.vimeo.com' + (
Vimeo_Upload(request.FILES.get('video'))
)
if request.FILES.get('illustration'):
page.illustration = request.FILES.get('illustration')
page.video = None
page.long_desc = form.cleaned_data['long_desc']
page.book = get_object_or_404(Book,pk=int(book))
page.save()
return HttpResponseRedirect("/page:"+str(page.id)+"/")
else:
return render_to_response("writinganewpage.html", {'form': form, 'parentid': parentid, "book": book}, context_instance=RequestContext(request))
return goHome()
示例9: add_page
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import is_valid [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)
示例10: edit
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import is_valid [as 别名]
def edit(request, name):
"""Allows users to edit wiki pages."""
try:
page = Page.objects.get(name=name)
except Page.DoesNotExist:
page = None
if request.method == "POST":
form = PageForm(request.POST)
if form.is_valid():
if not page:
page = Page()
page.name = form.cleaned_data["name"]
page.content = form.cleaned_data["content"]
page.save()
return HttpResponseRedirect("../../%s/" % page.name)
else:
if page:
form = PageForm(initial=page.__dict__)
else:
form = PageForm(initial={"name": name})
return render_to_response(
"wiki/edit.html",
{
"form": form,
"admin": is_admin(request),
"user": get_user(request),
"navbar": Page.objects.get(name="NavBar"),
},
)
示例11: view
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import is_valid [as 别名]
def view(request, test_id):
"""Test view, displays a test's pages"""
# If another test is started, go to that test
if 'test_id' in request.session and \
request.session['test_id'] != test_id:
return redirect('tests:view', request.session['test_id'])
# Attempt to load the test with test_id
test = get_object_or_404(Test, pk=test_id)
# If test_id is not started, start it
if 'test_id' not in request.session:
request.session['test_status'] = 'active'
request.session['test_id'] = test_id
request.session['page_number'] = 1
request.session['page_count'] = test.pages.count()
request.session['answers'] = {}
page_number = request.session['page_number']
page_count = request.session['page_count']
# This means that a test is finished, so proceed to the results
if request.session['test_status'] == 'finished':
return redirect('tests:result', test_id)
page = test.pages.all()[page_number-1]
# If page form has been submitted
if request.method == 'POST':
form = PageForm(request.POST, page=page)
if form.is_valid():
# Save answers in session
request.session['answers'].update(form.cleaned_data)
# Check if there is another page from the test; if not
# proceed to the results
if page_number < page_count:
request.session['page_number'] += 1
return redirect('tests:view', test_id)
else:
request.session['test_status'] = 'finished'
return redirect('tests:result', test_id)
else:
form = PageForm(page=page)
# Assign context variables
context = {
'test': test,
'page_number': page_number,
'page_count': page_count,
'form': form,
}
return render(request, 'tests/view.html', context)
示例12: edit
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import is_valid [as 别名]
def edit(request, name):
"""Allows users to edit wiki pages."""
try:
page = Page.objects.get(name=name)
except Page.DoesNotExist:
page = None
if request.method == 'POST':
form = PageForm(request.POST)
if form.is_valid():
if not page:
# it's a new page
page = Page()
page.name = form.cleaned_data['name']
page.user = request.user
page.created_on = datetime.now()
page.save()
page_revision = PageRevision(content = form.cleaned_data['content'], edit_reason = form.cleaned_data['edit_reason'], user = request.user, revision_for = page)
page_revision.save()
page.current_revision = page_revision
page.save()
else:
# it's an edit on an old page
page.name = form.cleaned_data['name']
revision_count = PageRevision.objects.filter(revision_for = page).count()
new_rev = revision_count + 1
page_revision = PageRevision(content = form.cleaned_data['content'], edit_reason = form.cleaned_data['edit_reason'], user = request.user, revision_for = page, revision_num = new_rev)
page_revision.save()
page.current_revision = page_revision
page.modified_on = datetime.now()
page.user = request.user
page.save()
return HttpResponseRedirect('../../%s/' % page.name)
else:
if page:
page_dict = page.__dict__
# we have phased out page.content,
# instead page will be a reference to current revision content.
# but for the purposes of the form, we'll emulate it (ugly hack!)
page_dict['content'] = page.current_revision.content
form = PageForm(initial=page_dict)
else:
form = PageForm(initial={'name': name})
context = RequestContext(request)
return render_to_response('wiki/edit.html', {'form': form}, context)
示例13: page_add
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import is_valid [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)
示例14: page_edit
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import is_valid [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)
示例15: submiteditedpage
# 需要导入模块: from forms import PageForm [as 别名]
# 或者: from forms.PageForm import is_valid [as 别名]
def submiteditedpage(request, pageid):
if request.user.is_authenticated() and request.method == "POST":
page = findPage(pageid)
if not page:
return go404()
if request.user.is_staff or page.author == findUser(request.user):
form = PageForm(request.POST, request.FILES)
if form.is_valid():
page.short_desc = form.cleaned_data['short_desc']
page.illustration = request.FILES['illustration']
page.long_desc = form.cleaned_data['long_desc']
page.save()
return HttpResponseRedirect("/page:"+str(page.id)+"/")
else:
return render_to_response("editingapage.html", {'form': form, 'page': page}, context_instance=RequestContext(request))
return goHome()