本文整理汇总了Python中forms.PageForm类的典型用法代码示例。如果您正苦于以下问题:Python PageForm类的具体用法?Python PageForm怎么用?Python PageForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PageForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_page
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: submiteditedpage
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()
示例3: edit_page
def edit_page(nickname, pagename):
if nickname != g.user.nickname:
flash('Cannot edit another users content page.')
return redirect(url_for('index'))
user_page = g.user.user_page(pagename)
if user_page == None:
flash('Content page doesn''t exist')
return redirect(url_for('index'))
form = PageForm()
if form.validate_on_submit():
user_page.page_title = form.page_title.data
user_page.page_content = form.page_content.data
db.session.add(user_page)
db.session.commit()
flash('Updated content page successfully!')
return redirect(url_for('index'))
else:
form.page_title.data = user_page.page_title
form.page_content.data = user_page.page_content
return render_template('page_form.html',
form = form)
示例4: add_page
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)
示例5: submitnewpage
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()
示例6: edit
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"),
},
)
示例7: add_page
def add_page(request, category_name_url):
context = RequestContext(request)
category_name = decode_category_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.DoesNotExist:
return render_to_response('rango/add_category.html', {}, context)
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', {
'cat_list': get_category_list(),
'category_name_url': category_name_url,
'category_name': category_name,
'form': form
},
context)
示例8: edit
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))
示例9: add_page
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)
示例10: edit
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))
示例11: view
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
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: pages
def pages():
form = PageForm()
if form.validate_on_submit():
page = Page(page_title = form.page_title.data, page_content = form.page_content.data, user_id = g.user.id)
db.session.add(page)
db.session.commit()
flash('Your page has been added!')
return redirect(url_for('index'))
return render_template('page_form.html',
form = form)
示例14: page_add
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)
示例15: save_page
def save_page(page_id=None):
"""Save Page to database
If page_id is None a new Page will be inserted in the database. Otherwise
the existing Page will be updated.
"""
message = 'Page updated'
page_form = PageForm(request.form)
if not page_form.validate():
flash('ERROR: errors detected. Page NOT saved!', category='error')
return edit_page(page_id=page_id, page_form=page_form)
if page_id is None:
page = Page(request.form['title'], request.form['content'])
page.status_id = 1
page.user_id = session['user_id']
page.createdate = datetime.now()
else:
page = get_page(page_id)
page_form.populate_obj(page)
page.lastmoddate = datetime.now()
# compile input to html
page.compile(app.config['REPL_TAGS'])
# update pubdate if page's pubdate is None and its status is set
# to public
if request.form['status'] == 'public' and \
unicode(page.status) != 'public' and \
page.pubdate is None:
page.pubdate = datetime.now()
page.status = get_status(request.form['status'])
if page.slug is None:
page.slug = slugify(page.title)
if page_id is None:
db_session.add(page)
message = 'New page was successfully added'
db_session.commit()
flash(message)
return redirect(url_for('edit_page', page_id=page.id))