Exemplo n.º 1
0
    def post(self, version):
        form = ArticleFlagForm().validate_for_api()  # 验证表单
        id = form.id.data
        flag = form.flag.data

        wechat_article = WechatArticle.query.get(id)
        if wechat_article:
            if wechat_article.flag != flag:
                wechat_article.flag = flag
                db.session.commit()
                return response_code.LayuiSuccess(message='文章:“{}”修改成功!'.format(wechat_article.title))

            return response_code.ParameterException(message='已经被被人修改,刷新看看!!')
        return response_code.ParameterException(message='修改失败!')
Exemplo n.º 2
0
    def post(self, version):
        form = SettingEmailForm().validate_for_api()  # 验证表单

        smtp_server = form.smtp_server.data
        smtp_port = form.smtp_port.data
        smtp_username = form.smtp_username.data
        smtp_password = form.smtp_password.data
        smtp_sender = form.smtp_sender.data

        setting_email_obj = System_Settings.query.order_by(
            System_Settings.create_time.desc()).first()

        if setting_email_obj:
            setting_email_obj.smtp_server = smtp_server
            setting_email_obj.smtp_port = smtp_port
            setting_email_obj.smtp_username = smtp_username
            setting_email_obj.smtp_password = smtp_password
            setting_email_obj.smtp_sender = smtp_sender

            db.session.commit()
            # 重新加载mail实例化的配置
            return response_code.LayuiSuccess(message='修改成功!')
        else:
            setting = System_Settings(smtp_server=smtp_server,
                                      smtp_port=smtp_port,
                                      smtp_username=smtp_username,
                                      smtp_password=smtp_password,
                                      smtp_sender=smtp_sender)
            db.session.add(setting)
            db.session.commit()
            return response_code.ParameterException(message='修改失败!')