Пример #1
0
    def post(self):
        kw = {"user_id": self.current_user.id}
        svc = ProResourceApplyService(self, kw)
        # pro_svc = ProjectService(self, kw)
        # pro_info_res = pro_svc.get_project()
        if self.kwargs["name"] == "apply.resource.add":
            post_action = u"提交"
            pro_resource_apply_res = svc.do_apply()
        elif self.kwargs["name"] == "apply.resource.edit":
            post_action = u"重新提交"
            pro_resource_apply_res = svc.do_re_apply()
        elif self.kwargs["name"] == "apply.resource.revoke":
            post_action = u"撤销"
            pro_resource_apply_res = svc.do_revoke()
        elif self.kwargs["name"] == "apply.resource.pay":
            post_action = u"支付"
            pro_resource_apply_res = svc.do_pay()
        pro_info_data = self.get_pro_data(pro_id=self.args.get("pro_id"))
        data = {"pro_resource_apply_res": pro_resource_apply_res}
        svc = ProjectService(self)
        env_resource_value_res = svc.load_env_resource_values()
        env_internet_ip_types_res = svc.load_env_internet_ip_types()
        data.update(
            dict(
                env_internet_ip_types_res=env_internet_ip_types_res,
                env_resource_value_res=env_resource_value_res,
            ))

        data.update(pro_info_data)
        if pro_resource_apply_res.return_code == 0:
            self.add_message(u"申请项目[%s-%s]%s资源成功!" %
                             (pro_resource_apply_res.data.project.name,
                              pro_resource_apply_res.data.desc, post_action),
                             level="success",
                             post_action=True)
            publish_notice_checker.delay(self.current_user.id)
            if self.kwargs["name"] == "apply.resource.pay":
                tmpl = self.render_to_string(
                    "admin/guide/_step_2_pay_detail.html", **data)
            else:
                tmpl = self.render_to_string(
                    "admin/guide/_step_1_res_detail.html", **data)
        else:
            self.add_message(u"申请项目%s资源失败!(%s)%s" %
                             (post_action, pro_resource_apply_res.return_code,
                              pro_resource_apply_res.return_message),
                             level="warning")
            if self.kwargs["name"] == "apply.resource.pay":
                tmpl = self.render_to_string("admin/guide/_step_2_pay.html",
                                             **data)
            else:
                tmpl = self.render_to_string(
                    "admin/guide/_step_1_res_add.html", **data)
        messages_tmpl = self.render_to_string("admin/base/base_messages.html")
        return simplejson.dumps(
            self.success(data={
                "tmpl": tmpl,
                "messages_tmpl": messages_tmpl
            }))
Пример #2
0
    def post(self, **kwargs):
        kw = {}
        kw.update(self.args)
        kw.update(kwargs)
        svc = ProResourceApplyService(self, kw)
        resource_action_res = svc.do_pay()
        if isinstance(resource_action_res, Exception):
            raise resource_action_res
        data = self.get_pro_info_res(kwargs["pro_id"])
        tmpl = self.render_to_string("admin/guide/step2_pjax.html", **data)

        return simplejson.dumps(self.success(data=tmpl))
Пример #3
0
    def post(self):
        kw = {"user_id": self.current_user.id}
        svc = ProResourceApplyService(self, kw)
        # pro_svc = ProjectService(self, kw)
        # pro_info_res = pro_svc.get_project()
        if self.kwargs["name"] == "apply.resource.add":
            post_action = u"提交"
            pro_resource_apply_res = svc.do_apply()
        elif self.kwargs["name"] == "apply.resource.edit":
            post_action = u"重新提交"
            pro_resource_apply_res = svc.do_re_apply()
        elif self.kwargs["name"] == "apply.resource.revoke":
            post_action = u"撤销"
            pro_resource_apply_res = svc.do_revoke()
        elif self.kwargs["name"] == "apply.resource.pay":
            post_action = u"支付"
            pro_resource_apply_res = svc.do_pay()
        pro_info_data = self.get_pro_data(pro_id=self.args.get("pro_id"))
        data = {
            "pro_resource_apply_res": pro_resource_apply_res
        }
        svc = ProjectService(self)
        env_resource_value_res = svc.load_env_resource_values()
        env_internet_ip_types_res = svc.load_env_internet_ip_types()
        data.update(dict(
            env_internet_ip_types_res = env_internet_ip_types_res,
            env_resource_value_res = env_resource_value_res,
        ))

        data.update(pro_info_data)
        if pro_resource_apply_res.return_code == 0:
            self.add_message(u"申请项目[%s-%s]%s资源成功!" % (pro_resource_apply_res.data.project.name, pro_resource_apply_res.data.desc, post_action), level="success", post_action=True)
            publish_notice_checker.delay(self.current_user.id)
            if self.kwargs["name"] == "apply.resource.pay":
                tmpl = self.render_to_string("admin/guide/_step_2_pay_detail.html", **data)
            else:
                tmpl = self.render_to_string("admin/guide/_step_1_res_detail.html", **data)
        else:
            self.add_message(u"申请项目%s资源失败!(%s)%s" % (post_action, pro_resource_apply_res.return_code, pro_resource_apply_res.return_message), level="warning")
            if self.kwargs["name"] == "apply.resource.pay":
                tmpl = self.render_to_string("admin/guide/_step_2_pay.html", **data)
            else:
                tmpl = self.render_to_string("admin/guide/_step_1_res_add.html", **data)
        messages_tmpl = self.render_to_string("admin/base/base_messages.html")
        return simplejson.dumps(self.success(data={"tmpl": tmpl, "messages_tmpl": messages_tmpl}))