当前位置: 首页>>代码示例>>Python>>正文


Python MessageForm.validate方法代码示例

本文整理汇总了Python中forms.MessageForm.validate方法的典型用法代码示例。如果您正苦于以下问题:Python MessageForm.validate方法的具体用法?Python MessageForm.validate怎么用?Python MessageForm.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.MessageForm的用法示例。


在下文中一共展示了MessageForm.validate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import validate [as 别名]
 def post(self):
     user_id = force_int(self.get_argument('user_id', 0), 0)
     current_user = self.current_user
     user = User.get(id=user_id)
     if user:
         form = MessageForm(self.request.arguments)
         if form.validate():
             message_box1 = current_user.get_message_box(user=user)
             message_box2 = user.get_message_box(user=current_user)
             if not message_box1:
                 message_box1 = MessageBox(sender_id=current_user.id,
                         receiver_id=user.id, status=1).save()
             if not message_box2:
                 message_box2 = MessageBox(sender_id=user.id,
                         receiver_id=current_user.id).save()
             message = form.save(user_id=current_user.id,
                     message_box1_id=message_box1.id,
                     message_box2_id=message_box2.id)
             result = {"status": "success", "message": "私信发送成功",
                     "content": message.content, "created": message.created,
                     "avatar": current_user.get_avatar(size=48), "url":
                     current_user.url, "id": message.id}
         else:
             result = {"status": "error", "message": "请填写至少 4 字的内容"}
         if self.is_ajax:
             return self.write(result)
         self.flash_message(result)
         return self.redirect_next_url()
     result = {"status": "error", "message": "没有目标用户,不能发送私信哦"}
     if self.is_ajax:
         return self.write(result)
     self.flash_message(result)
     return self.redirect_next_url()
开发者ID:laofo,项目名称:collipa,代码行数:35,代码来源:user.py

示例2: post

# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import validate [as 别名]
 def post(self):
     user_id = force_int(self.get_argument('user_id', 0), 0)
     sender = self.current_user
     receiver = User.get(id=user_id)
     if receiver:
         form = MessageForm(self.request.arguments)
         if form.validate():
             message = form.save(sender_id=sender.id,
                                 receiver_id=receiver.id)
             result = {
                 "status": "success",
                 "message": "私信发送成功",
                 "content": message.content,
                 "created": message.created,
                 "avatar": sender.get_avatar(size=48),
                 "url": sender.url,
                 "id": message.id,
             }
         else:
             result = {"status": "error", "message": "请填写至少 4 字的内容"}
         self.send_result(result)
         self.finish()
         return WebSocketHandler.send_message(message.receiver_id, message)
     result = {"status": "error", "message": "没有目标用户,不能发送私信哦"}
     self.send_result(result)
开发者ID:hallocrowc,项目名称:collipa,代码行数:27,代码来源:user.py

示例3: home

# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import validate [as 别名]
def home():
    """Renders the home page."""
    form = MessageForm(request.form)
    if request.method == 'POST' and form.validate():
        #Save to db
        table_service = TableService(account_name=config.ACC_NAME, 
                                     account_key=config.ACC_KEY)
        message = {'PartitionKey': 'message', 
                   'RowKey': form.name.data + datetime.datetime.now().isoformat(), 
                   'name' : form.name.data,
                   'email': form.email.data,
                   'date' : str(datetime.datetime.now())}
        if form.message_body.data:
            message["message"] = form.message_body.data
        table_service.insert_entity('landingmessages', message)
        return render_template(
            'index.html',
            hiden_block='#wright-us',
            form=form,
        )
    return render_template(
        'index.html',
        hiden_block='#got-ur-message',
        form=form,
    )
开发者ID:catInet,项目名称:landingPage,代码行数:27,代码来源:views.py

示例4: post

# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import validate [as 别名]
 def post(self):
     abort_if_not_an_admin()
     data = ImmutableMultiDict(request.json)
     message_form = MessageForm(data, csrf_enabled=False)
     if message_form.validate():
         message_form.save()
         return {"status": "success"}
     return message_form.errors
开发者ID:savad,项目名称:monitor,代码行数:10,代码来源:views.py

示例5: mess_send

# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import validate [as 别名]
def mess_send(*args,**kwargs):
    form = MessageForm(request.form)
    if request.method == 'POST' and 'proj_id' in kwargs and form.validate():
        mess = Messages(content = form.message.data,
                kind = 'project',
                author = g.user,
                project = Projects.query.get(kwargs['proj_id']),
                reciever = Projects.query.get(kwargs['proj_id']).user
                )
        db.session.add(mess)
        db.session.commit()
        flash('Message send')
        return redirect('/projects/%s#/2' % kwargs['proj_id'])
    if request.method == 'POST' and 'author' in kwargs and form.validate():
        mess = Messages(content = form.message.data,
                kind = 'private',
                author = g.user,
                reciever = User.query.filter_by(name = kwargs['author']).first()
                )
        db.session.add(mess)
        db.session.commit()
        flash('Message send')
        return redirect('/user/%s#/2' % g.user.name)
    return redirect('.')
开发者ID:B1aZer,项目名称:ImInIt,代码行数:26,代码来源:__init__.py

示例6: post

# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import validate [as 别名]
    def post(self, user_id):
        auth_user = self.auth.get_user_by_session()
        user_auth_key = ndb.Key('UserModel', auth_user['user_id'])
        user_key = ndb.Key('UserModel', int(user_id))
        data = json.decode(self.request.body)
        form = MessageForm(**data)
        if not form.validate():
            return ResponseBadRequest(form.errors)

        message = MessageModel()
        message.sender = user_auth_key
        message.receiver = user_key
        message.text = form.text.data
        message.put()

        return Response(message)
开发者ID:serg-cayuga,项目名称:webapp2test,代码行数:18,代码来源:handlers.py


注:本文中的forms.MessageForm.validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。