本文整理汇总了Python中models.Article.title方法的典型用法代码示例。如果您正苦于以下问题:Python Article.title方法的具体用法?Python Article.title怎么用?Python Article.title使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Article
的用法示例。
在下文中一共展示了Article.title方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getArticles
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import title [as 别名]
def getArticles():
articles = Article.query()
if articles.count() == 0:
hello = Article()
hello.title = "Hello World"
hello.content = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur, voluptatum. Provident accusamus sit, commodi corrupti illo, veniam possimus minima rerum itaque. Magni, beatae, facere."
hello.put()
bye = Article()
bye.title = "Bye World"
bye.content = "Iraqi PM Nouri Maliki steps aside, ending political deadlock in Baghdad as the government struggles against insurgents in the north."
bye.put()
del hello, bye
articles = Article.query()
return serialize(list(articles.order(Article.date).fetch(10)))
示例2: post
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import title [as 别名]
def post(self):
d = json.loads(self.request.body)
if d['secret'] == '16jutges16':
if 'key' in d and len(d['key']) > 10: #Keys are looong.
article = ndb.Key(urlsafe = d['key']).get()
logging.info('Modifying entry {}'.format(d['key']))
else:
article = Article()
article.slug = d['slug']
article.title = d['title']
article.text = d['text']
if 'when' in d:
# Matches isoformat into datetime object. Found in stackoverflow
article.when = datetime.datetime(
*map(int, re.split('[^\d]', d['when'])[:-1])
)
else:
article.when = datetime.datetime.now()
try:
article.keywords = string.split(d['keywords'])
except AttributeError:
article.keywords = d['keywords']
article.put()
示例3: submitarticle
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import title [as 别名]
def submitarticle(request):
error_msg = u"No POST data sent."
if request.method == "POST":
post = request.POST.copy()
if post.has_key('tags') and post.has_key('title') and post.has_key('url'):
try:
url = post['url']
art = Article()
art.tags = post['tags'].strip().split(',')
art.author = str(request.user)
art.title = post['title']
art.votecount = 0
art.viewcount = 0
if not url.startswith('http://'):
url = 'http://'+url
art.url = url
if art.url and art.title and art.author:
try:
person = getPerson(request)
person.timesArticle = person.timesArticle + 1
person.lastActive = datetime.datetime.now()
rating = Score.objects(type='submitarticle')[0].value
person.currentRating = person.currentRating + rating
person.save()
incrementStat('articles',1)
art.save()
except Exception as inst:
print inst
return HttpResponseRedirect('/')
except:
return HttpResponseServerError('wowza! an error occurred, sorry!')
else:
error_msg = u"Insufficient POST data (need 'content' and 'title'!)"
return HttpResponseServerError(error_msg)
示例4: new_blog
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import title [as 别名]
def new_blog(request):
if request.method == "POST":
form = BlogForm(request.POST)
if form.is_valid():
_blog = form.save(commit=False)
req_url = BASE_URL % (_blog.name, TEST_API_KEY)
# parse json
req = requests.get(req_url)
jsonlist = json.loads(req.content)
response = jsonlist['response']
posts = response['posts']
blog = response['blog']
# for post in posts:
# print post['body']
_blog.title = blog['title']
_blog.url = blog['url']
_blog.save()
for post in posts:
article = Article()
article.title = post['title']
article.url = post['post_url']
article.description = post['body']
# article.published_date =
# datetime.datetime.fromtimestamp(float(post['timestamp']))
# print article.published_date
article.blog = _blog
article.save()
return redirect('blogs.views.articles_list')
else:
form = BlogForm()
return render(request, "new_blog.html", {"form": form})
示例5: article_save
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import title [as 别名]
def article_save():
mid = request.form.get('id')
title = request.form.get('title', '')
content = request.form.get('content', '')
if (mid == None or mid == ''):
article = Article(title=title, content=content, add_time=datetime.now(), edit_time=datetime.now())
for cid in request.form.getlist("tags"):
article.tags.add(Tag.query.get(cid))
for cid in request.form.getlist("categories"):
article.categories.add(Category.query.get(cid))
db.session.add(article)
else:
article = Article.query.get(int(mid))
article.title=title
article.content=content
article.edit_time=datetime.now()
article.categories.clear()
article.tags.clear()
for cid in request.form.getlist("tags"):
article.tags.add(Tag.query.get(cid))
for cid in request.form.getlist("categories"):
article.categories.add(Category.query.get(cid))
db.session.commit()
flash('保存成功!', 'success')
return redirect(url_for('.article',page=1))
示例6: create
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import title [as 别名]
def create():
csrf_token = request.form.get('csrf_token')
upload_folder = os.path.join(app.config['UPLOAD_FOLDER'], mod.name, csrf_token, 'files')
form = RegistrationForm()
if not os.path.exists(upload_folder):
flash(u'Selecione o arquivo do artigo para enviá-lo.', 'danger')
return render_template('scholar/new.html', form=form)
if form.validate() is False:
return render_template('scholar/new.html', form=form)
else:
article = Article()
article.title = form.title.data
article.theme = form.theme.data
article.abstract = form.abstract.data
article.postage_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
article.approval_status = 0
author_input_list = form.authors.data.split(',')
for author_input in author_input_list:
article.authors.append(AuthorScholar(author_input))
keyword_input_list = form.keywords.data.split(',')
for keyword_input in keyword_input_list:
keyword = KeyWord.query.filter_by(name=keyword_input).first()
if not keyword:
article.keywords.append(KeyWord(keyword_input))
else:
article.keywords.append(keyword)
db.session.add(article)
db.session.flush()
if os.path.exists(upload_folder):
file_name = [file for file in os.listdir(upload_folder)][0]
article.url = upload_helper.upload_s3_file(
os.path.join(upload_folder, file_name),
os.path.join('scholar/', str(article.id), 'files/', 'article'),
{
'ContentType': "application/pdf",
'ContentDisposition': 'attachment; filename=dataviva-article-' + str(article.id) + '.pdf'
}
)
shutil.rmtree(os.path.split(upload_folder)[0])
db.session.commit()
message = u'Muito obrigado! Seu estudo foi submetido com sucesso e será analisado pela equipe do DataViva. \
Em até 15 dias você receberá um retorno sobre sua publicação no site!'
flash(message, 'success')
return redirect(url_for('scholar.index'))
示例7: create
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import title [as 别名]
def create():
csrf_token = request.form.get('csrf_token')
upload_folder = os.path.join(app.config['UPLOAD_FOLDER'], mod.name, csrf_token, 'files')
form = RegistrationForm()
if not os.path.exists(upload_folder):
flash(u'Selecione o arquivo do artigo para enviá-lo.', 'danger')
return render_template('scholar/new.html', form=form)
if form.validate() is False:
form.set_choices(approved_articles_keywords())
return render_template('scholar/new.html', form=form)
else:
article = Article()
article.title = form.title.data
article.theme = form.theme.data
article.abstract = form.abstract.data
article.postage_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
article.approval_status = 0
author_input_list = form.authors.data.replace(', ', ',').split(',')
for author_input in author_input_list:
article.authors.append(AuthorScholar(author_input))
for keyword_input in form.keywords.data:
keyword = KeyWord.query.filter_by(name=keyword_input).first()
if not keyword:
article.keywords.append(KeyWord(keyword_input))
else:
article.keywords.append(keyword)
db.session.add(article)
db.session.flush()
if os.path.exists(upload_folder):
file_name = [file for file in os.listdir(upload_folder)][0]
article.file_url = upload_helper.upload_s3_file(
os.path.join(upload_folder, file_name),
os.path.join('scholar/', str(article.id), 'files/', 'article'),
{
'ContentType': "application/pdf",
'ContentDisposition': 'attachment; filename=dataviva-article-' + str(article.id) + '.pdf'
}
)
shutil.rmtree(os.path.split(upload_folder)[0])
db.session.commit()
upload_helper.log_operation(module=mod.name, operation='create', user=(g.user.id, g.user.email), objs=[(article.id, article.title)])
new_article_advise(article, request.url_root)
message = dictionary()["article_submission"]
flash(message, 'success')
return redirect(url_for('scholar.index'))
示例8: create
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import title [as 别名]
def create(request):
""" Create a new blog article
"""
# instantiate a new instance and populate fields from form data
article = Article()
article.title = request.POST.get("title", None)
article.author = request.user
article.content = request.POST.get("content", None)
# save new article, get updated articles list and user
article.save()
articles = Article.objects.all()
user = request.user
# render index page with updated data
return render(request, "index.html", {"testvar": "Test String 2!", "articles": articles, "user":user})
示例9: add_article
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import title [as 别名]
def add_article():
if request.method == 'POST':
art = Article()
art.author_id = current_user.id
art.body = request.form.get("body")
art.css = request.form.get("css")
art.javascript_before = request.form.get("javascript_before")
art.javascript_after = request.form.get("javascript_after")
art.title = request.form.get("title")
art.author_blurb = request.form.get("author_blurb")
base_app.db.session.add(art)
base_app.db.session.commit()
return default()
return render_template("add_article.html")
示例10: put
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import title [as 别名]
def put(self):
rbody = self.request.body.split('&')
rbody = dict([(p.split('=')[0], p.split('=')[1]) for p in rbody])
tid = rbody['tid']
article = Article.query.filter_by(id=tid).first()
if not article:
article = Article()
title = rbody['title']
content = rbody['content']
tag = rbody['tag']
try:
article.title = title
article.content = content
article.tag = tag
db.session.add(article)
db.session.flush()
db.session.commit()
except Exception as e:
raise tornado.web.HTTPError(500, 'edit article error')
self.write('ok')
示例11: __save_blog
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import title [as 别名]
def __save_blog(title, abstract, body, category_id, tag_names, article_id=None):
tags = []
for tag_name in tag_names.split(','):
tag, is_create = Tag.objects.get_or_create(name=tag_name)
tags.append(tag)
category = Category.objects.filter(id=category_id)[0]
if article_id is None:
article = Article(title=title, abstract=abstract, body=body, category=category)
else:
article = Article.objects.filter(id=article_id)[0]
article.title = title
article.abstract = abstract
article.body = body
article.category = category
article.save()
print dir(article)
article.tag.clear()
article.tag.add(*tags)
return article.id
示例12: post
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import title [as 别名]
def post(self):
til = self.get_argument('title', None)
content = self.get_argument('content', None)
uid = self.get_argument('uid', None)
tag = self.get_argument('tag', '')
cat = self.get_argument('cat_id', 0)
if not til or not content or not uid:
raise tornado.web.HTTPError(400, 'parameters invalid')
try:
article = Article()
article.title = til
article.content = content
article.user_id = int(uid)
article.tag = tag
article.cat_id = int(cat)
db.session.add(article)
db.session.flush()
db.session.commit()
except Exception as e:
raise tornado.web.HTTPError(500, 'add article error')
self.write('ok')
示例13: edit_article
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import title [as 别名]
def edit_article(request, id=None):
data = {}
article = Article()
if request.method == "POST":
form = ArticleForm(request.POST,instance=article) # A form bound to the POST data
if form.is_valid():
article.title = form.cleaned_data['title']
article.content = form.cleaned_data['content']
article.author = User.objects.get(pk=request.user.id)
article.save()
return HttpResponseRedirect('/blog/view/%s' % article.id)
elif request.method == "GET":
if id != None:
article = Article.objects.get(pk=id)
form = ArticleForm(instance=article)
else:
raise Http404
data['form'] = form
print form.errors
return render_to_response(BLOG_TEMPLATE + 'edit.html', data, context_instance=RequestContext(request))
示例14: post
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import title [as 别名]
def post(self, request, *args, **kwargs):
if request.session.get('account_id', None) is None:
return HttpResponseRedirect('/account/login')
d = request.POST.dict()
i = Article()
account_id = request.session['account_id']
i.account_id = str(account_id)
i.username = request.session['username']
tag = d.get('tag', None)
if tag != '':
if tag[-1] == ';':
tag = tag[:-1]
i.tag = tag.split(';')
i.category = int(d['category'])
i.head_image = d.get('head_image', None)
i.title = d['title']
i.content = d['content']
i.status = 1
i.save()
return HttpResponseRedirect('/blog')
示例15: post
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import title [as 别名]
def post(self):
from markdown2 import markdown
title = self.request.get('title')
content = self.request.get('content')
slug_title = self.request.get('slug_title')
section_type = self.request.get('section_type')
content_html = markdown(content)
#user = users.get_current_user()
article = Article()
article.title = title
article.slug_title = slug_title
article.content = content
article.section_type = section_type
#article.author = user
article.content_html = content_html
article.is_draft = True
article.put()
self.response.out.write(article.to_json('title', 'section_type', 'is_draft', 'is_deleted', 'is_active', 'is_starred'))