Esempio n. 1
0
 def post(form):
     topic = Topic()
     topic.title = form.title.data
     topic.content = html_clean(form.content.data)
     topic.is_markdown = True if form.choice.data == 1 else False
     topic.uid = make_uid()
     topic.author = current_user
     tags = sp(',|;|,|;| ', form.tags.data)
     tags = [x for x in list(set(tags)) if x != ''][:4]
     post_tags = []
     for tag in tags:
         if tag != '':
             exsit_tag = Tags.query.filter_by(tagname=tag).first()
             if exsit_tag is not None:
                 post_tags.append(exsit_tag)
                 if exsit_tag not in current_user.following_tags:
                     current_user.following_tags.append(exsit_tag)
             else:
                 t = Tags()
                 t.tagname = tag
                 post_tags.append(t)
                 current_user.following_tags.append(t)
     topic.tags = post_tags
     topic.board_id = form.category.data
     db.session.add(topic)
     db.session.commit()
     current_user.following_topics.append(topic)
     topic.board.count.topics += 1
     topic.board.count.all_topics += 1
     db.session.commit()
     RedisData.set_topics()
     return topic
Esempio n. 2
0
 def post(self, form, uid):
     reply = Reply()
     content = html_clean(form.content.data)
     content, usernames = self.at_user(content)
     reply.content = content
     reply.author = current_user
     reply.topic_id = uid
     db.session.add(reply)
     db.session.commit()
     topic = reply.topic
     self.reply_count(topic, reply)
     self.reply_notice(topic, reply, usernames)
     return reply
Esempio n. 3
0
 def put(form, topicId):
     topic = Topic.query.filter_by(uid=topicId).first_or_404()
     topic.title = form.title.data
     topic.content = html_clean(form.content.data)
     topic.is_markdown = True if form.choice.data == 1 else False
     tags = sp(',|;|,|;| ', form.tags.data)
     tags = [x for x in list(set(tags)) if x != ''][:4]
     post_tags = []
     for tag in tags:
         if tag != '':
             exsit_tag = Tags.query.filter_by(tagname=tag).first()
             if exsit_tag is not None:
                 post_tags.append(exsit_tag)
                 if exsit_tag not in current_user.following_tags:
                     current_user.following_tags.append(exsit_tag)
             else:
                 t = Tags()
                 t.tagname = tag
                 post_tags.append(t)
                 current_user.following_tags.append(t)
     topic.tags = post_tags
     topic.board_id = form.category.data
     db.session.commit()
     return topic