示例#1
0
文件: purchase.py 项目: xutaoding/bmp
    def to(self, p):
        approvals = p.approvals
        to = []
        if not p.is_finished:
            if p.cur_approval_type == PURCHASE.FLOW_ONE:
                ldap=Ldap()
                suser = User.get(ldap.get_2nd_manager(p.apply_uid))
                to.append(suser["mail"])
            else:
                to.extend([u.mail for u in Group.get_users(p.cur_approval_type)])
        else:
            user = User.get(p.apply_uid)
            to.extend([u.mail for u in Group.get_users(DEFAULT_GROUP.PURCHASE.FIN)])
            to.append(user["mail"])

        sub = u"采购编号:%s 采购申请:%s" % (p.id, ",".join([g.category.name for g in p.goods]))

        self.send(
            to,
            sub,
            "/templates/purchase/approval.html",
            "mail.purchase.tpl.html",
            purchase=p,
            goods=p.goods,
            approvals=approvals,
            group_names=Group.get_descs())
示例#2
0
文件: purchase.py 项目: cash2one/bmp
    def to(self, p):
        approvals = p.approvals
        to = []
        if not p.is_finished:
            if p.cur_approval_type == PURCHASE.FLOW_ONE:
                ldap = Ldap()
                suser = User.get(ldap.get_2nd_manager(p.apply_uid))
                to.append(suser["mail"])
            else:
                to.extend(
                    [u.mail for u in Group.get_users(p.cur_approval_type)])
        else:
            user = User.get(p.apply_uid)
            to.extend(
                [u.mail for u in Group.get_users(DEFAULT_GROUP.PURCHASE.FIN)])
            to.append(user["mail"])

        sub = u"采购编号:%s 采购申请:%s" % (p.id, ",".join(
            [g.category.name for g in p.goods]))

        self.send(to,
                  sub,
                  "/templates/purchase/approval.html",
                  "mail.purchase.tpl.html",
                  purchase=p,
                  goods=p.goods,
                  approvals=approvals,
                  group_names=Group.get_descs())
示例#3
0
    def put(self, name, new="", desc=""):
        if new:
            if not Group.edit(name, new, desc):
                return self.fail()
            return self.succ()

        submit = self.request()
        if not Group.join(name, submit.split(",")):
            return self.fail()
        return self.succ()
示例#4
0
文件: release.py 项目: xutaoding/bmp
    def to(self, r,submit):
        approvals = r.approvals
        to, cc = [], []
        to_group = [DEFAULT_GROUP.QA]
        to_group.extend([DEFAULT_GROUP.OP])
        for g in to_group:
            to.extend([u.mail for u in Group.get_users(g)])

        user = User.get(r.apply_uid)
        sub = u"发布申请:%s" % r.project
        if submit and submit["status"] == RELEASE.FAIL:
            sub = u"发布退回:%s %s" % (r.project, submit["type"])
            to = [user["mail"]]
        elif approvals:
            sub = u"发布确认:%s %s" % (r.project, submit["type"])
            to.append(user["mail"])

        try:
            copy_to = User.get(r.copy_to_uid)
            if copy_to["mail"] not in to:
                cc.append(copy_to["mail"])
        except:
            pass

        self.send(
            to,
            sub,
            "/templates/release/release.html",
            "mail.tpl.html",
            cc=cc,
            release=r,
            approvals=approvals)
示例#5
0
文件: release.py 项目: cash2one/bmp
    def to(self, r, submit):
        approvals = r.approvals
        to, cc = [], []
        to_group = [DEFAULT_GROUP.QA]
        to_group.extend([DEFAULT_GROUP.OP])
        for g in to_group:
            to.extend([u.mail for u in Group.get_users(g)])

        user = User.get(r.apply_uid)
        sub = u"发布申请:%s" % r.project
        if submit and submit["status"] == RELEASE.FAIL:
            sub = u"发布退回:%s %s" % (r.project, submit["type"])
            to = [user["mail"]]
        elif approvals:
            sub = u"发布确认:%s %s" % (r.project, submit["type"])
            to.append(user["mail"])

        try:
            copy_to = User.get(r.copy_to_uid)
            if copy_to["mail"] not in to:
                cc.append(copy_to["mail"])
        except:
            pass

        self.send(to,
                  sub,
                  "/templates/release/release.html",
                  "mail.tpl.html",
                  cc=cc,
                  release=r,
                  approvals=approvals)
示例#6
0
文件: alert.py 项目: xutaoding/bmp
    def add(self, name, obj, expire_time, lead_times):
        try:
            _id = "_".join([obj.__class__.__name__, str(obj.id)])

            if not isinstance(lead_times, list):
                lead_times = [lead_times]

            content = "神盾局OPS系统:前方英雄【%s 编号:%s】即将在【%s】过期,请及时充能!!" % (
                name, str(obj.id), expire_time.strftime("%Y-%m-%d")
            )

            for lead_time in lead_times:
                date = expire_time - lead_time

                BaseSms.send(self,
                             [u.mobile for u in Group.get_users(DEFAULT_GROUP.SMS.ALERT)],
                             content, date=date, _id="_".join([_id, str(lead_time.days)]))

                BaseMail.send(self,
                              [app.config["MAIL_ALERT"]],
                              content,
                              "",
                              "mail.alert.tpl.html",
                              date=date,
                              _id="_".join([_id, str(lead_time.days)]))

        except Exception, e:
            traceback.print_exc()
            log.exception(e)
            raise ExceptionEx("添加邮件或短信提示失败!")
示例#7
0
文件: access.py 项目: xutaoding/bmp
    def to(self, access):
        try:
            ldap = Ldap()

            copy_to_uid = [User.get(uid)["mail"] for uid in access.copy_to_uid.split(",")] \
                if access.copy_to_uid \
                else [User.get(ldap.get_1st_manager(access.apply_uid))["mail"]]

            copy_to_uid.extend([u.mail for u in Group.get_users(DEFAULT_GROUP.OP)])


            sub = u" %s权限申请 申请人:%s 申请时间:%s" % (
                access.type,
                access.apply_uid,
                access.apply_time.strftime("%Y-%m-%d %H:%M")
            )

            self.send(
                copy_to_uid,
                sub,
                access=access,
                url="/templates/jurisdiction/curr_apply.html?id=%d"%access.id,
                tpl="mail.access.tpl.html"
            )

            return True
        except Exception, e:
            traceback.print_exc()
            return False
示例#8
0
    def to(self, l):
        try:
            uids = [l.uid, l.approval_uid] + l.copy_to_uid.split(",")
            if l.status == LEAVE.PASS:
                uids += [u.uid for u in Group.get_users(DEFAULT_GROUP.LEAVE.MAIL)]
                to = [User.get(uid)["mail"] for uid in uids]
                to.append("*****@*****.**")
            else:
                to = [User.get(uid)["mail"] for uid in uids]

            status = l.status
            if status != LEAVE.PASS:
                status = u"已退回"

            sub = u"%s的请假申请%s 审批时间:%s 编号:%d" % ( l.uid,status,l.approval_time.strftime("%Y-%m-%d"),l.id)

            self.send(
                to,
                sub,
                "/templates/leave/approval.html",
                "mail.leave.tpl.html",
                leave=l,
                leave_type=Ref.map(LEAVE.TYPE)[int(l.type_id)])

        except Exception,e:
            log.exception(e)
            raise ExceptionEx("邮件发送失败,请重试!")
示例#9
0
    def to(self, access):
        try:
            ldap = Ldap()

            copy_to_uid = [User.get(uid)["mail"] for uid in access.copy_to_uid.split(",")] \
                if access.copy_to_uid \
                else [User.get(ldap.get_1st_manager(access.apply_uid))["mail"]]

            copy_to_uid.extend(
                [u.mail for u in Group.get_users(DEFAULT_GROUP.OP)])

            sub = u" %s权限申请 申请人:%s 申请时间:%s" % (
                access.type, access.apply_uid,
                access.apply_time.strftime("%Y-%m-%d %H:%M"))

            self.send(copy_to_uid,
                      sub,
                      access=access,
                      url="/templates/jurisdiction/curr_apply.html?id=%d" %
                      access.id,
                      tpl="mail.access.tpl.html")

            return True
        except Exception, e:
            traceback.print_exc()
            return False
示例#10
0
文件: alert.py 项目: cash2one/bmp
    def add(self, name, obj, expire_time, lead_times):
        try:
            _id = "_".join([obj.__class__.__name__, str(obj.id)])

            if not isinstance(lead_times, list):
                lead_times = [lead_times]

            content = "神盾局OPS系统:前方英雄【%s 编号:%s】即将在【%s】过期,请及时充能!!" % (
                name, str(obj.id), expire_time.strftime("%Y-%m-%d"))

            for lead_time in lead_times:
                date = expire_time - lead_time

                BaseSms.send(self, [
                    u.mobile for u in Group.get_users(DEFAULT_GROUP.SMS.ALERT)
                ],
                             content,
                             date=date,
                             _id="_".join([_id, str(lead_time.days)]))

                BaseMail.send(self, [app.config["MAIL_ALERT"]],
                              content,
                              "",
                              "mail.alert.tpl.html",
                              date=date,
                              _id="_".join([_id, str(lead_time.days)]))

        except Exception, e:
            traceback.print_exc()
            log.exception(e)
            raise ExceptionEx("添加邮件或短信提示失败!")
示例#11
0
文件: purchase.py 项目: xutaoding/bmp
 def get(self, pid=0):
     if pid:
         return self.succ(Purchase.get(pid))
     g_dict = {}
     for g in set(PURCHASE.FLOW).difference([PURCHASE.FLOW_ONE]):
         g_dict[g] = [user.uid for user in Group.get_users(g)]
     unfinished = Purchase.unfinished(g_dict)
     return self.succ(unfinished)
示例#12
0
    def unfinished(user_groups):
        from bmp.models.user import Group, User

        purchases = []
        uid = session[USER_SESSION]["uid"]
        group = set(User.get(uid)["group"]).intersection(PURCHASE.FLOW)
        group_map = {}
        for g in Group.select(to_dict=False):
            group_map[g.name.upper()] = g.desc

        for purchase in Purchase.query \
                .filter(Purchase.is_draft == False) \
                .filter(Purchase.is_finished == False).order_by(Purchase.apply_time.desc()).all():

            approvals = purchase.approvals
            apply_uid = purchase.apply_uid
            cur_approval_type = purchase.cur_approval_type
            purchase.cur_approval_type_desc = ""
            purchase.approval_enable = False
            is_append = False

            if group_map.__contains__(cur_approval_type.upper()):
                purchase.cur_approval_type_desc = group_map[
                    cur_approval_type.upper()]

            if uid in [purchase.apply_uid] + [a.uid for a in approvals] \
                    or group.intersection([a.type for a in approvals]):
                purchases.append(purchase)
                is_append = True

            if cur_approval_type == PURCHASE.FLOW_ONE:
                if Purchase.__is_superior(uid, apply_uid):
                    purchase.approval_enable = True
                    if not is_append:
                        purchases.append(purchase)
            elif uid in user_groups[cur_approval_type]:
                purchase.approval_enable = True
                if not is_append:
                    purchases.append(purchase)
            else:
                continue
        return [
            Purchase._to_dict(p, ["approval_enable", "cur_approval_type_desc"])
            for p in purchases
        ]
示例#13
0
文件: purchase.py 项目: xutaoding/bmp
    def unfinished(user_groups):
        from bmp.models.user import Group, User

        purchases = []
        uid = session[USER_SESSION]["uid"]
        group = set(User.get(uid)["group"]).intersection(PURCHASE.FLOW)
        group_map = {}
        for g in Group.select(to_dict=False):
            group_map[g.name.upper()] = g.desc

        for purchase in Purchase.query \
                .filter(Purchase.is_draft == False) \
                .filter(Purchase.is_finished == False).order_by(Purchase.apply_time.desc()).all():

            approvals = purchase.approvals
            apply_uid = purchase.apply_uid
            cur_approval_type = purchase.cur_approval_type
            purchase.cur_approval_type_desc = ""
            purchase.approval_enable = False
            is_append = False

            if group_map.__contains__(cur_approval_type.upper()):
                purchase.cur_approval_type_desc = group_map[cur_approval_type.upper()]

            if uid in [purchase.apply_uid] + [a.uid for a in approvals] \
                    or group.intersection([a.type for a in approvals]):
                purchases.append(purchase)
                is_append = True

            if cur_approval_type == PURCHASE.FLOW_ONE:
                if Purchase.__is_superior(uid, apply_uid):
                    purchase.approval_enable = True
                    if not is_append:
                        purchases.append(purchase)
            elif uid in user_groups[cur_approval_type]:
                purchase.approval_enable = True
                if not is_append:
                    purchases.append(purchase)
            else:
                continue
        return [Purchase._to_dict(p, ["approval_enable", "cur_approval_type_desc"]) for p in purchases]
示例#14
0
文件: purchase.py 项目: xutaoding/bmp
 def get(id):
     from bmp.models.user import Group
     purchase = Purchase.query.filter(Purchase.id == id).one()
     purchase.cur_approval_type_desc = Group.get(purchase.cur_approval_type).desc
     return Purchase._to_dict(purchase, ["cur_approval_type_desc"])
示例#15
0
# coding=utf-8
from flask import session

from bmp.apis.base import BaseApi
from bmp.const import DEFAULT_GROUP, USER_SESSION
from bmp.models.leave import Leave
from bmp.models.user import Group


class Leave_searchApi(BaseApi):
    route = ["/leave/search/<string:begin_time>/<string:end_time>",
             "/leave/search/<string:begin_time>/<string:end_time>/<string:name>"]

    def get(self, begin_time, end_time, name="%"):
        if session[USER_SESSION]["uid"] not in [u.uid for u in Group.get_users(DEFAULT_GROUP.LEAVE.SEARCH)]:
            name = session[USER_SESSION]["uid"]

        return self.succ(Leave.search(begin_time, end_time, name))


if __name__ == "__main__":
    print Group.get_users(DEFAULT_GROUP.LEAVE.SEARCH)
示例#16
0
 def get(id):
     from bmp.models.user import Group
     purchase = Purchase.query.filter(Purchase.id == id).one()
     purchase.cur_approval_type_desc = Group.get(
         purchase.cur_approval_type).desc
     return Purchase._to_dict(purchase, ["cur_approval_type_desc"])
示例#17
0
 def get(self, name="%"):
     return self.succ(Group.select(name))
示例#18
0
 def post(self, name, desc):
     if not Group.add(name, desc):
         return self.fail()
     return self.succ()
示例#19
0
    def get(self, begin_time, end_time, name="%"):
        if session[USER_SESSION]["uid"] not in [u.uid for u in Group.get_users(DEFAULT_GROUP.LEAVE.SEARCH)]:
            name = session[USER_SESSION]["uid"]

        return self.succ(Leave.search(begin_time, end_time, name))
示例#20
0
文件: session.py 项目: xutaoding/bmp
def members(*groups):
    r = []
    for group in groups:
        users = Group.get_users(group)
        r.extend([u.uid for u in users])
    return r
示例#21
0
def members(*groups):
    r = []
    for group in groups:
        users = Group.get_users(group)
        r.extend([u.uid for u in users])
    return r
示例#22
0
 def delete(self, name):
     Group.delete(name)
     return self.succ()