本文整理汇总了Python中models.Topic类的典型用法代码示例。如果您正苦于以下问题:Python Topic类的具体用法?Python Topic怎么用?Python Topic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Topic类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: post
def post(self):
creator = users.get_current_user()
title = self.request.get('title')
descrip = self.request.get('descrip')
start = util.convert_htmldatetime(self.request.get('start'))
end = util.convert_htmldatetime(self.request.get('end'))
slot_minutes = int(self.request.get('slot_minutes'))
topic = Topic(
creator=creator,
title=title,
descrip=descrip,
start=start,
end=end,
slot_minutes=slot_minutes)
topic.put()
# Now create slots
current_slot = start
while (current_slot < end):
slot = TopicSlot(start=current_slot, topic=topic)
slot.put()
current_slot += datetime.timedelta(minutes=slot_minutes)
self.redirect(topic.full_link)
开发者ID:djensenius,项目名称:hangout-scheduler,代码行数:25,代码来源:pages.py
示例2: store
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
开发者ID:QFAPP,项目名称:QF,代码行数:30,代码来源:__init__.py
示例3: recursive_copy_topic_list_structure
def recursive_copy_topic_list_structure(parent, topic_list_part):
delete_topics = {}
for topic_dict in topic_list_part:
logging.info(topic_dict["name"])
if "playlist" in topic_dict:
topic = Topic.get_by_title_and_parent(topic_dict["name"], parent)
if topic:
logging.info(topic_dict["name"] + " is already created")
else:
version = TopicVersion.get_edit_version()
root = Topic.get_root(version)
topic = Topic.get_by_title_and_parent(topic_dict["playlist"], root)
if topic:
delete_topics[topic.key()] = topic
logging.info("copying %s to parent %s" %
(topic_dict["name"], parent.title))
topic.copy(title=topic_dict["name"], parent=parent,
standalone_title=topic.title)
else:
logging.error("Topic not found! %s" % (topic_dict["playlist"]))
else:
topic = Topic.get_by_title_and_parent(topic_dict["name"], parent)
if topic:
logging.info(topic_dict["name"] + " is already created")
else:
logging.info("adding %s to parent %s" %
(topic_dict["name"], parent.title))
topic = Topic.insert(title=topic_dict["name"], parent=parent)
if "items" in topic_dict:
delete_topics.update(
recursive_copy_topic_list_structure(topic,
topic_dict["items"]))
return delete_topics
开发者ID:di445,项目名称:server,代码行数:35,代码来源:topics.py
示例4: save
def save(self):
topic_post = False
if not self.topic:
topic_type = self.cleaned_data['topic_type']
if topic_type:
topic_type = TopicType.objects.get(id=topic_type)
else:
topic_type = None
topic = Topic(forum=self.forum,
posted_by=self.user,
subject=self.cleaned_data['subject'],
need_replay=self.cleaned_data['need_replay'],
need_reply_attachments=self.cleaned_data['need_reply_attachments'],
topic_type=topic_type,
)
topic_post = True
topic.save()
else:
topic = self.topic
post = Post(topic=topic, posted_by=self.user, poster_ip=self.ip,
message=self.cleaned_data['message'], topic_post=topic_post)
post.save()
attachments = self.cleaned_data['attachments']
post.update_attachments(attachments)
return post
开发者ID:macdylan,项目名称:LBForum,代码行数:25,代码来源:forms.py
示例5: new_topic
def new_topic(request,gname):
'''
login user add a new topic
'''
vars = {}
group = Group.objects.get(name=gname)
vars['group'] = group
if request.method == "POST":
rev_title = request.POST.get("rev_title","")
rev_text = request.POST.get("rev_text","")
image_names = request.POST.get("image_names","")
if rev_text == "" or rev_title == '':
vars["msg"] = "标题和内容不能不写啊"
return render(request,'new_topic.html',vars)
images = image_names.split("|")[:-1]
image_str = ""
for im in images:
image_str += "%s<br/>"%im
rev_text = image_str+">>>>||>>>>"+rev_text
topic = Topic(name=rev_title,content=rev_text,group=group,creator=request.user)
topic.save()
topic_amount = Topic_reply_amount(topic=topic,amount=0)
topic_amount.save()
return redirect("topic",id=topic.id)
return render(request,'new_topic.html',vars)
开发者ID:amituofo,项目名称:BOHOO,代码行数:25,代码来源:views.py
示例6: writeTopic
def writeTopic(request):
topic_name = request.POST['topic']
sender_name = request.POST['name']
topic_record = Topic()
topic_record.sender_name = sender_name
topic_record.topic_name = topic_name
topic_record.save()
return HttpResponse("ok");
开发者ID:zhangwentao,项目名称:geek,代码行数:8,代码来源:views.py
示例7: AddTopicForm
class AddTopicForm(AddPostForm):
name = forms.CharField(label=_('Subject'), max_length=255)
def save(self):
self.topic = Topic(forum=self.forum,
user=self.user,
name=self.cleaned_data['name'])
self.topic.save()
return super(AddTopicForm, self).save()
开发者ID:vencax,项目名称:django-vxk-forum,代码行数:9,代码来源:forms.py
示例8: test_postSave
def test_postSave(self):
a = Topic(name='My special topic')
a.save()
# For each topic in the Topic model we need a self
# referencing element in the closure table.
topics = Topic.objects.all()
for topic in topics:
ct = Topic.index._ctModel.objects.get(ancestor=topic)
self.assertTrue(ct.ancestor == ct.descendant and ct.path_length == 0)
开发者ID:wodo,项目名称:django-ct,代码行数:9,代码来源:tests.py
示例9: saveTopic
def saveTopic(self):
topic = Topic()
topic.class_type = self.class_type.data
topic.class_id = int(self.class_id.data)
topic.subject = self.subject.data
topic.content = self.content.data
topic.project_id = self.project.id
topic.user_id = self.user.id
current_time = int(time.time())
topic.created_at = current_time
topic.updated_at = current_time
db.session.add(topic)
db.session.commit()
project = topic.project
for atta_id in self.attachments:
atta = Attachment.query.get(atta_id)
atta.topic_id = topic.id
atta.project_id = topic.project_id
atta.root_class = topic.class_type
if topic.class_id == 0:
atta.root_id = topic.id
else:
atta.root_id = topic.class_id
db.session.commit()
project.file_count += 1
db.session.commit()
return topic
开发者ID:Red54,项目名称:Sophia,代码行数:27,代码来源:forms.py
示例10: pyforum_view
def pyforum_view(self):
topics = Topic.objects
form = Form(self.request,schema=TopicSchema())
if form.validate():
context = {'title' : form.data['title']}
Topic.add(context)
return HTTPFound(location='/list')
return {'title': 'List View PyForum',
'topics':topics,
'form' : FormRenderer(form)
}
开发者ID:tgonzales,项目名称:pyramid-forum,代码行数:11,代码来源:views.py
示例11: discussion
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)
开发者ID:ouxuedong,项目名称:dod-app,代码行数:12,代码来源:main.py
示例12: save_topic
def save_topic(data_dict):
topic_list = Topic.objects.filter(title=data_dict['title'])
if topic_list.count() == 0:
t = Topic(title=data_dict['title'])
t.image_url = data_dict['image']
t.link = data_dict['link']
t.desc = data_dict['desc']
t.date = data_dict['date']
t.user = data_dict['user']
t.clicked=data_dict['clicked']
t.comments = data_dict['comments']
t.save()
开发者ID:caoguangyao,项目名称:b-tv,代码行数:13,代码来源:views.py
示例13: addTopic
def addTopic(inTitle):
try:
existingTopic = Topic.objects.get(title=inTitle)
return False
except Topic.DoesNotExist: #this is a good thing! We can create an topic now!
newTopic = Topic()
newTopic.title = inTitle
newTopic.save()
return newTopic
开发者ID:jweiner1,项目名称:factlist,代码行数:9,代码来源:dbutils.py
示例14: publish_api
def publish_api(request):
if request.method == 'POST':
data = request.POST
new_board = Board.objects.get(board_title=data['topic_board'])
new_user = User.objects.get(email=data['topic_author'])
new_user_profile = UserProfile.objects.get(user=new_user)
new_tags = data['topic_tags'].split(',')
new_topic = Topic(
topic_status = data['topic_status'],
topic_is_top = data['topic_is_top'],
topic_title = data['topic_title'],
topic_content = data['topic_content'],
topic_board = new_board,
topic_author =new_user_profile,
topic_is_pub = data['topic_is_pub'],
topic_final_comment_time = datetime.datetime.now(),
topic_final_comment_user = new_user_profile,
)
new_topic.save()
for tag in new_tags:
if tag != '':
t = Tag.objects.get(tag_name=tag)
new_topic.topic_tag.add(t)
new_topic.save()
return HttpResponse(json.dumps({
'status':'success',
'id':new_topic.id,
},ensure_ascii=False),content_type="application/json")
else:
tf = TopicForm()
return HttpResponse(json.dumps({
'status':'not post',
},ensure_ascii=False),content_type="application/json")
开发者ID:seraph0017,项目名称:qa,代码行数:51,代码来源:views.py
示例15: save
def save(self):
if not self.topic:
## caution I maybe will modified the name to
## tag in the future
topic = Topic(tag = self.tag,
subject = self.cleaned_data['subject'],
posted_by = self.user,
)
topic.save()
else:
topic = self.topic
post = Post(topic=topic,tag = self.tag,posted_by=self.user,poster_ip=self.ip,content = self.cleaned_data['content'])
post.save()
return post
开发者ID:SeavantUUz,项目名称:Kutoto,代码行数:14,代码来源:forms.py
示例16: new_topic
def new_topic(request, forum_slug):
forum = get_object_or_404(Forum, slug=forum_slug)
if request.method == 'GET':
topic_form = TopicForm()
elif request.method == 'POST':
topic_form = TopicForm(request.POST)
if topic_form.is_valid():
data = topic_form.cleaned_data
new_topic = Topic(forum=forum, title=data['title'], user=request.user)
new_topic.save()
new_post = Post(topic=new_topic, body=data['body'], user=request.user, ip_address=request.META.get('REMOTE_ADDR'))
new_post.save()
return HttpResponseRedirect(new_topic.get_absolute_url())
return render_to_response('forum/topic_new.html', {'forum':forum, 'form':topic_form}, RequestContext(request))
开发者ID:fdb,项目名称:projecthub,代码行数:14,代码来源:views.py
示例17: save
def save(self, user, topic=None):
data = self.data
try:
node_name = data.pop('node_name')
if not self.node:
self.node = Node.get(name=node_name)
except KeyError:
logging.info('no node_name in form data, data: %s', data)
if not self.node:
logging.info('node is None in form instance, self: %s', self)
content = unicode(data.get('content'))
data.update({'user_id': user.id, 'node_id': self.node.id,
'content': strip_xss_tags(content)})
if topic:
category = 'edit'
pre_node_id = topic.node_id
pre_title = topic.title
pre_content = topic.content
cur_node_id = data.get('node_id')
cur_title = data.get('title')
cur_content = data.get('content')
changed = 0
if pre_node_id != cur_node_id:
topic.node.topic_count -= 1
self.node.topic_count += 1
diff_content = '主题节点从' + '<a class="node" href="' +\
topic.node.url + '">' + topic.node.name +\
'</a>移动到<a class="node" href="' + self.node.url + '">' +\
self.node.name + '</a>'
changed = 1
if pre_title != cur_title or pre_content != cur_content:
content1 = '<p><h2>' + pre_title + '</h2></p>' + pre_content
content2 = '<p><h2>' + cur_title + '</h2></p>' + cur_content
diff_content = ghdiff.diff(content1, content2, css=None)
changed = 1
if changed == 1:
topic.node_id = cur_node_id
topic.title = cur_title
topic.content = cur_content
History(user_id=user.id, content=diff_content,
topic_id=topic.id).save()
else:
return topic
else:
category = 'create'
topic = Topic(**data)
return topic.save(category=category)
开发者ID:ljtyzhr,项目名称:collipa,代码行数:48,代码来源:topic.py
示例18: POST
def POST(self):
if not session.user or not session.user.id:
return bad_request('请先登录!')
if session.user.username != 'ff':
return bad_request('sorry,你没有创建权限')
data = web.data()
data = json.loads(data)
topic_data = {
"title": data.get('title'),
"owner_id": session.user.id,
"created_time": datetime.now(),
}
try:
topic_id = Topic.create(**topic_data)
except sqlite3.IntegrityError:
return bad_request('你已创建过该名称!')
result = {
"id": topic_id,
"title": topic_data.get('title'),
"owner_id": session.user.id,
"owner_name": session.user.username,
"created_time": str(topic_data.get('created_time')),
}
return json.dumps(result)
开发者ID:fatfan,项目名称:mychat,代码行数:28,代码来源:handlers.py
示例19: get
def get(self):
version_name = self.request.get('version', 'edit')
topics = map(str, self.request.get_all("topic") or self.request.get_all("topic[]"))
edit_version = TopicVersion.get_by_id(version_name)
if edit_version is None:
default_version = TopicVersion.get_default_version()
if default_version is None:
# Assuming this is dev, there is an empty datastore and we need an import
edit_version = TopicVersion.create_new_version()
edit_version.edit = True
edit_version.put()
create_root(edit_version)
else:
raise Exception("Wait for setting default version to finish making an edit version.")
if self.request.get('migrate', False):
return self.topic_migration()
if self.request.get('fixdupes', False):
return self.fix_duplicates()
root = Topic.get_root(edit_version)
data = root.get_visible_data()
tree_nodes = [data]
template_values = {
'edit_version': jsonify(edit_version),
'tree_nodes': jsonify(tree_nodes)
}
self.render_jinja2_template('topics-admin.html', template_values)
return
开发者ID:di445,项目名称:server,代码行数:33,代码来源:topics.py
示例20: library_content_html
def library_content_html(mobile=False, version_number=None):
if version_number:
version = TopicVersion.get_by_number(version_number)
else:
version = TopicVersion.get_default_version()
tree = Topic.get_root(version).make_tree(types = ["Topics", "Video", "Exercise", "Url"])
videos = [item for item in walk_children(tree) if item.kind()=="Video"]
root, = prepare(tree)
topics = root.subtopics
timestamp = time.time()
template_values = {
'topics': topics,
'is_mobile': mobile,
# convert timestamp to a nice integer for the JS
'timestamp': int(round(timestamp * 1000)),
'version_date': str(version.made_default_on),
'version_id': version.number,
'approx_vid_count': Video.approx_count(),
'exercise_count': Exercise.get_count(),
}
html = shared_jinja.get().render_template("library_content_template.html", **template_values)
return html
开发者ID:di445,项目名称:server,代码行数:30,代码来源:library.py
注:本文中的models.Topic类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论