本文整理汇总了Python中models.Topic.get方法的典型用法代码示例。如果您正苦于以下问题:Python Topic.get方法的具体用法?Python Topic.get怎么用?Python Topic.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Topic
的用法示例。
在下文中一共展示了Topic.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: discussion
# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get [as 别名]
def discussion(topic_key):
messages = None
if topic_key:
topic = Topic.get(topic_key)
if not topic:
flash('No topic found', 'error')
return redirect(url_for('index'))
child_topics = []
for child_topic_key in topic.child_topics:
child_topics.append(Topic.get(child_topic_key))
messages = Message.all().filter('topic', topic).order('-created_at').fetch(limit=50)
return render_template('discussion.html', messages=messages, topic=topic, child_topics=child_topics)
示例2: put
# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get [as 别名]
def put(self, topic_id):
topic_id = int(topic_id)
topic = Topic.get(id=topic_id)
if not topic:
raise tornado.web.HTTPError(404)
action = self.get_argument('action', None)
user = self.current_user
if not action:
result = {'status': 'info', 'message':
'需要 action 参数'}
if action == 'up':
if topic.user_id != user.id:
result = user.up(topic_id=topic_id)
else:
result = {'status': 'info', 'message':
'不能为自己的主题投票'}
if action == 'down':
if topic.user_id != user.id:
result = user.down(topic_id=topic_id)
else:
result = {'status': 'info', 'message':
'不能为自己的主题投票'}
if action == 'collect':
result = user.collect(topic_id=topic_id)
if action == 'thank':
result = user.thank(topic_id=topic_id)
if action == 'report':
result = user.report(topic_id=topic_id)
if self.is_ajax:
return self.write(result)
else:
self.flash_message(**result)
return self.redirect_next_url()
示例3: store
# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get [as 别名]
def store(self, topic_name, article_entry_list):
"""Stores the article entries in the database.
:param topic_name The name of the topic
:param article_entry_list The list of entries of this topic
"""
try:
# Try to retrieve the topic to see if it exists already
topic = Topic.get(Topic.name == topic_name)
except Topic.DoesNotExist:
# If not, create it
topic = Topic.create(name=topic_name)
# Go through all the articles in this topic
for article_entry in article_entry_list:
article_name = article_entry.subject
# If there is no subject, it means the article is corrupted
# therefore we skip it
if not article_name:
continue
# Create the files with the content
# Overwrite existing files
try:
Article.create(topic=topic, subject=article_name,
body=article_entry.body)
except Article.DoesNotExist:
pass
示例4: get
# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get [as 别名]
def get(self, topic_id):
topic = Topic.get(id=topic_id)
if not topic:
return self.redirect_next_url()
if not topic.histories:
return self.redirect(topic.url)
return self.render("topic/history.html", topic=topic, histories=topic.histories)
示例5: seed_sources
# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get [as 别名]
def seed_sources():
crawler = GenericSourceCrawler(Scraper([GenericSourceParser]), Scraper([RSSParser]))
with open('resources/sources.dat') as f:
for source_url in f:
source = crawler.crawl(source_url.strip())
db_subscription = Subscription.update_or_create(Subscription.url == source.url,
url=source.url,
name=source.name,
image=source.image_url)
for topic in source.topics:
kwargs = {'source': db_subscription, 'name': topic.name, 'url': topic.url}
try:
Topic.get(**kwargs)
except Topic.DoesNotExist:
Topic.create(**kwargs)
示例6: poll
# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get [as 别名]
def poll():
messages = []
topic_key = request.args.get('topic_key')
if topic_key:
topic = Topic.get(topic_key)
if topic:
offset = int(request.args.get('offset'))
l = Message.all().filter('topic', topic).order('created_at').fetch(limit=100, offset=offset)
messages = [{'content': m.content, 'email': m.author.email, 'created_at': pretty_date(m.created_at), 'topic_key': str(m.topic.key())} for m in l]
return jsonify(messages=messages)
示例7: get
# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get [as 别名]
def get(self, topic_id):
topic = Topic.get(id=topic_id)
if topic and (topic.author == self.current_user or self.current_user.is_admin):
selected = topic.node.name
else:
return self.redirect_next_url()
choices = Node.get_node_choices()
args = {'node_name': [selected], 'title': [topic.title], 'content':
[topic.content]}
form = TopicForm.init(choices=choices, selected=selected, args=args)
return self.render("topic/create.html", form=form, node=topic.node)
示例8: change_topic_name
# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get [as 别名]
def change_topic_name():
title = request.form.get('title')
topic_key = request.form.get('topic_key')
if not title:
flash('Title required.', 'error')
if not topic_key:
flash('Topic not found.', 'error')
else:
topic = Topic.get(topic_key)
topic.title = title
topic.put()
return redirect(url_for('discussion', topic_key=topic_key))
示例9: post
# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get [as 别名]
def post():
content = ''
content = request.form.get('content')
topic_key = request.form.get('topic_key')
if not topic_key:
flash('Topic not found.')
if not content:
flash('Content required.')
topic = Topic.get(topic_key)
message = Message(content=content, author=g.user, topic=topic)
message.put()
return redirect(url_for('discussion', topic_key=topic_key))
示例10: create_topic
# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get [as 别名]
def create_topic():
title = start = end = parent_topic_key = ''
message = None
if request.method == 'POST':
title = request.form.get('title')
if not title:
flash('Title required.', 'error')
else:
topic = Topic(title=title, author=g.user)
parent_topic_key = request.form.get('parent_topic_key')
parent_topic = None
if parent_topic_key:
parent_topic = Topic.get(parent_topic_key)
topic.parent_topic = parent_topic
start = request.form.get('start')
if start:
try:
start = datetime.strptime(start, '%Y-%m-%d %H:%M')
except ValueError:
start = datetime.now()
topic.start = start
end = request.form.get('end')
if end:
try:
end = datetime.strptime(end, '%Y-%m-%d %H:%M')
topic.end = end
except ValueError:
pass
new_topic_key = topic.put()
if parent_topic:
parent_topic.child_topics.append(new_topic_key)
parent_topic.put()
flash('Topic "%s" created.!' % title)
return redirect(url_for('discussion', topic_key=new_topic_key))
elif request.method == 'GET':
message_key = request.args.get('message_key')
if message_key:
message = Message.get(message_key)
parent_topic_key = str(message.topic.key())
start = datetime.now().strftime('%Y-%m-%d %H:%M')
title = 'On - %s' % message.content
return render_template('index.html', title=title, start=start, end=end,
parent_topic_key=parent_topic_key, message=message)
示例11: post
# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get [as 别名]
def post(self, topic_id):
topic = Topic.get(id=topic_id)
if not topic or (topic.author != self.current_user and not self.current_user.is_admin):
return self.redirect_next_url()
user = self.current_user
form = TopicForm(self.request.arguments)
if form.validate():
topic = form.save(user=user, topic=topic)
topic.put_notifier()
result = {'status': 'success', 'message': '主题修改成功',
'topic_url': topic.url}
if self.is_ajax:
return self.write(result)
self.flash_message(**result)
return self.redirect(topic.url)
if self.is_ajax:
return self.write(form.result)
return self.render("topic/create.html", form=form, node=topic.node)
示例12: post
# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get [as 别名]
def post(self, topic_id):
if not self.has_permission:
return
topic = Topic.get(id=topic_id)
if not topic:
return self.redirect_next_url()
user = self.current_user
form = TopicForm(self.request.arguments)
if form.validate():
topic = form.save(user=user, topic=topic)
result = {'status': 'success', 'message': '主题修改成功',
'topic_url': topic.url}
if self.is_ajax:
return self.write(result)
self.flash_message(result)
return self.redirect(topic.url)
if self.is_ajax:
return self.write(form.result)
return self.render("topic/create.html", form=form, node=topic.node)
示例13: post
# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get [as 别名]
def post(self):
if not self.has_permission:
return
page = int(self.get_argument("page", 1))
topic_id = int(self.get_argument("topic_id", 0))
topic = Topic.get(id=topic_id)
if not topic_id:
result = {"status": "error", "message": "无此主题,不能创建评论"}
if self.is_ajax:
return self.write(result)
else:
self.flash_message(result)
return self.redirect_next_url()
user = self.current_user
form = ReplyForm(self.request.arguments)
if form.validate():
reply = form.save(user=user, topic=topic)
if 'class="mention"' in reply.content:
put_notifier(reply)
result = {
"status": "success",
"message": "评论创建成功",
"content": reply.content,
"name": reply.author.name,
"nickname": reply.author.nickname,
"author_avatar": reply.author.get_avatar(size=48),
"author_url": reply.author.url,
"author_name": reply.author.name,
"author_nickname": reply.author.nickname,
"reply_url": reply.url,
"created": reply.created,
"id": reply.id,
"floor": reply.floor,
}
if self.is_ajax:
return self.write(result)
self.flash_message(result)
return self.redirect(topic.url)
if self.is_ajax:
return self.write(form.result)
self.flash_message(form.result)
return self.render("topic/index.html", form=form, topic=topic, category="index", page=page)
示例14: post
# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get [as 别名]
def post(self):
if not self.has_permission:
return
page = int(self.get_argument('page', 1))
topic_id = int(self.get_argument('topic_id', 0))
topic = Topic.get(id=topic_id)
if not topic_id:
result = {'status': 'error', 'message':
'无此主题,不能创建评论'}
if self.is_ajax:
return self.write(result)
else:
self.flash_message(result)
return self.redirect_next_url()
user = self.current_user
form = ReplyForm(self.request.arguments)
if form.validate():
reply = form.save(user=user, topic=topic)
if 'class="mention"' in reply.content:
put_notifier(reply)
result = {'status': 'success', 'message': '评论创建成功',
'content': reply.content, 'name': reply.author.name,
'nickname': reply.author.nickname, 'author_avatar':
reply.author.get_avatar(size=48), 'author_url':
reply.author.url, 'author_name': reply.author.name,
'author_nickname': reply.author.nickname,
'reply_url': reply.url, 'created': reply.created,
'id': reply.id, 'floor': reply.floor}
if self.is_ajax:
return self.write(result)
self.flash_message(result)
return self.redirect(topic.url)
if self.is_ajax:
return self.write(form.result)
self.flash_message(form.result)
return self.render("topic/index.html", form=form, topic=topic,
category='index', page=page)
示例15: post
# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get [as 别名]
def post(self):
page = int(self.get_argument('page', 1))
category = self.get_argument('category', 'index')
topic_id = int(self.get_argument('topic_id', 0))
topic = Topic.get(id=topic_id)
if not topic_id:
result = {'status': 'error', 'message': '无此主题,不能创建评论'}
if self.is_ajax:
return self.write(result)
else:
self.flash_message(**result)
return self.redirect_next_url()
user = self.current_user
form = ReplyForm(self.request.arguments)
if form.validate():
reply = form.save(user=user, topic=topic)
reply.put_notifier()
result = {'status': 'success', 'message': '评论创建成功',
'content': reply.content, 'name': reply.author.name,
'nickname': reply.author.nickname, 'author_avatar':
reply.author.get_avatar(size=48), 'author_url':
reply.author.url, 'author_name': reply.author.name,
'author_nickname': reply.author.nickname,
'reply_url': reply.url, 'created': reply.created,
'id': reply.id, 'floor': reply.floor}
if self.is_ajax:
return self.write(result)
self.flash_message(**result)
return self.redirect(topic.url)
reply_count = topic.reply_count
page_count = (reply_count + config.reply_paged - 1) // config.reply_paged
replies = topic.get_replies(page=page, category=category)
data = dict(form=form, topic=topic, replies=replies, category=category, page=page, page_count=page_count,
url=topic.url)
return self.send_result_and_render(form.result, "topic/index.html", data)