本文整理汇总了Python中models.Article.all方法的典型用法代码示例。如果您正苦于以下问题:Python Article.all方法的具体用法?Python Article.all怎么用?Python Article.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Article
的用法示例。
在下文中一共展示了Article.all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def index():
articles = Article.all()
if 'email' in session:
person = Person.query.filter_by(email=session['email']).first()
name = person.firstname
return render_template('index.html', articles=articles, name=name)
return render_template('index.html', articles=articles)
示例2: check
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def check():
q = Article.all()
q.order("datetime")
# check_cursor = memcache.get("check_cursor")
# if check_cursor:
# q.with_cursor(start_cursor = check_cursor)
chunk_size = 30
articles = q.fetch(chunk_size)
art_ctr = 0
l = []
for article in articles:
# if not article.sentiment:
# article.analyzed = False
# article.put()
art_ctr += 1
l.append(".")
count = len(articles)
# if len(articles) < chunk_size:
# memcache.delete("check_cursor")
# if check_cursor:
# memcache.set("check_cursor",check_cursor, 11000)
# else:
# memcache.add("check_cursor",check_cursor, 11000)
return [count,art_ctr,unicode(l)]
示例3: get
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def get(self):
query = Article.all().order('-pub_date')
posts = query.fetch(10)
rss_items = []
for post in posts:
this_link = self.request.host_url + "/posts/" + post.slug
item = PyRSS2Gen.RSSItem(
title=post.title,
link=this_link,
description=post.body_html,
guid="",
pubDate=post.pub_date
)
rss_items.append(item)
rss = PyRSS2Gen.RSS2(
title=settings['blog_title'],
link=self.request.host_url,
description="a blog by " + settings['author'],
lastBuildDate=datetime.datetime.now(),
items=rss_items
)
rss_xml = rss.to_xml()
self.response.headers['Content-Type'] = 'application/rss+xml'
self.response.out.write(rss_xml)
示例4: all_sentiment_old_articles
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def all_sentiment_old_articles():
q = Article.all()
q.order("datetime")
# memcache.delete("ana_old_cursor") #debug only
ana_old_cursor = memcache.get("ana_old_cursor")
if ana_old_cursor:
q.with_cursor(start_cursor = ana_old_cursor)
chunk_size = 8
articles = q.fetch(chunk_size)
for article in articles:
if not article.analyzed:
# if article.clean and not article.sentiment:
sentiment(article)
# article.sentiment = "sugar"
if len(articles) < chunk_size:
memcache.delete("ana_old_cursor")
if ana_old_cursor:
memcache.set("ana_old_cursor",ana_old_cursor, 11000)
else:
memcache.add("ana_old_cursor",ana_old_cursor, 11000)
示例5: index
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def index(page = 1):
articles = Article.all().paginate(page,app.config['POST_PER_PAGE'],False)
if 'email' in session:
person = Person.query.filter_by(email=session['email']).first()
name = person.firstname
return render_template('index.html', articles= articles, name=name)
return render_template('index.html', articles= articles)
示例6: get
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def get(self):
was_here = self.get_cookie('was_here', False)
tweets = self.cache.get("tweets")
if not was_here:
self.set_cookie('was_here', '1')
articles = Article.all({'slug': 'article-pertama'})
self.render("home", articles=articles, was_here=was_here, tweets=tweets)
示例7: all_articles
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def all_articles():
# q = Article.all(keys_only=True) #fetching only the key, not the whole object.
# fetch only the titles, and use them for comparison
q = Article.all()
# q = Article.all(projection=["title"]) funker ikke. feil med syntaks i doku.
article_keys = q.fetch(10000) # this is just wrong! you are not fetching the keys here.
duplicates = []
for article_key in article_keys: # this is also just wrong - never dupe check on keys - they are all different!
if article_key.title in duplicates:
db.delete(article_key)
else:
duplicates.append(article_key.title)
示例8: articles
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def articles():
article_keys = memcache.get("article_keys")
# logging.debug("dupe() article keys: %s", article_keys[:3])
duplicate_check = memcache.get("duplicate_check")
# dupe check skal inneholde:
# i verste fall:
# alle fra db - hente derfra hvis ingen dupe check
# i beste fall:
# de som ble skrapet forrige gang = article keys nå + dupe checks skal lagres som neste dupe check
delete_ctr = 0
if article_keys: # lagret av forrige scrape
# logging.debug("article keys exist in dupes")
if duplicate_check: # lagret av forrige duplicates
for article_key in article_keys:
article = Article.get_by_id(article_key.id())
if article:
if article.title in duplicate_check:
db.delete(article)
article_keys.remove(article_key)
delete_ctr += 1
else:
duplicate_check.append(article.title)
memcache.set("duplicate_check", duplicate_check)
memcache.set("article_keys", article_keys, 7200)
else:
q = Article.all(keys_only=True)
# q.order("datetime") no datetime on keys
keys = q.fetch(500)
duplicate_check = []
for key in keys:
article = Article.get_by_id(key.id())
duplicate_check.append(article.title)
for article_key in article_keys:
article = Article.get_by_id(key.id())
if article:
if article.title in duplicate_check:
db.delete(article)
article_keys.remove(article_key)
delete_ctr += 1
else:
duplicate_check.append(article.title)
memcache.set("duplicate_check", article_keys, 7200)
memcache.set("article_keys", article_keys, 7200)
elif duplicate_check:
# logging.debug("article keys do NOT exist in dupes")
memcache.set("duplicate_check", duplicate_check, 7200)
logging.debug("deleted %s duplicate articles", delete_ctr)
示例9: settings
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def settings():
articles = Article.all()
if 'email' in session:
person = Person.query.filter_by(email=session['email']).first()
form = PersonUpdateForm(request.form, person)
name = person.firstname
if form.validate_on_submit():
form.populate_obj(person)
db.session.merge(person)
db.session.commit()
return render_template('index.html', articles=articles)
return render_template('settings.html', form=form, name=name)
return render_template('index.html', articles=articles)
示例10: create_article
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def create_article(request):
articles = Article.all()
if request.method == "POST":
form = ArticleForm(request.POST)
if form.is_valid():
article = Article(title=form.cleaned_data['title'],
body=form.cleaned_data['body'])
article.put()
messages.success(request, 'Article created successful')
return redirect('create_article')
return render_to_response('create_article.html', dict(articles=articles))
示例11: update_article
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def update_article(request, article_id):
article = Article.get_by_id(int(article_id))
articles = Article.all()
if request.method == "POST":
form = ArticleForm(request.POST)
if form.is_valid():
article.title = form.cleaned_data['title']
article.body = form.cleaned_data['body']
article.put()
messages.success(request, 'Article updated successfully')
return redirect('create_article')
return render_to_response('create_article.html', dict(articles=articles, article=article, form_action="edit"))
示例12: get
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def get(self):
path = self.request.path.replace('citeulike/', '')
url = 'http://www.citeulike.org' + path
socket = urllib.urlopen(url)
# Build template
template = Template(open('views/page.html').read())
attrs = citeulike.page_metadata(socket.read(), url)
attrs['views'] = Article.all().filter("id =", self.request.path).count()
s = template.render_unicode(attributes=attrs)
# Render the page
self.response.out.write(template.render_unicode(attributes=attrs))
# Record that this article has been viewed
article = Article(id=self.request.path, last_viewed=datetime.now())
article.put()
示例13: get
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def get(self):
"""
Simple offset-based endless json/jsonp feed
"""
articles = Article.all().filter('publish_state = ', True)\
if self.request.get('start') and self.request.get('end'):
articles = articles.filter('publish_date >=',
datetime.strptime(self.request.get('start'), '%d/%m/%Y')
).filter('publish_date <=',
datetime.strptime(self.request.get('end'), '%d/%m/%Y'))
articles = articles.order('-publish_date').fetch(10, offset=int(self.request.get('offset', 0)))
articles = [to_dict(item) for item in articles]
callback = self.request.get('callback')
if callback:
self.jsonp_response(articles, callback)
else:
self.json_response(articles)
示例14: add_article
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def add_article():
"""Add a article."""
form = ArticleForm()
if request.method == 'POST':
if form.validate_on_submit():
# Get the right number - the article ID
number = 1
articles = Article.all().order('-number')
if articles.count() > 0:
number = articles[0].number + 1
article = Article(
number=number,
title=form.title.data,
content=form.content.data,
tags=form.tags.data,
is_public=form.is_public.data,
)
article.save()
return redirect(article.get_absolute_url())
action_url = url_for('add_article')
return render_template('add_article.html', form=form, action_url=action_url)
示例15: check_all_articles
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def check_all_articles():
q = Article.all(keys_only=True)
# q.order("datetime") no datetime in keys
article_keys = q.fetch(10000)
# maintenance = memcache.get("maintenance")
# if maintenance:
# article = maintenance.pop() # last element is removed in place
# check(article)
# memcache.set("maintenance", maintenance)
# else:
# q = Article.all().filter("clean =", None) # now, it doesn't check those with clean == True!
# articles = q.fetch(8)
# memcache.add("articles", articles)
duplicates = []
changed_ctr = 0
dupe_ctr = 0
for key in article_keys:
article = Article().get_by_id(key.id())
if article == None:
if article.title in duplicates:
db.delete(article)
dupe_ctr += 1
else:
duplicates.append(article.title)
changed = check(article)
if changed:
changed_ctr += 1
logging.debug("janitored %s articles", changed_ctr)
logging.debug("janitor dupe removed %s articles", dupe_ctr)
article_keys = memcache.get("article_keys")
if article_keys and len(article_keys) > 1000:
memcache.set("article_keys", article_keys[:500])