Пример #1
0
def get_data_use_sql(model, start_index, end_index, filter_params):
    u'''特殊处理模型特殊模型的导出,优化'''
    from django.db import connection as cnn
    from base.middleware.threadlocals import get_current_request
    from mysite.personnel.models.model_deptadmin import DeptAdmin
    request = get_current_request()
    dict_export = get_eport_dict()
    sql_key = model._meta.app_label + "." + model.__name__
    if dict_export.has_key(sql_key):
        fields = dict_export[sql_key]["db_fields"]
        use_perms = dict_export[sql_key]["use_perms"]
        need_verbose_field = dict_export[sql_key]["verbose_fields"]
        cur = cnn.cursor()
        sql_add = ""
        #print dict_export[sql_key]["sql"]%(filter_params, start_index, end_index)
        dept_admin_ids = DeptAdmin.objects.filter(
            user=request.user).values_list("dept_id", flat=True)
        try:
            if use_perms == "True":  #使用按授权部门权限导出
                if not request.user.is_superuser:
                    if dept_admin_ids:  #登录用户有按授权部门分配
                        sql_add = "and u.defaultdeptid in (select dept_id from deptadmin where user_id=%s)" % request.user.pk
                        sql = dict_export[sql_key]["sql"] % (
                            sql_add, filter_params, start_index, end_index)
                    else:
                        sql = dict_export[sql_key]["sql"] % (
                            sql_add, filter_params, start_index, end_index)
                    cur.execute(sql)
                else:
                    cur.execute(dict_export[sql_key]["admin_sql"] %
                                (filter_params, start_index, end_index))
            else:
                cur.execute(dict_export[sql_key]["sql"] %
                            (filter_params, start_index, end_index))
            records = cur.fetchall() or []
            cnn._commit()
        except:
            import traceback
            traceback.print_exc()
            records = ""
        ret = []
        fields_len = len(fields)
        for elem in records:
            row = {}
            for i in range(fields_len):
                e = elem[i]
                if need_verbose_field.has_key("%s" % i):
                    tmp_dict = dict(
                        model._meta.get_field(
                            need_verbose_field["%s" % i]).get_choices())
                    if tmp_dict.has_key(e):  # and e:
                        row[fields[i]] = u"%s" % (tmp_dict[e])
                    else:
                        row[fields[i]] = e
                else:
                    row[fields[i]] = e
            ret.append(row)
        return ret
    else:
        return []
Пример #2
0
def render_emp_widget(name, data, multiple, popup, filter):
    #员工自助
    req = get_current_request()
    if req.session.has_key("employee"):
        emp = req.session["employee"]
        return u"<input type='hidden' value =%(v)s name =%(n)s /><span>%(d)s</span>" % {
            "v": emp.pk,
            "n": name,
            "d": emp,
        }

    js_attrs = {}
    try:
        from depttree import DeptTree
        from mysite.personnel.models import Employee, Department
        from dbapp.urls import dbapp_url
        from mysite.urls import surl
        if type(data) == list:
            data = ','.join(d for d in [str(i) for i in data])
        url = data and ("/%s%s/select_emp_data/?id__exact=%s" %
                        (surl, Employee._meta.app_label, data)) or (
                            "/%s%s/select_emp_data/?%s" %
                            (surl, Employee._meta.app_label, filter))
        date_now = datetime.datetime.now()
        str_now = str(date_now.strftime('%Y%m%d%H%M%S')) + str(
            date_now.microsecond) + name
        js_attrs["multiple_select"] = multiple
        js_attrs["popup"] = popup
        js_attrs["select_record"] = data and data or False
        js_attrs["field_name"] = name
        js_attrs["grid_id"] = "emp_select_%s" % (str_now)
        js_attrs["surl"] = surl
        js_attrs["model_url"] = url
        json_attrs = simplejson.dumps(js_attrs)
        html = ""
        if multiple:
            html += u"<input type='hidden' name='multipleFieldName' value='%s' />" % name
        html+=u"<table id='id_corner_tbl' class='corner_tbl' cellpadding='0' cellspacing='0' style='float:left;'><tr><td></td><td></td><td class='tboc1 h1'></td><td></td><td></td></tr>" \
            +u"<tr><td></td><td class='tboc1 w1 h1'>&nbsp;</td><td class='tbac1'></td>" \
            +u"<td class='tboc1 w1 h1'>&nbsp;</td><td></td></tr><tr><td class='tboc1 w1'>&nbsp;" \
            +u"</td><td class='tbac1 tbg'></td><td class='tbac1 tbg td_contant'><div class='div_contant'>" \
                    +u"<div class='zd_Emp div_box_emp'>" \
                            +u"<div id='%s'></div>"%(js_attrs["grid_id"]) \
                            +"<script> $(document).ready(function(){$.zk._select_emp(%s);}) </script>"%(json_attrs) \
                    +"</div>" \
            +u"<div class='clear'></div></div></td><td class='tbac1 tbg'>"\
            +u"</td><td class='tboc1 w1'>&nbsp;</td></tr>" \
            +u"<tr><td></td><td class='tboc1 w1 h1'>&nbsp;</td><td class='tbac1'></td><td class='tboc1 w1 h1'>&nbsp;</td>" \
            +u"<td></td></tr><tr><td></td><td></td><td class='tboc1 h1'></td><td></td><td></td></tr></table>"
        return html

    except:
        import traceback
        traceback.print_exc()
Пример #3
0
    def value_from_datadict(self, data, files, name):
        u"是否选择下级节点,递归预处理选择的节点"
        from django.utils.datastructures import MultiValueDict, MergeDict
        from mysite.personnel.models import Employee
        from mysite.iclock.iutils import get_area_from_all, get_max_in
        from base.middleware.threadlocals import get_current_request

        if isinstance(data, (MultiValueDict, MergeDict)):
            dept_ids = data.getlist(name)
            check_child_name = u"%schecked_child" % name
            is_checked_child = data.get(check_child_name)

            if is_checked_child == "on":
                request = get_current_request()
                dept_ids = get_area_from_all(dept_ids, request)
            return dept_ids
        else:
            return data.get(name, None)
Пример #4
0
    def delete(self):
        u"删除加班单"
        req = get_current_request()
        if req.session.has_key("employee"):
            if self.audit_status == AUDIT_SUCCESS:
                raise Exception(_(u'审核通过的记录不能被删除'))
        if self.audit_status == AUDIT_SUCCESS:
            from model_waitforprocessdata import WaitForProcessData as wfpd
            wtmp = wfpd()
            st = datetime.datetime(self.starttime.year, self.starttime.month,
                                   self.starttime.day, 0, 0, 0)
            et = datetime.datetime(self.endtime.year, self.endtime.month,
                                   self.endtime.day, 23, 59, 59)
            wtmp.UserID = self.emp
            wtmp.starttime = st
            wtmp.endtime = et
            wtmp.save()

        super(OverTime, self).delete()
Пример #5
0
    def save(self, *args, **kwargs):
        if not self.emp:
            raise Exception(_(u'必须选择人员'))
        if self.start >= self.end:
            raise Exception(_(u'结束时间不能小于或等于开始时间'))
        tt = EmpSpecDay.objects.filter(emp=self.emp,
                                       start__lte=self.end,
                                       end__gte=self.start)
        if tt and tt[0].id != self.id:
            raise Exception(_(u'请假时间重复'))
#        if tt and int(tt[0].audit_status)== AUDIT_SUCCESS:
        if self.id and tt and tt[0].audit_status == AUDIT_SUCCESS:
            raise Exception(_(u'审核通过的请假记录不能修改'))
#        tmp=EmpSpecDay.objects.filter(Q(emp=self.emp,start__lte=self.start,end__gte=self.end)| Q(emp=self.emp,start__gte=self.start,end__lte=self.end)).exclude(pk=1)
#        if tmp and tmp[0].pk !=self.pk :
#            raise Exception(_(u'已存在相同请假记录!'))

        req = get_current_request()
        if self.pk:
            tx = EmpSpecDay.objects.get(pk=self.pk)
            if req.session.has_key("employee"):
                if int(tx.audit_status) == AUDIT_SUCCESS:
                    raise Exception(_(u'该记录已审核'))
                if int(tx.state) == REFUSE:
                    self.audit_status = APPLICATION_AGAIN
        elif (not req.session.has_key("employee")):
            self.audit_status = AUDIT_SUCCESS

        super(EmpSpecDay, self).save()
        from mysite.att.models.__init__ import get_autocalculate_time as gct
        from model_waitforprocessdata import WaitForProcessData as wfpd
        import datetime
        gct_time = gct()
        if self.start < gct_time or self.end <= gct_time:
            wtmp = wfpd()
            st = self.start
            et = self.end
            wtmp.UserID = self.emp
            wtmp.starttime = st
            wtmp.endtime = et
            #wtmp.customer=self.customer
            wtmp.save()
Пример #6
0
    def save(self):
        #验证
        obj_tmp = OverTime.objects.filter(emp=self.emp,
                                          starttime__lte=self.endtime,
                                          endtime__gte=self.starttime)
        if obj_tmp and obj_tmp[0].pk != self.pk:
            raise Exception(_(u'加班记录重复'))
        if self.endtime <= self.starttime:
            raise Exception(_(u'结束时间不能小于等于开始时间'))

        req = get_current_request()
        if self.pk:  #编辑
            tmp = OverTime.objects.get(pk=self.pk)
            if req.session.has_key("employee"):  #员工自助用户申请或者重新申请
                if tmp.audit_status == REFUSE:
                    self.audit_status = APPLICATION_AGAIN
                if tmp.audit_status == AUDIT_SUCCESS:
                    raise Exception(_(u'该记录已审核'))
        elif (not req.session.has_key("employee")):  #管理员,新增,默认就是审核通过
            self.audit_status = AUDIT_SUCCESS

        super(OverTime, self).save()
        #        from mysite.att.calculate.global_cache import JBD_DATA
        #        if JBD_DATA.has_key(self.emp.id):
        #            del JBD_DATA[self.emp.id]
        if self.audit_status == AUDIT_SUCCESS:
            from mysite.att.models.__init__ import get_autocalculate_time as gct
            from model_waitforprocessdata import WaitForProcessData as wfpd

            gct_time = gct()
            if self.starttime < gct_time or self.endtime <= gct_time:
                wtmp = wfpd()
                st = datetime.datetime(self.starttime.year,
                                       self.starttime.month,
                                       self.starttime.day, 0, 0, 0)
                et = datetime.datetime(self.endtime.year, self.endtime.month,
                                       self.endtime.day, 23, 59, 59)
                wtmp.UserID = self.emp
                wtmp.starttime = st
                wtmp.endtime = et
                wtmp.save()
Пример #7
0
    def value_from_datadict(self, data, files, name):
        #        from django.utils.datastructures import MultiValueDict, MergeDict
        #        if isinstance(data, (MultiValueDict, MergeDict)):
        #            dept_all = data.getlist("dept_all")#'on'或者''
        #
        #            if dept_all:#选择部门下所有人员
        #                dept_id = data.getlist("deptIDs")
        #                #print '------dept_id=',dept_id
        #                from mysite.personnel.models import Employee
        #                return [e.pk for e in MeetingEmp.objects.filter(DeptID__in = dept_id)]
        #            else:
        #                return data.getlist(name)
        #        else:
        #            return data.get(name, None)
        from django.utils.datastructures import MultiValueDict, MergeDict
        from mysite.personnel.models import Employee
        from mysite.personnel.models.empwidget import filter_for_select_emp
        from mysite.iclock.iutils import get_dept_from_all, get_max_in

        if isinstance(data, (MultiValueDict, MergeDict)):
            dept_all = data.getlist(u"%s_dept_all" % name)  #'on'或者''
            if dept_all:  #选择部门下所有人员
                dept_id = data.getlist("deptIDs")
                deptIDschecked_child = data.get("deptIDschecked_child")
                if deptIDschecked_child == "on":
                    request = get_current_request()
                    dept_id = get_dept_from_all(dept_id, request)
                UserID = get_max_in(filter_for_select_meetingemp(data),
                                    dept_id, "DeptID__in")
                print "data", data
                print "data.meetingid", data.getlist("meetingID")
                print "------------", int(data.getlist("meetingID")[0])

                print "UserID", UserID
                u = [e.pk for e in UserID]

                return u
            else:
                return data.getlist(name)
        else:
            return data.get(name, None)
Пример #8
0
    def value_from_datadict(self, data, files, name):
        from django.utils.datastructures import MultiValueDict, MergeDict
        from mysite.personnel.models import Employee
        from mysite.iclock.iutils import get_dept_from_all, get_max_in

        if isinstance(data, (MultiValueDict, MergeDict)):
            dept_all = data.getlist(u"%s_dept_all" % name)  #'on'或者''
            if dept_all:  #选择部门下所有人员
                dept_id = data.getlist("deptIDs")
                deptIDschecked_child = data.get("deptIDschecked_child")
                if deptIDschecked_child == "on":
                    request = get_current_request()
                    dept_id = get_dept_from_all(dept_id, request)
                UserID = get_max_in(filter_for_select_emp(data), dept_id,
                                    "DeptID__in")
                u = [e.pk for e in UserID]

                return u[:1001]
            else:
                return data.getlist(name)
        else:
            return data.get(name, None)
Пример #9
0
    def limit_originalrecord_to(self, queryset, user):
        from base.middleware.threadlocals import get_current_request
        request = get_current_request()
        from mysite.iclock.iutils import get_dept_from_all, get_max_in
        deptids = request.GET.get('UserID__DeptID__in', "").split(',')
        meetingids = request.GET.get('meetingID__in', "").split(',')
        typeids = request.GET.get('checkType__in', "").split(',')
        users = request.GET.get('user__in', "")
        if users == "":
            users = None
        list_user = list(str(users).split(','))
        user_list = []
        if request:
            if len(deptids) > 0:
                dept_id = deptids
                checked_child = request.GET.get('deptIDschecked_child', None)
                if checked_child == "on" and dept_id:  #包含部门下级
                    depts = get_dept_from_all(dept_id, request)
                    if len(meetingids) > 0:
                        meetingid = meetingids
                        if meetingid[0] != "":
                            if len(typeids) > 0:
                                typeid = typeids
                                if typeid[0] != "":
                                    user_list = get_max_in(
                                        OriginalRecord.objects.filter(
                                            meetingID__in=meetingid,
                                            checkType__in=typeid), depts,
                                        "user__DeptID__in")
                                else:
                                    user_list = get_max_in(
                                        OriginalRecord.objects.filter(
                                            meetingID__in=meetingid), depts,
                                        "user__DeptID__in")
                            elif len(typeids) > 0:
                                typeid = typeids
                                if typeid[0] != "":
                                    user_list = get_max_in(
                                        OriginalRecord.objects.filter(
                                            checkType__in=typeid), depts,
                                        "user__DeptID__in")
                            else:
                                user_list = get_max_in(
                                    OriginalRecord.objects.filter(), dept_id,
                                    "user__DeptID__in")
                        elif typeids[0] != "":
                            typeid = typeids
                            user_list = get_max_in(
                                OriginalRecord.objects.filter(
                                    checkType__in=typeid), depts,
                                "user__DeptID__in")
                        else:
                            user_list = get_max_in(
                                OriginalRecord.objects.all(), depts,
                                "user__DeptID__in")
                    else:
                        user_list = get_max_in(
                            OriginalRecord.objects.filter(
                                meetingID__in=meetingid, checkType__in=typeid),
                            depts, "user__DeptID__in")

                if dept_id[0] == "":
                    if len(meetingids) > 0:
                        meetingid = meetingids
                        if meetingid[0] != "":
                            if len(typeids) > 0:
                                typeid = typeids
                                if typeid[0] != "":
                                    if users != None:
                                        user_list = OriginalRecord.objects.filter(
                                            meetingID__in=meetingid,
                                            checkType__in=typeid,
                                            user__in=list_user)
                                    else:
                                        user_list = OriginalRecord.objects.filter(
                                            meetingID__in=meetingid,
                                            checkType__in=typeid)
                                else:
                                    user_list = OriginalRecord.objects.filter(
                                        meetingID__in=meetingid)

                            if users != None:
                                if len(typeids) > 0:
                                    typeid = typeids
                                    if typeid[0] != "":
                                        user_list = OriginalRecord.objects.filter(
                                            meetingID__in=meetingid,
                                            checkType__in=typeid,
                                            user__in=list_user)
                                    else:
                                        user_list = OriginalRecord.objects.filter(
                                            meetingID__in=meetingid,
                                            user__in=list_user)
                        else:
                            if len(typeids) > 0 and users != None:
                                typeid = typeids
                                if typeid[0] != "":
                                    user_list = OriginalRecord.objects.filter(
                                        checkType__in=typeid,
                                        user__in=list_user)
                                else:
                                    user_list = OriginalRecord.objects.filter(
                                        user__in=list_user)
                    else:
                        user_list = OriginalRecord.objects.filter(
                            meetingID__in=meetingid,
                            checkType__in=typeid,
                            user__in=list_user)

        return user_list