def topic_add(): form = turn_to_dict() u = current_user() form['writer_id'] = u.id form['content'] = form['content'] Topic.new(form) return redirect(url_for('public.index'))
def add_read_num(topic_id): topic = Topic.one(id=topic_id) log('TOPIC\n{}'.format(topic)) log('CONTENT\n{}'.format(topic.content)) read_num = topic.read_num + 1 log('Reading num increase!') Topic.update(cls_id=topic.id, read_num=read_num) return Topic.one(id=topic_id)
def topic_update(): u = current_user() form = turn_to_dict() topic_id = form.pop('id') form['writer_id'] = u.id form['update_time'] = time.time() log(form) Topic.update(topic_id, **form) return redirect(url_for('public.index'))
def topic_edit(): topic_id = request.args['id'] topic = Topic.one(id=topic_id) u = current_user() if not u.is_guest(): token = Csrf.one(user_id=u.id).csrf_token else: token = '' return render_template('edit.html', topic=topic, csrf=token)
def profile_index(username): can_edit = True user = User.one(username=username) log(f'USER<{username}>:{user}') user_id = user.id replys = Reply.all(writer_id=user_id) replys.reverse() topics = Topic.all_order(writer_id=user_id) return render_template('profile.html', user=user, replys=replys, topics=topics, can_edit=can_edit)
def add_topic(): add_form = AddTopicForm() if add_form.validate_on_submit(): session = db_session.create_session() topic = Topic( topic_title=add_form.topic_title.data, user_id=current_user.id ) session.add(topic) session.commit() return redirect(f'/{0}/{0}') return render_template('add_topic.html', title='Добавление темы', form=add_form, link=url_for('static', filename='css/style.css'))
def post(self, curr_user): data = request.get_json() member = curr_user.member topic_title = data.get("title") cluster_title = data.get("cluster_title") message = data.get("message") if not topic_title or not cluster_title: json_abort(400, "אחד או יותר מהנושאים חסרים") new_topic = Topic(title=topic_title, member_email=member.email, cluster_title=cluster_title) db.session.add(new_topic) db.session.flush() # To obtain id. if not new_topic: json_abort(500, "תהליך יצירת נושא חדש נכשל") new_message = Message(content=message, member_email=member.email, topic_id=new_topic.id) db.session.add(new_message) db.session.commit() response = make_response(jsonify(message='הפוסט הוסף בהצלחה'), 200) return response
def create(cls,userkey,topic,topickey): t = Topic.get(topickey) b = cls(user=userkey,comment=topic,topic=t) b.put()
def get(self, topic): t = Topic.get(topic) user = User.get(self.session["current_user"]) comments = [comment for comment in t.comment_set.run()] self.render_response("comments.html", topic=t, comments=comments)
def get(self): user = User.get(self.session['current_user']) topics = Topic.all() self.render_response('main.html',user=user,topics=topics)
def post(self): user = User.get(self.session['current_user']) topic = self.request.POST['topic'] desc = self.request.POST['description'] Topic.create(user,topic,desc) self.redirect('/')
def index(): u = current_user() topics = Topic.all() log('TOPICS OBJECT\n{}'.format(topics)) return render_template('index.html', topics=topics, user=u)
def topic_delete(): topic_id = request.args['id'] Topic.delete(topic_id) return redirect(url_for('public.index'))