本文整理汇总了Python中models.Page.all方法的典型用法代码示例。如果您正苦于以下问题:Python Page.all方法的具体用法?Python Page.all怎么用?Python Page.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Page
的用法示例。
在下文中一共展示了Page.all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import all [as 别名]
def edit(self):
year, month, day, route = self._get_route_args()
post = Post.by_route(route)
if post is None:
return HTTPNotFound('No such post')
form = BlogView.Form(self.request.POST, post)
if self.request.method == 'POST' and form.validate():
post.title = form.title.data
post.created = form.created.data
post.body = form.body.data
post.is_published = form.is_published.data
# edit tags
del post.tags
for tag in Tag.from_list(form.tags.data):
nt = NodeTag()
nt.tag = tag
post.tags.append(nt)
return HTTPFound(
location=self.request.route_url('post_view',
year=year,
month=month,
day=day,
route=RouteAbleMixin.url_quote(post.title))
)
return dict(
post=post,
form=form,
pages=Page.all(),
logged_in=authenticated_userid(self.request),
)
示例2: add
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import all [as 别名]
def add(self):
request = self.request
form = ImageView.UploadForm(request.POST)
if request.method == 'POST' and form.validate():
# looks like we will us form here only for validation an html gen
# name = form.image.name doesn't work this way there is always 'image' as name
name = request.POST['image'].filename
path = os.path.join(os.path.dirname(__file__),'files', name)
in_file = request.POST['image'].file
with open(path, "w") as fd:
in_file.seek(0)
while 1:
data = in_file.read(2<<16)
if not data:
break
fd.write(data)
image = Image.add(name)
return HTTPFound(location=request.route_url(
'image_view',
id=image.id,
)
)
return dict(
form=form,
url=self.request.route_url('image_add'),
pages=Page.all(),
logged_in=authenticated_userid(self.request),
)
示例3: view_y
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import all [as 别名]
def view_y(self):
year = int(self.request.matchdict['year'])
return dict(
posts=Post.by_year(year),
pages=Page.all(),
logged_in=authenticated_userid(self.request),
)
示例4: index
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import all [as 别名]
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')
示例5: view
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import all [as 别名]
def view(self):
year, month, day, route = self._get_route_args()
post = Post.by_route(route)
if post is None:
return HTTPNotFound("No such post")
form = BlogView.CommentForm(self.request.POST)
if self.request.method == 'POST' and form.validate():
if form.parent.data == '':
post_comment = PostComment()
post_comment.comment = Comment(form.name.data, form.email.data, form.body.data)
post.comments.append(post_comment)
else:
parent_id = int(form.parent.data)
parent_comment = Comment.by_id(parent_id)
parent_comment.childs.append(
Comment(
form.name.data,
form.email.data,
form.body.data,
parent_id,
)
)
return HTTPFound(
location=self.request.route_url('post_view',
year=year,
month=month,
day=day,
route=RouteAbleMixin.url_quote(post.title))
)
return dict(
form=form,
post=post,
pages=Page.all(),
logged_in=authenticated_userid(self.request),
)
示例6: view_ym
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import all [as 别名]
def view_ym(self):
year = int(self.request.matchdict['year'])
month = int(self.request.matchdict['month'])
return dict(
posts=Post.by_month(year, month),
pages=Page.all(),
logged_in=authenticated_userid(self.request),
)
示例7: get
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import all [as 别名]
def get(self, page_title):
page = Page.all().filter('title =', page_title).get()
data = {
'page': page,
'uri_for': uri_for,
}
template = jinja.get_template('page-edit.html')
return self.response.out.write(template.render(data))
示例8: update_pages
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import all [as 别名]
def update_pages():
logging.info('-> updateing pages')
from importing import get_docs_data
docs = get_docs_data(Var.get_value('admin'),Var.get_value('password'))
docs_by_keys = dict((doc['res_id'],doc) for doc in docs)
updated_or_deleted = set()
updated_cnt = deleted_cnt = created_cnt = 0
# updateing
for page in Page.all():
# delete
if not page.res_id in docs_by_keys:
page.delete()
deleted_cnt+=1
logging.info('page %s deleted'%page.res_id)
updated_or_deleted.add( page.res_id )
else:
doc = docs_by_keys[page.res_id]
# update existing
page.slug = doc['slug']
page.lang = doc['lang']
page.title = doc['title']
page.etag = doc['etag']
page.updated = doc['updated']
page.content = get_doc_content(doc['src'])
page.src = doc['src']
page.edit_url = doc['edit_url']
page.put()
logging.info('page %s updated'%doc['res_id'])
updated_cnt+=1
updated_or_deleted.add( page.res_id )
# new pages
new_pages_ids = set(docs_by_keys) - updated_or_deleted
for new_page_id in new_pages_ids:
doc = docs_by_keys[new_page_id]
# create new page
page = Page(key_name=doc['res_id'],
slug = doc['slug'],
lang = doc['lang'],
title = doc['title'],
etag = doc['etag'],
updated = doc['updated'],
src = doc['src'],
edit_url = doc['edit_url'],
content = get_doc_content(doc['src']),
)
page.put()
logging.info('page %s created'%doc['res_id'])
created_cnt+=1
logging.info('<- updateing pages updated=%s created=%s deleted=%s'%(updated_cnt, created_cnt, deleted_cnt))
示例9: update_cache
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import all [as 别名]
def update_cache(self):
""" odswiezenie calego cachu stron """
cnt = 0
for page in Page.all():
ok, _ = page.update_cache()
ok2 = page.update_cache_content()
if ok and ok2:
cnt+=1
self.set_flash(u'Odświeżono w cache %s stron.'%cnt)
return self.redirect_to('admin')
示例10: search
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import all [as 别名]
def search(request):
hits = 0
params = {}
s = request.GET.get('s', '')
results = Page.all()
results.search(s)
for result in results:
hits += 1
params['results'] = results
return respond(request, 'wiki/list', params)
示例11: get
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import all [as 别名]
def get(self):
output = get_cache("home")
if output is None:
items = Page.all().order('-publish_date').fetch(50)
context = {
"items": items,
"title": "Hacker Posts",
}
# calculate the template path
output = self.render("index.html", context)
memcache.add("home", output, 3600)
self.response.out.write(output)
示例12: respond
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import all [as 别名]
def respond(request, template, params=None):
if params is None:
params = {}
if request.LANGUAGE_CODE != 'en':
params['is_foreign'] = request.LANGUAGE_CODE
if not template.endswith('.html'):
template += '.html'
params['skin'] = settings.SKIN
params['app_id'] = settings.APP_ID
session_token = None
user = users.get_current_user()
if user:
params['user'] = user
params['author'] = db.Query(Author).filter('email = ', user.email()).get()
if users.IsCurrentUserAdmin():
params['authsub_url'], session_token, client = check_auth(request, user)
params['is_admin'] = True # users.IsCurrentUserAdmin() # global
params['developer'] = ('Dev' in os.getenv('SERVER_SOFTWARE'))
params['sign_out'] = users.CreateLogoutURL('/')
else:
params['sign_in'] = users.CreateLoginURL(request.path)
params['session_token'] = session_token
# Events
startTime = datetime.datetime.now() + datetime.timedelta(weeks=-2)
endTime = datetime.datetime.now() + datetime.timedelta(weeks=2)
urlparams = 'start-min=%s&start-max=%s' % (startTime.strftime("%Y-%m-%dT%H:%M:%S"), endTime.strftime("%Y-%m-%dT%H:%M:%S"))
url = 'http://www.google.com/calendar/feeds/%s/public/basic?' % settings.GOOGLE_ACCOUNT
url = url + urlparams
feed = urlfetch.fetch(url)
calendar = feedparser.parse(feed.content)
events = calendar['entries']
params['events'] = events
# sidebar categories & page links
categories = Category.all()
categories.order("sequence")
params['categories'] = categories
pages = Page.all()
pages.order("sequence")
params['pages'] = pages
return shortcuts.render_to_response(template, params)
示例13: set_on_cdn
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import all [as 别名]
def set_on_cdn():
cursor = request.form.get('cursor', None)
pages = Page.all()
if cursor:
pages.with_cursor(start_cursor=cursor)
requeue = False
for page in pages.fetch(100):
requeue = True
page.on_cdn = False
page.put()
page.queue_upload()
if requeue:
taskqueue.add(url=url_for('tasks.set_on_cdn'), params={'cursor': pages.cursor()})
return 'OK'
示例14: get
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import all [as 别名]
def get(self):
section = None
if self.request.get('section'):
try:
section = Section.get( self.request.get('section') )
except BadKeyError:
# invalid key
self.redirect('.')
pages = Page.all().filter('section =', section).order('-inserted').fetch(page_count+1)
else:
pages = Page.all().order('-inserted').fetch(page_count+1)
more = True if len(pages) > page_count else False
vals = {
'title' : 'Page List',
'sections' : Section.all(),
'section' : section,
'pages' : pages,
'page_count' : page_count if more else len(pages),
'more' : more,
}
self.template( 'page-list.html', vals, 'admin' );
示例15: post
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import all [as 别名]
def post(self, **kwargs):
try:
privatekey = '792ec9274bc52418e995f355e3a8a4d1'
if hashlib.md5(self.request.get("security_data") + privatekey).hexdigest() != self.request.get("security_hash"):
self.abort(500)
referrer = urllib.unquote(self.request.get("referrer"))
referrer = referrer.split('|')
uid = referrer[0]
pages = referrer[1]
subscriber_info = {}
subscriber_info['details'] = self.request.get("details")
subscriber_info['event'] = self.request.get("event")
subscriber_info['productname'] = self.request.get("productname")
subscriber_info['quantity'] = self.request.get("quantity")
subscriber_info['reference'] = self.request.get("reference")
subscriber_info['uid'] = uid
subscriber_info['pages'] = pages
subscriber_info['status'] = self.request.get("status")
subscriber_info['type'] = self.request.get("type")
subscriber_info['enddate'] = self.request.get("enddate")
subscriber_info['nextperioddate'] = self.request.get("nextperioddate")
subscriber_info = simplejson.dumps(subscriber_info)
user = User.get_by_key_name(uid)
user.subscriber_info = subscriber_info
db.put(user)
if self.request.get("event") == 'Active':
pages = pages.split(',');
batch = []
for p in pages:
page = Page.get_by_key_name(p)
if page:
page.upgraded = '1'
page.upgraded_by = user
batch.append(page)
db.put(batch)
if self.request.get("event") == 'Inactive':
pages = Page.all().filter('upgraded_by =', user)
batch = []
for p in pages:
p.upgraded = '0'
p.upgraded_by = None
batch.append(p)
db.put(batch)
self.response.set_status(200)
except:
logging.error('Listen Error')
self.abort(500)