Exemplo n.º 1
0
 def POST(self, post_id):
     if session.user_id is None:
         raise web.SeeOther('/login')
     post = post_model().get_one({'id':post_id})
     if post is not None:
         if not self.form.validates():
             raise web.SeeOther('/post/' + post_id)
         else:
             user_model().update_session(session.user_id)
             length, cost = money_model().cal_comment(self.form.d.content)
             if session.money < cost:
                 self.crumb.append('财富不够')
                 return render.no_money('财富不够', '你的财富值不够,不能创建改主题 :(', self.crumb.output())
             content = html2db(self.form.d.content)
             content, receiver_list = notify_model().convert_content(content)
             create_time = time.time()
             comment_id = comment_model().insert({'user_id' : session.user_id, 'post_id' : post_id, 'content' : content, 'time' : create_time})
             money_type_id = money_type_model().get_one({'name':'comment'})['id']
             money_model().insert({'user_id':session.user_id, 'money_type_id':money_type_id, 'amount':-cost, 'length':length, 'balance':user_model().update_money(session.user_id, -cost), 'foreign_id':comment_id})
             if session.user_id != post.user_id:
                 money_model().insert({'user_id':post.user_id, 'money_type_id':money_type_id, 'amount':cost, 'length':length, 'foreign_id':comment_id, 'balance':user_model().update_money(post.user_id, cost)})
                 # notify
                 notify_model().insert({'user_id':session.user_id, 'receiver':post.user_id, 'type_id':notify_type_model().get_one({'name':'comment'}).id, 'foreign_id':comment_id})
             # notify
             receiver_list = list_diff(receiver_list, [session.name, user_model().get_one({'id':post.user_id}).name])
             notify_model().insert_notify(session.user_id, receiver_list, 'comment_at', comment_id)
             user_model().update_session(session.user_id)
             post_model().update({'id':post_id}, {'last_update':create_time})
             post_model().count_comment(post_id)
             raise web.SeeOther('/post/' + post_id)
     else:
          raise web.SeeOther('/post/' + post_id)
Exemplo n.º 2
0
 def POST(self, post_id):
     if session.user_id is None:
         raise web.SeeOther('/login')
     post = post_model().get_one({'id': post_id})
     if post is not None:
         if not self.form.validates():
             raise web.SeeOther('/post/' + post_id)
         else:
             user_model().update_session(session.user_id)
             length, cost = money_model().cal_comment(self.form.d.content)
             if session.money < cost:
                 self.crumb.append('财富不够')
                 return render.no_money('财富不够', '你的财富值不够,不能创建改主题 :(',
                                        self.crumb.output())
             content = html2db(self.form.d.content)
             create_time = time.time()
             comment_id = comment_model().insert({
                 'user_id': session.user_id,
                 'post_id': post_id,
                 'content': content,
                 'time': create_time
             })
             money_type_id = money_type_model().get_one({'name':
                                                         'comment'})['id']
             money_model().insert({
                 'user_id':
                 session.user_id,
                 'money_type_id':
                 money_type_id,
                 'amount':
                 -cost,
                 'length':
                 length,
                 'balance':
                 user_model().update_money(session.user_id, -cost),
                 'foreign_id':
                 comment_id
             })
             if session.user_id != post.user_id:
                 money_model().insert({
                     'user_id':
                     post.user_id,
                     'money_type_id':
                     money_type_id,
                     'amount':
                     cost,
                     'length':
                     length,
                     'foreign_id':
                     comment_id,
                     'balance':
                     user_model().update_money(post.user_id, cost)
                 })
             user_model().update_session(session.user_id)
             post_model().update({'id': post_id},
                                 {'last_update': create_time})
             post_model().count_comment(post_id)
             raise web.SeeOther('/post/' + post_id)
     else:
         raise web.SeeOther('/post/' + post_id)
Exemplo n.º 3
0
 def POST(self, node_name):
     if session.user_id is None:
         raise web.SeeOther('/login?next=/post/create' + node_name)
     conditions = {'name' : node_name}
     node = node_model().get_one(conditions)
     if node is None:
         return render.not_found('节点未找到', '节点未找到')
     if not self.form.validates():
         return render.create_post(self.form, '创建失败, 请重创:D', self.crumb.output())
     user_model().update_session(session.user_id)
     length, cost = money_model().cal_post(self.form.d.content)
     if session.money < cost:
         self.crumb.append('财富不够')
         return render.no_money('财富不够', '你的财富值不够,不能创建改主题 :(', self.crumb.output())
     title = strip_tags(self.form.d.title)
     content = html2db(self.form.d.content)
     content, receiver_list = notify_model().convert_content(content)
     create_time = time.time()
     post_id = post_model().insert({'title' : title, 'content' : content, 'node_id' : node.id, 'time' : create_time, 'last_update':create_time, 'user_id' : session.user_id})
     # money
     money_type_id = money_type_model().get_one({'name':'post'})['id']
     money_model().insert({'user_id':session.user_id, 'money_type_id':money_type_id, 'amount':-cost, 'length':length, 'balance':user_model().update_money(session.user_id, -cost), 'foreign_id':post_id})
     # notify
     receiver_list = list_diff(receiver_list, [session.name])
     notify_model().insert_notify(session.user_id, receiver_list, 'post_at', post_id)
     user_model().update_session(session.user_id)
     raise web.seeother('/post/' + str(post_id))
Exemplo n.º 4
0
 def POST(self, post_id):
     if session.user_id is None:
         raise web.SeeOther('/login?next=/edit/post/' + post_id)
     conditions = {'id': int(post_id)}
     post = post_model().get_one(conditions)
     if post is None:
         return render.not_found('节点未找到', '节点未找到')
     if not self.form.validates():
         return render.create_post(self.form, '创建失败, 请重创:D',
                                   self.crumb.output())
     user_model().update_session(session.user_id)
     length, cost = money_model().cal_post(self.form.d.content)
     if session.money < cost:
         self.crumb.append('财富不够')
         return render.no_money('财富不够', '你的财富值不够,不能创建改主题 :(',
                                self.crumb.output())
     title = strip_tags(self.form.d.title)
     content = html2db(self.form.d.content)
     content, receiver_list = notify_model().convert_content(content)
     create_time = time.time()
     post_model().update({'id': int(post_id)}, {
         'title': title,
         'content': content,
         'node_id': post.node_id,
         'time': create_time,
         'last_update': create_time,
         'user_id': session.user_id
     })
     # money
     money_type_id = money_type_model().get_one({'name': 'post'})['id']
     money_model().insert({
         'user_id':
         session.user_id,
         'money_type_id':
         money_type_id,
         'amount':
         -cost,
         'length':
         length,
         'balance':
         user_model().update_money(session.user_id, -cost),
         'foreign_id':
         post_id
     })
     # notify
     receiver_list = list_diff(receiver_list, [session.name])
     notify_model().insert_notify(session.user_id, receiver_list, 'post_at',
                                  post_id)
     user_model().update_session(session.user_id)
     raise web.seeother('/post/' + str(post_id))
Exemplo n.º 5
0
 def POST(self, node_name):
     if session.user_id is None:
         raise web.SeeOther('/login?next=/post/create' + node_name)
     conditions = {'name' : node_name}
     node = node_model().get_one(conditions)
     if node is None:
         return render.not_found('节点未找到', '节点未找到')
     if not self.form.validates():
         return render.create_post(self.form, '创建失败, 请重创:D', self.crumb.output())
     user_model().update_session(session.user_id)
     length, cost = money_model().cal_post(self.form.d.content)
     if session.money < cost:
         self.crumb.append('财富不够')
         return render.no_money('财富不够', '你的财富值不够,不能创建改主题 :(', self.crumb.output())
     title = html2db(self.form.d.title)
     content = html2db(self.form.d.content)
     create_time = time.time()
     post_id = post_model().insert({'title' : title, 'content' : content, 'node_id' : node.id, 'time' : create_time, 'last_update':create_time, 'user_id' : session.user_id})
     money_type_id = money_type_model().get_one({'name':'post'})['id']
     money_model().insert({'user_id':session.user_id, 'money_type_id':money_type_id, 'amount':-cost, 'length':length, 'balance':user_model().update_money(session.user_id, -cost), 'foreign_id':post_id})
     
     user_model().update_session(session.user_id)
     raise web.seeother('/post/' + str(post_id))