本文整理汇总了Python中model.Article类的典型用法代码示例。如果您正苦于以下问题:Python Article类的具体用法?Python Article怎么用?Python Article使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Article类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: getArticle
def getArticle():
article=Article()
articlelist=Article.query.all()
articles=[]
for article in articlelist:
articles.append(article.to_json())
return (jsonify(rows=articles))
开发者ID:shixiutingfen,项目名称:sugarcoffeeadmin,代码行数:7,代码来源:article.py
示例2: test_create_article
def test_create_article():
_author_id = random.randint(1, 20)
_new_article = Article()
_new_article.title = 'Test_Article_%s' % random.randint(100001, 999999)
_new_article.author_id = _author_id
_new_article.published_datetime = _new_article.last_modified_datetime = datetime.datetime.now()
_random_seed = str(random.random())
_new_article.digest = 'digest - %s' % (''.join(random.randint(2, 5)*md5(_random_seed).hexdigest()))
_content = ArticleContent(content='content - %s' % (''.join(random.randint(10, 50)*sha224(_random_seed).hexdigest())))
_new_article.content = _content
db_session.add(_new_article) # @UndefinedVariable
db_session.flush() # @UndefinedVariable
_catalogs = [
random.randint(1, 20),
random.randint(1, 20),
random.randint(1, 20),
]
for _cid in _catalogs:
db_session.execute(association_table_catalog_article.insert().values({ # @UndefinedVariable
'catalog_id': _cid,
'article_id': _new_article.id,
}))
db_session.commit() # @UndefinedVariable
开发者ID:gengv,项目名称:mantis,代码行数:28,代码来源:Article_Test.py
示例3: get
def get(self, id=""):
# try:
if id:
oldobj = Article.get_article_by_id_edit(id)
print "DelPost()", oldobj
if not oldobj:
return
if MYSQL_TO_KVDB_SUPPORT:
oldobj_category = oldobj["category"]
oldobj_archive = oldobj["archive"]
oldobj_tags = oldobj["tags"]
else:
oldobj_category = oldobj.category
oldobj_archive = oldobj.archive
oldobj_tags = oldobj.tags
Category.remove_postid_from_cat(oldobj_category, str(id))
Archive.remove_postid_from_archive(oldobj_archive, str(id))
Tag.remove_postid_from_tags(set(oldobj_tags.split(",")), str(id))
Article.del_post_by_id(id)
increment("Totalblog", NUM_SHARDS, -1)
cache_key_list = ["/", "post:%s" % id, "cat:%s" % quoted_string(oldobj_category)]
clear_cache_by_pathlist(cache_key_list)
clear_cache_by_pathlist(["post:%s" % id])
self.redirect("%s/admin/edit_post/" % (BASE_URL))
开发者ID:yobin,项目名称:saepy-log,代码行数:25,代码来源:admin.py
示例4: get
def get(self):
try:
objs = Article.get_post_for_homepage()
except:
self.redirect('/install')
return
if objs:
fromid = objs[0].id
endid = objs[-1].id
else:
fromid = endid = ''
allpost = Article.count_all_post()
allpage = allpost/EACH_PAGE_POST_NUM
if allpost%EACH_PAGE_POST_NUM:
allpage += 1
output = self.render('index.html', {
'title': "%s - %s"%(SITE_TITLE,SITE_SUB_TITLE),
'keywords':KEYWORDS,
'description':SITE_DECR,
'objs': objs,
'cats': Category.get_all_cat_name(),
'tags': Tag.get_hot_tag_name(),
'page': 1,
'allpage': allpage,
'listtype': 'index',
'fromid': fromid,
'endid': endid,
'comments': Comment.get_recent_comments(),
'links':Link.get_all_links(),
},layout='_layout.html')
self.write(output)
return output
开发者ID:bibodeng,项目名称:pyWeiXin_SAElog,代码行数:34,代码来源:blog.py
示例5: post
def post(self, secret=""):
articles = (self.get_argument("articles", ""),)
if articles and secret:
if secret == getAttr("MOVE_SECRET"):
Article.set_articles(articles[0])
return self.write("1")
return self.write("Fail")
开发者ID:yobin,项目名称:saepy-log,代码行数:7,代码来源:admin.py
示例6: run
def run(input_filename, output_filename):
articles = defaultdict(set)
without_identifiers = set()
reader = csv.reader(open(input_filename, 'r'))
try:
biggest = 0
for i, article in enumerate(reader):
article = Article(*article)
identifiers = [(k,v) for k,v in article._asdict().items() if k in IDENTIFIERS and v]
data = None # dict(identifiers)
if not identifiers:
without_identifiers.add(article.id)
continue
articles[identifiers[0]].add(article.id)
for identifier in identifiers[1:]:
if articles[identifiers[0]] is not articles[identifier]:
articles[identifiers[0]] |= articles[identifier]
articles[identifier] = articles[identifiers[0]]
if len(articles[identifier]) > biggest:
biggest = len(articles[identifier])
if i % 10000 == 0:
print "%7d" % i, resource.getrusage(resource.RUSAGE_SELF)[2], biggest
if resource.getrusage(resource.RUSAGE_SELF)[2] > 1e7:
print "Using too much memory"
raise Exception
except Exception, e:
print e
开发者ID:HeinrichHartmann,项目名称:OpenCitationsCorpus,代码行数:32,代码来源:unify_identifiers.py
示例7: editor
def editor(request):
content = request.POST['content']
title = request.POST['title']
article = Article(title=title,content=content,group='1');
article.save()
result = "文章保存成功!"
print result
return HttpResponse(result, mimetype='application/javascript')
开发者ID:zimuxh,项目名称:pb,代码行数:8,代码来源:views.py
示例8: get
def get(self):
posts = Article.get_post_for_homepage()
output = self.render('index.xml', {
'posts':posts,
'site_updated':Article.get_last_post_add_time(),
})
self.set_header('Content-Type','application/atom+xml')
self.write(output)
开发者ID:yobin,项目名称:saepy-log,代码行数:8,代码来源:blog.py
示例9: get
def get(self):
logging.info("Seeding Datastore...")
for user in users:
user_ent = User(name=user[0],
age=user[1])
user_ent.put()
for article in articles:
article_ent = Article(title=article[0])
article_ent.put()
开发者ID:timdiam,项目名称:datastore-to-bigquery-automation,代码行数:10,代码来源:handlers.py
示例10: _create_structure
def _create_structure():
category = Category('test category', 'category test', 'test_category')
category.meta = {'id': 1, 'webtranslateit_ids': {'content': 1}}
section = Section(category, 'test section', 'section test', 'test_section')
section.meta = {'id': 2, 'webtranslateit_ids': {'content': 2}}
category.sections.append(section)
article = Article(section, 'test article', 'article body', 'test_article')
article.meta = {'id': 3, 'webtranslateit_ids': {'content': 3, 'body': 4}}
section.articles.append(article)
return category, section, article
开发者ID:KeepSafe,项目名称:zendesk-helpcenter-cms,代码行数:10,代码来源:test_cms.py
示例11: source_fetch
def source_fetch(source):
debug("SF: Doing fetch for source: {0}".format(source.url))
result = _source_fetch(source)
debug("SF: Done with source fetch for {0}; result type: {1}".format(source.url, (result.method if result else None)))
added_any = False
now = datetime.datetime.now()
to_put = []
tasks_to_enqueue = []
if result:
if result.feed_title:
source.title = result.feed_title
if result.brand:
source.brand = result.brand
titles = [entry['title'] for entry in result.entries if entry['title']]
source.shared_title_suffix = shared_suffix(titles)
entries = result.entries[:min(25, len(result.entries))]
entry_ids = [Article.id_for_article(entry['url'], source.url) for entry in entries]
print "ENTRY IDs:", entry_ids
print "ENtry id lens: ", str(map(len, entry_ids))
article_futures = [Article.get_or_insert_async(id) for id in entry_ids]
articles = [future.get_result() for future in article_futures]
print "ARTICLE_OBJECTS:", articles
for i, (entry, article) in enumerate(zip(entries, articles)):
if not article.url:
added_any = True
article.added_date = now
article.added_order = i
article.source = source.key
article.url = canonical_url(entry.get('url'))
article.submission_url = canonical_url(entry.get('submission_url'))
if entry['published']:
article.published = entry['published']
else:
article.published = datetime.datetime.now()
if not article.title:
article.title = entry['title']
to_put.append(article)
delay = (i+1) * 4 # wait 5 seconds between each
tasks_to_enqueue.append(article.create_fetch_task(delay=delay))
debug("SF: About to put {0} items".format(len(to_put)))
if len(to_put):
ndb.put_multi(to_put)
debug("SF: About to enqueue")
if len(tasks_to_enqueue):
taskqueue.Queue('articles').add_async(tasks_to_enqueue)
debug("SF: done enqueuing")
if added_any:
source.most_recent_article_added_date = now
source_search.add_source_to_index(source)
source.last_fetched = now
source.put()
开发者ID:nate-parrott,项目名称:fast-news,代码行数:54,代码来源:source_fetch_old.py
示例12: get
def get(self, id = ''):
try:
if id:
oldobj = Article.get_article_by_id_edit(id)
Category.remove_postid_from_cat(oldobj.category, str(id))
Archive.remove_postid_from_archive(oldobj.archive, str(id))
Tag.remove_postid_from_tags( set(oldobj.tags.split(',')) , str(id))
Article.del_post_by_id(id)
increment('Totalblog',NUM_SHARDS,-1)
cache_key_list = ['/', 'post:%s'% id, 'cat:%s' % quoted_string(oldobj.category)]
clear_cache_by_pathlist(cache_key_list)
clear_cache_by_pathlist(['post:%s'%id])
self.redirect('%s/admin/edit_post/'% (BASE_URL))
except:
pass
开发者ID:yangzilong1986,项目名称:saepy-log,代码行数:15,代码来源:admin.py
示例13: get_response_article_by_id
def get_response_article_by_id(self, post_id):
global PIC_URL
# 从数据库查询得到若干文章
article = Article.get_article_by_id_detail(post_id)
# postId为文章id
if article:
title = article.slug
description = article.description
picUrl = PIC_URL
url = article.absolute_url
count = 1
# 这里实现相关逻辑,从数据库中获取内容
# 构造图文消息
articles_msg = {'articles':[]}
for i in range(0,count):
article = {
'title':title,
'description':description,
'picUrl':picUrl,
'url':url
}
# 插入文章
articles_msg['articles'].append(article)
article = {}
# 返回文章
return articles_msg
else:
return
开发者ID:bibodeng,项目名称:pyWeiXin_SAElog,代码行数:29,代码来源:blog.py
示例14: get_response_article
def get_response_article(self, keyword):
global PIC_URL
keyword = str(keyword)
# 从数据库查询得到若干文章
article = Article.get_article_by_keyword(keyword)
# 这里先用测试数据
if article:
title = article.slug
description = article.description
picUrl = PIC_URL
url = article.absolute_url
count = 1
# 也有可能是若干篇
# 这里实现相关逻辑,从数据库中获取内容
# 构造图文消息
articles_msg = {'articles':[]}
for i in range(0,count):
article = {
'title':title,
'description':description,
'picUrl':picUrl,
'url':url
}
# 插入文章
articles_msg['articles'].append(article)
article = {}
# 返回文章
return articles_msg
else:
return
开发者ID:bibodeng,项目名称:pyWeiXin_SAElog,代码行数:31,代码来源:blog.py
示例15: put_article
def put_article():
'''
Add new article for a user.
'''
username = request.headers.get('x-koala-username')
apikey = request.headers.get('x-koala-key')
user = locate_user(username, apikey)
reqjson = request.get_json()
result = validators.url(reqjson['url'])
if not result:
# try again but with http://
result = validators.url('http://' + reqjson['url'])
if not result:
logging.info("Bad URL: %s" % reqjson['url'])
abort(400)
else:
reqjson['url'] = 'http://' + reqjson['url']
title = reqjson.get('title', reqjson['url'])
url = reqjson['url']
date = str(datetime.now())
read = False
favorite = False
owner = user.id
article = Article.create(title=title, url=url, date=date, read=read, favorite=favorite, owner=owner)
return jsonify({'id': article.id}), 201
开发者ID:bostrt,项目名称:koala,代码行数:30,代码来源:koala.py
示例16: wx_search_article
def wx_search_article(self, k):
article = Article.get_article_by_keyword(k)
if article:
if MYSQL_TO_KVDB_SUPPORT:
title = article['slug']
description = article['description']
url = article['absolute_url']
else:
title = article.slug
description = article.description
url = article.absolute_url
picUrl = WX_DEFAULT_PIC
count = 1
articles_msg = {'articles':[]}
for i in range(0,count):
article = {
'title':title,
'description':description,
'picUrl':picUrl,
'url':url
}
articles_msg['articles'].append(article)
article = {}
return articles_msg
return ''
开发者ID:yobin,项目名称:saepy-log,代码行数:26,代码来源:blog.py
示例17: wx_get_article_by_id
def wx_get_article_by_id(self, post_id):
k = 'wx_post_%s' % (str(post_id))
v = getMc(k)
if v:
return v
article = Article.get_article_by_id_detail(post_id)
if article:
if MYSQL_TO_KVDB_SUPPORT:
title = article['slug']
description = article['description']
url = article['absolute_url']
else:
title = article.slug
description = article.description
url = article.absolute_url
picUrl = WX_DEFAULT_PIC
count = 1
articles_msg = {'articles':[]}
for i in range(0,count):
article = {
'title':title,
'description':description,
'picUrl':picUrl,
'url':url
}
articles_msg['articles'].append(article)
article = {}
setMc(k,articles_msg)
return articles_msg
return ''
开发者ID:yobin,项目名称:saepy-log,代码行数:32,代码来源:blog.py
示例18: wx_get_latest_articles
def wx_get_latest_articles(self):
k = 'wx_latest'
v = getMc(k)
if v:
return v
posts = Article.get_articles_by_latest()
articles_msg = {'articles':[]}
for post in posts:
#slug = slugfy(post['title'])#yobin 20160718
slug = post['title']
desc = HTML_REG.sub('',post['content'].decode('utf-8')[:DESCRIPTION_CUT_WORDS].encode('utf-8'))
shorten_url = '%s/t/%s' % (BASE_URL, post['id'])
article = {
'title': slug,
'description':desc,
'picUrl':WX_DEFAULT_PIC,
'url':shorten_url,
}
# 插入文章
articles_msg['articles'].append(article)
article = {}
setMc(k,articles_msg)
return articles_msg
开发者ID:yobin,项目名称:saepy-log,代码行数:26,代码来源:blog.py
示例19: get
def get(self, id):
article = Article.get(self.db, id)
if article is None:
error = '404: Page Not Found'
self.render('error.html', error=error, home_title=options.home_title)
else:
labels = ' '.join(map(lambda item: '[' + item['detail'] + ']', article['labels']))
self.render('editArticle.html', article=article, labels=labels)
开发者ID:adonis0147,项目名称:Blog,代码行数:8,代码来源:blog.py
示例20: get_articles
def get_articles(count=10, force=False):
max_time = datetime.datetime.now() if force else datetime.datetime.now() - datetime.timedelta(hours=1)
q = Article.query(Article.ml_service_time <= max_time, Article.ml_service_time != None).order(-Article.ml_service_time)
articles = q.fetch(count)
for a in articles:
a.ml_service_time = datetime.datetime.now()
ndb.put_multi(articles)
return articles
开发者ID:nate-parrott,项目名称:fast-news,代码行数:8,代码来源:ml.py
注:本文中的model.Article类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论