本文整理汇总了Python中models.Page类的典型用法代码示例。如果您正苦于以下问题:Python Page类的具体用法?Python Page怎么用?Python Page使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Page类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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"),
},
)
示例2: processCmsRequest
def processCmsRequest(request, resource):
if request.user.is_authenticated():
loged = "<br><br>Logged in as " + request.user.username +\
". <a href='/admin/logout/'>Logout</a><br>"
else:
loged = "<br><br>Not logged. <a href='/admin/login/'>Login</a><br>"
if request.method == 'GET':
try:
page = Page.objects.get(name=resource)
return HttpResponse(page.page + loged)
except Page.DoesNotExist:
return HttpResponseNotFound("Page not found" + loged)
elif request.method == 'PUT':
if request.user.is_authenticated():
try:
newPage = Page.objects.get(name=resource)
newPage.page = request.body
except Page.DoesNotExist:
newPage = Page(name = resource, page = request.body)
newPage.save()
return HttpResponse("Added to the list")
else:
return HttpResponse("Couldn't add to the list" + loged)
else:
return HttpResponse(status=403)
示例3: addPage
def addPage(name, content):
try:
newPage = Page.objects.get(name=name)
newPage.page = content
except Page.DoesNotExist:
newPage = Page(name = name, page = content)
newPage.save()
示例4: get
def get(self, name):
"""Handles the get requests for edit page of the wiki pages
The user will get redirected to the SignupPage if authentication fails.
If a version is specified in the url it retreives the corresponding version
of the requested page. If the version doesn't exists, it redirects to the
requested edit page without a version specified.
If no version is specified the latest version of the page will be retreived
to be displayed.
If there is no version of the page in the datastore, the requested name will
be transformed and used for Page.name.
"""
self.restrictedArea()
name = utils.checkPage(name)
version = self.request.get('v')
version = 0 if not version else int(version)
page = Page.getName(name, version)
if not page and version:
self.redirect('/_edit/%s' % name)
return None
if not page and not version:
page = Page.createPage(name)
params = { 'page': page }
self.render(settings.TEMPLATE_FILENAME['edit'], **params)
示例5: make_request_context
def make_request_context(dic=None):
from limited.utils import widgets
from models import Page, Tag, User
from viewutils import get_latest_comments
if dic is None:
dic = {}
static_files = GroupedDict(find_static_files())
dic.update((key, getattr(settings, key)) for key in ("BLOG_URL", "MEDIA_URL", "ADMINS", "USE_PYGMENTS"))
dic.update(DEFAULT_CONTEXT_VARIABLES)
dic.update(
{
"navigation_top": [HomePage()] + list(Page.filter(in_navigation=True)),
"tags": Tag.objects.all().order_by("-name"),
"latestcomments": get_latest_comments(),
"popular_pages": Page.filter(popular=True),
"WIDGETS": widgets.get_widgets(),
"JS_FILES": static_files["js"],
"CSS_FILES": static_files["css"],
"limited": _internal.software_info(),
}
)
if not "COPYRIGHT_YEARS" in dic:
from datetime import datetime
dic["COPYRIGHT_YEARS"] = [datetime.now().year]
assert 0 < len(dic["COPYRIGHT_YEARS"]) < 3
# two years at maximum
return dic
示例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 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))
示例7: post
def post(self,slug):
page = Page.query(Page.slug == slug).get()
if page:
page.slug = slug
page.title = self.request.get('title')
page.text = self.request.get('text')
page.prev = self.request.get('prev')
page.next = self.request.get('next')
page.doc = self.request.get('doc')
page.allowed = int(self.request.get('level'))
page.put()
self.redirect('/content/{}'.format(slug))
else:
page = Page(title = self.request.get('title'),
slug = slug,
author = users.get_current_user(),
text = self.request.get('text'),
prev = self.request.get('prev'),
next = self.request.get('next'),
doc = self.request.get('doc'),
allowed = int(self.request.get('level'))
)
page.put()
self.redirect('/content/{}'.format(slug))
示例8: edit
def edit(request, slug):
params = {"slug": slug}
page = get_or_none(Page, slug=slug)
text = page.current_revision.text if page and page.current_revision else ""
form = EditForm(data=request.POST or None, initial={"text": text})
if request.method == "POST" and form.is_valid():
if not page:
page = Page(title=unslugify(slug), slug=slug)
page.save()
form.save(page, request.user)
return redirect(reverse("wiki-detail", kwargs={"slug": page.slug}))
params["form"] = form
if page:
params["action"] = "Edit"
params["title"] = page.title
params["modified"] = page.modified_on
params["action"] = "Edit"
else:
params["title"] = unslugify(slug)
params["modified"] = "NULL"
params["action"] = "Create"
return render(request, "edit.html", params)
示例9: wiki
def wiki(user_slug, wiki_slug):
""" Renders a wiki's main page.
-> user's slugified name; wiki's slugified title
"""
try:
user = User.get_by(name_slug=user_slug)
except NoResultFound:
flash("This user does not exist,<br />\
and consequently, their wiki does not either.")
return redirect(url_for('main'))
try:
wiki = user.wiki_by_slug(wiki_slug)
except NoResultFound:
if user_slug == g.user.name_slug:
flash("This wiki does not exist.")
else:
flash("This wiki either is private or does not exist.")
return redirect(url_for('main'))
if request.method == 'POST':
title = request.form['title']
try:
Page.get_by(title_slug=slugify(title))
except NoResultFound:
page = Page(wiki=wiki, title=title, title_slug=slugify(title),
content="<h1>%s</h1><p></p>" % title)
models.session.commit()
return redirect(url_for('wiki_page', user_slug=user.name_slug,
wiki_slug=wiki.title_slug, page_slug=slugify(title)))
else:
page = wiki.page_by_slug(wiki_slug)
if wiki.permission_to_view(g.user):
return render_template('page.html', user=user, wiki=wiki, page=page)
else:
flash("This wiki either is private or doesn't exist.")
return redirect(url_for('main'))
示例10: contentapp
def contentapp(request,resourceName):
response = "<h1> WELLCOME TO THE JUNGLE! </h1>"
if request.method == "GET":
try:
info = Page.objects.get(name=resourceName)
return HttpResponse(response + info.contenido)
except Page.DoesNotExist:
response += '<body> Valor no encontrado, definalo </body>'
form = "<form action='' method='POST'>\n"
form += "Nombre: <input type='text' name='name' value='" + resourceName + "'><br>\n"
form += "Contenido: <input type='text' name='contenido'><br>\n"
form += "<input type='submit' value='enviar'>\n"
form += "</form>\n"
response += form
return HttpResponse(response)
elif request.method == "POST":
response += '<body> POST </body>'
newPage = Page(name=request.POST['name'], contenido=request.POST['contenido'])
newPage.save()
response += "Nombre: " + request.POST['name']
response += ", Contenido: " + request.POST['contenido']
return HttpResponse(response)
else:
response += '<body> No way </body>'
return HttpResponse(response)
示例11: create_page
def create_page(db, page):
new_data = Page()
new_data.title = unicode(page['title'])
new_data.content = unicode(page["content"])
new_data.css = unicode(page['css'])
new_data.book_id = int(page["book_id"])
db.session.add(new_data)
示例12: get
def get(self, title):
# check the user identity
cookie_val = self.request.cookies.get('user_id')
#check whether it is login user
username = checkUser(cookie_val)
if username:
#check whether the request has version para in it
page=None
version = self.request.get("v")
if version:
if version.isdigit():
page = Page.get_by_id(int(version))
if page:
page=[page]
else:
self.error("404")
return
else:
self.error("404")
return
# check whether the page has been created
else:
query = Page.fetchPages(title)
page = query.fetch(1)
if page:
self.render_front(username=username,title=title,content=page[0].content)
else:
self.render_front(username=username,title=title)
else:
self.redirect("/")
示例13: get_object
def get_object(self, request, region='', slug=''):
self.setup_region(region)
obj = Page(slug=slugify(slug), region=self.region)
obj.title = obj.versions.most_recent().name
obj.page = obj
return obj
示例14: create_default_page
def create_default_page(page_title):
default_text = ('This page is brand new. ' +
'You can edit it by clicking the link above.')
page = Page(title=page_title, text=default_text)
page.put()
return page
示例15: index
def index(request):
params = {}
if settings.SHOWPAGES:
pages = Page.all()
pages.order("-modified")
posts = pages.fetch(settings.SHOWPAGES)
params['posts'] = posts
return respond(request, 'base.html', params)
else:
home_category = 'Main'
home_page = 'Home'
page = db.GqlQuery("SELECT * FROM Page WHERE name = :1", home_page).get()
if page == None:
if users.get_current_user():
category = db.GqlQuery("SELECT * FROM Category WHERE name = :1", home_category).get()
if category == None:
category = Category(name=home_category, sequence=1)
category.put()
page = Page(name=home_page, category=home_category, sequence=1, content='<h1>Home Page</h1><h5>Change me!</h5>')
page.put()
else:
return HttpResponseRedirect(users.create_login_url(request.get_full_path()))
return viewPage(request, 'Main', 'Home')