class PositionSelect(GridModel): ''' 职位选择 ''' verbose_name=u'职位选择' app_menu ="personnel" menu_index=15 visible = False # template = 'TransInfo_GridModel.html' head = [('id',u'id'),('pname',u'职位名称'),('pcode',u'职位编号'),('dname',u'组织名称'),('dcode',u'组织代码'),('DeptID',u'组织ID')] search_form = [ ('pname',forms.CharField(label=u'职位名称')), ('pcode',forms.CharField(label=u'职位编号')), ('dname',forms.CharField(label=u'组织名称')), ('dcode',forms.CharField(label=u'组织代码')), ] option = { "usepager": True, # "title": 'Countries', "useRp": True, "rp": 20, "height":165, 'checkbox' : True, "showTableToggleBtn":False, "onToggleCol" : False, "buttons":[ {"name": '选择', "bclass": 'select', "onpress" : '$do_select$'}, ], } def __init__(self, request): super(PositionSelect, self).__init__() #设置sql self.grid.sql = sqlUtil.getPositionSelectSql() #设置 colum 属性 self.grid.fields["id"]["width"]=10 self.grid.fields["pcode"]["width"]=120 self.grid.fields["dname"]["width"]=120 self.grid.fields["dcode"]["width"]=120 self.grid.fields["dname"]["width"]=120 self.grid.fields["id"]["hide"] = True self.grid.fields["DeptID"]["hide"] = True def MakeData(self,request,**arg): #添加数据 self.ParseLike(request) deptids = GetAuthoIDs(request.user,1) if deptids: self.grid.sql += " and DeptID in (%s)"%deptids pass
class EmpSelect(GridModel): ''' 人员选择 ''' verbose_name = u'人员选择' icon_class = "menu_people" app_menu = "personnel" menu_index = 15 visible = False # template = 'TransInfo_GridModel.html' head = [('userid', u'userid'), ('badgenumber', u'身份证号码'), ('name', u'姓名'), ('DeptName', u'组织'), ('code', u'组织代码'), ('DeptID', u'组织ID')] search_form = [('DeptName', forms.CharField(label=u'组织名称')), ('code', forms.CharField(label=u'组织代码')), ('name', forms.CharField(label=u'人员姓名')), ('badgenumber', forms.CharField(label=u'身份证号码'))] option = { "usepager": True, "useRp": True, "rp": 20, "height": 170, 'checkbox': True, "showTableToggleBtn": False, "onToggleCol": False, 'sortname': "DeptName", 'sortorder': "asc", "buttons": [ { "name": '选择', "bclass": 'select', "onpress": '$do_select$' }, ], } def __init__(self, request): super(EmpSelect, self).__init__() #设置sql from mosys.sql_utils import get_sql self.grid.sql = get_sql("sqls", "emp_select") #sqlUtil.getEmpSelectSql() #设置 colum 属性 self.grid.fields["userid"]["width"] = 10 self.grid.fields["badgenumber"]["width"] = 100 self.grid.fields["name"]["width"] = 100 self.grid.fields["DeptName"]["width"] = 120 self.grid.fields["code"]["width"] = 100 self.grid.fields["userid"]["hide"] = True self.grid.fields["DeptID"]["hide"] = True def MakeData(self, request, **arg): #添加数据 self.ParseLike(request) deptids = GetAuthoIDs(request.user, 1) if deptids: self.grid.sql += " and DeptID in (%s)" % deptids pass
class EmployeeReport(GridModel): ''' 人员报告 ''' verbose_name=u'Redis中人员报告' app_menu ="personnel" menu_grup = 'att_monitor' icon_class = "menu_people" menu_index=15 visible = True head = [('pin',u'工号'),('EName',u'姓名'),('Card',u'卡号'),('Password',u'密码'),('area',u'区域'),('device',u'设备'),('fingerprint',u'指纹'), ('face',u'面部'), ('employeepic',u'用户照片')] search_form = [ ('pin',forms.CharField(label=u'工号')) ] option = { "usepager": True, "useRp": True, "rp": 20, "height":350, 'checkbox' : False, "showTableToggleBtn":True, "buttons":[{"name": '导出xls', "bclass": 'export_xls', "onpress" : '$do_export$'}], } def __init__(self, request): super(EmployeeReport, self) .__init__() self.grid.fields["area"]["width"]=200 self.grid.fields["device"]["width"]=350 def MakeData(self,request,**arg): #添加数据 from ooredis.client import get_client m_client = get_client() m_pin = request.params.get('pin',None) if m_pin: keys = m_client.keys("employee:*%s*:info"%m_pin) else: keys = m_client.keys("employee:*:info") self.Paging(arg['offset'],item_count=len(keys)) m_keys = keys[self.grid._begin:self.grid._end] self.grid.InitItems() for e in m_keys: r = self.grid.NewItem() emp = Dict(e) r["pin"] = e.split(':')[1] r["EName"] = emp["EName"] r["Card"] = emp["Card"] r["Password"] = emp["Password"] m_area = Set('employee:%s:areas'%r["pin"]) if m_area: r["area"] = ', '.join(m_area) else: r["area"] = '' m_device = Set('employee:%s:devices'%r["pin"]) if m_area: r["device"] = ', '.join(m_device) else: r["device"] = '' m_keys = m_client.keys("fingerprint:%s|*"%r["pin"]) if len(m_keys)>0: r["fingerprint"] = '有' else: r["fingerprint"] = '' m_keys = m_client.keys("face:%s|*"%r["pin"]) if len(m_keys)>0: r["face"] = '有' else: r["face"] = '' m_keys = m_client.keys("employeepic:%s"%r["pin"]) if len(m_keys)>0: r["employeepic"] = '有' else: r["employeepic"] = '' self.grid.AddItem(r)
class SvnChangeInfo(GridModel): ''' 更改日志 ''' verbose_name = u'更改日志' app_menu = "att" icon_class = "menu_monitor" menu_index = 15 visible = True # template = 'TransInfo_GridModel.html' head = [('version', u'提交版本'), ('author', u'提交人'), ('time', u'提交日期'), ('file', u'文件名'), ('path', u'文件目录'), ('desc', u'修改原因')] search_form = [ ('author', forms.CharField(label=u'提交人', initial='jone')), # ('start', models.DateTimeField(verbose_name=u'开始日期')), # ('end', models.DateTimeField(verbose_name=u'结束日期')), ] option = { "usepager": False, # "title": 'Countries', "useRp": True, "rp": 20, "height": 380, 'checkbox': True, "showTableToggleBtn": True, # 'sortname' : "DeptName", # 'sortorder' : "asc", "buttons": [{ "name": '导出', "bclass": 'add', "onpress": '$do_export$' }], # "searchitems" : [ # {'display': '人员编号', 'name' : 'badgenumber', 'isdefault': True}, # {'display': '姓名', 'name' : 'name'}, # {'display': '所在部门', 'name' : 'DeptName'}, # ], } def __init__(self, request): super(SvnChangeInfo, self).__init__() #设置sql #设置 colum 属性 self.grid.fields["version"]["width"] = 80 self.grid.fields["author"]["width"] = 80 self.grid.fields["time"]["width"] = 150 self.grid.fields["file"]["width"] = 240 self.grid.fields["path"]["width"] = 300 self.grid.fields["desc"]["width"] = 400 def MakeData(self, request, **arg): #添加数据 m_list = ParseSvnInfo() m_author = request.POST.get('author', '') self.grid.InitItems() for e in m_list: r = self.grid.NewItem() r["version"] = e["version"] r["author"] = e["author"] if m_author: if r["author"] != m_author: continue r["time"] = e["time"] r["desc"] = '%s' % e["desc"] for m in e["action"]: r["file"] = '%s: %s' % (m[0], m[2]) r["path"] = m[1] self.grid.AddItem(r) self.Paging(1) pass
class DeptSelect(GridModel): ''' 组织选择 ''' verbose_name = u'组织选择' icon_class = "menu_vault" app_menu = "personnel" menu_index = 15 visible = False head = [('DeptID', u'DeptID'), ('code', u'组织代码'), ('DeptName', u'组织名称')] search_form = [ ('DeptName', forms.CharField(label=u'组织名称')), ('code', forms.CharField(label=u'组织代码')), ] option = { "usepager": True, "useRp": True, "rp": 20, "height": 195, 'checkbox': True, "showTableToggleBtn": False, "onToggleCol": False, 'sortname': "code", 'sortorder': "asc", "buttons": [ { "name": '选择', "bclass": 'select', "onpress": '$do_select$' }, ], } def __init__(self, request): super(DeptSelect, self).__init__() #设置sql from mosys.sql_utils import get_sql self.grid.sql = get_sql("sqls", "dept_select") # self.grid.sql_data = "select DeptID,code,DeptName from departments where status=0 LIMIT 0,20" #设置 colum 属性 self.grid.fields["DeptID"]["width"] = 10 self.grid.fields["code"]["width"] = 200 self.grid.fields["DeptName"]["width"] = 200 self.grid.fields["DeptID"]["hide"] = True def MakeData(self, request, **arg): self.ParseLike(request) deptids = GetAuthoIDs(request.user, 1) if deptids: self.grid.sql += " and DeptID in (%s)" % deptids #添加数据 pass
class ChangeRecord(GridModel): ''' 调动记录 ''' WAIT = 1 PASS = 2 REFUSE = 3 #当前状态 AUDIT_STATUS = ( (WAIT, u'待审核'), (PASS, u'审核通过'), (REFUSE, u'拒绝'), ) verbose_name = u'调动记录' icon_class = "menu_home" app_menu = "personnel" menu_index = 3 visible = True # template = 'position_change.html' head = [('id', u'id'), ('UserID_id', u'UserID_id'), ('badgenumber', u'身份证号码'), ('name', u'姓名'), ('changeType', u'调动类型'), ('oldvalue', u'调动前'), ('newvalue', u'调动后'), ('currStatus', u'当前状态'), ('applicationTime', u'申请时间'), ('changereason', u'申请原因'), ('checkTime', u'审核时间'), ('remark', u'审核备注'), ('defaultdeptid', u'defaultdeptid')] search_form = [ ('UserID_id', forms.CharField( label=u'人员', widget=MultySelectFieldWidget( attrs={'url': '/page/personnel/EmpSelect/?pure'}))), ('defaultdeptid', forms.CharField( label=u'组织', widget=MultySelectFieldWidget( attrs={'url': '/page/personnel/DeptSelect/?pure'}))), ('currStatus', forms.ChoiceField(label=u'状态', choices=AUDIT_STATUS, initial=WAIT)) ] option = { "usepager": True, "useRp": True, "rp": 20, "height": 340, 'checkbox': True, "showTableToggleBtn": False, "onToggleCol": False, } def __init__(self, request): super(ChangeRecord, self).__init__() #设置sql self.grid.sql = sqlUtil.getChangeRecordSql() def getName(sql): cursor = connection.cursor() cursor.execute(sql) rows = cursor.fetchall() return ",".join([row[0] for row in rows]) def getValue(types, val): """ parm: type:类型 val:id值 return: name """ if val == "" or val == "None": return "" deptSql = """ select DeptName from departments where DeptID in (%s) """ % val areaSql = """ select areaname from personnel_area where id in(%s) """ % val positionSql = """ select name from personnel_positions where id in (%s) """ % val if types == 1: return getName(deptSql) elif types == 2: return getName(areaSql) else: return getName(positionSql) def fooOldvalue(r): types = r[4] #调动类型对应sql语句中的第5列,如果sql语句中发生变化,请注意调整该处 value = r[5] #调动前id值对应sql语句中的第6列,如果sql语句中发生变化,请注意调整该处 return getValue(types, value) def fooNewvalue(r): type = r[4] #调动类型对应sql语句中的第5列,如果sql语句中发生变化,请注意调整该处 value = r[6] #调动后id值对应sql语句中的第7列,如果sql语句中发生变化,请注意调整该处 return getValue(type, value) def fooChangeType(r): """ 调动类型 1:企业组织机构 2:项目区域 3:职位 """ val = r[4] #调动类型对应sql语句中的第5列,如果sql语句中发生变化,请注意调整该处 if val == 1: return u"企业组织机构" elif val == 2: return u"项目区域" else: return u"职位" def fooCurrStatus(r): """ 当前状态 1:待审核 2:审核通过 3:拒绝 """ val = r[7] #当前状态对应sql语句中的第8列,如果sql语句中发生变化,请注意调整该处 if val == 1: return u"待审核" elif val == 2: return u"审核通过" else: return u"拒绝" #设置 colum 属性 self.grid.fields["id"]["width"] = 10 self.grid.fields["UserID_id"]["width"] = 10 self.grid.fields["badgenumber"]["width"] = 100 self.grid.fields["name"]["width"] = 80 self.grid.fields["changeType"]["width"] = 80 self.grid.fields["oldvalue"]["width"] = 180 self.grid.fields["newvalue"]["width"] = 180 self.grid.fields["applicationTime"]["width"] = 120 self.grid.fields["changereason"]["width"] = 150 self.grid.fields["currStatus"]["width"] = 80 self.grid.fields["checkTime"]["width"] = 120 self.grid.fields["remark"]["width"] = 150 self.grid.fields["id"]["hide"] = True self.grid.fields["UserID_id"]["hide"] = True self.grid.fields["defaultdeptid"]["hide"] = True self.grid.colum_trans["oldvalue"] = fooOldvalue self.grid.colum_trans["newvalue"] = fooNewvalue self.grid.colum_trans["changeType"] = fooChangeType self.grid.colum_trans["currStatus"] = fooCurrStatus def MakeData(self, request, **arg): #添加数据 UserID_id = request.params.get("UserID_id", '') if UserID_id: self.grid.sql += " and UserID_id in (%s)" % UserID_id deptids = GetAuthoIDs(request.user, 1) defaultdeptid = request.params.get("defaultdeptid", '') if defaultdeptid: self.grid.sql += " and defaultdeptid in (%s)" % defaultdeptid elif deptids: self.grid.sql += " and defaultdeptid in (%s)" % deptids changeType = request.params.get("changeType", '') currStatus = request.params.get("currStatus", '') if changeType: self.grid.sql += " and changeType=%s" % changeType if currStatus: self.grid.sql += " and currStatus=%s" % currStatus pass
class TransInfo(GridModel): ''' 人员调动 ''' verbose_name = u'人员调动' icon_class = "menu_interact" app_menu = "personnel" menu_index = 2 visible = True template = 'TransInfo_GridModel.html' head = [('userid', u'userid'), ('defaultdeptid', u'defaultdeptid'), ('name', u'姓名'), ('badgenumber', u'身份证号码'), ('DeptName', u'组织名称'), ('code', u'组织代码'), ('areaname', u'项目区域'), ('areaid', u'areaid'), ('pname', u'职位'), ('pid', u'pid')] search_form = [ ('defaultdeptid', forms.CharField( label=u'组织', initial='jone', widget=MultySelectFieldWidget( attrs={'url': '/page/personnel/DeptSelect/?pure'}))), ('areaid', forms.CharField( label=u'项目区域', widget=MultySelectFieldWidget( attrs={'url': '/page/personnel/AreaSelect/?pure'}))), ('pid', forms.CharField( label=u'职位', widget=MultySelectFieldWidget( attrs={'url': '/page/personnel/PositionSelect/?pure'}))), ('name', forms.CharField(label=u'姓名')), ('badgenumber', forms.CharField(label=u'身份证号码')) ] option = { "usepager": True, # "title": 'Countries', "useRp": True, "rp": 20, "height": 280, 'checkbox': True, "showTableToggleBtn": True, "buttons": [ # {"name": '导出', "bclass": 'add', "onpress" : '$do_export$'}, { "name": '调整组织', "bclass": 'dept_chg', "onpress": '$do_deptchange$' }, { "name": '调整项目区域', "bclass": 'area_chg', "onpress": '$do_areachange$' }, { "name": '调整职位', "bclass": 'pos_chg', "onpress": '$do_positionchange$' }, { "name": '组织调动记录', "bclass": 'dept_chg', "onpress": '$record_deptchange$' }, { "name": '项目区域调动记录', "bclass": 'area_chg', "onpress": '$record_areachange$' }, { "name": '职位调动记录', "bclass": 'pos_chg', "onpress": '$record_positionchange$' }, ], "searchitems": [ { 'display': '身份证号码', 'name': 'badgenumber', 'isdefault': True }, { 'display': '姓名', 'name': 'name' }, { 'display': '所在组织', 'name': 'DeptName' }, ], } def __init__(self, request): super(TransInfo, self).__init__() #设置sql self.grid.sql = sqlUtil.getTransInfoSql() #设置 colum 属性 self.grid.fields["userid"]["width"] = 10 self.grid.fields["defaultdeptid"]["width"] = 10 self.grid.fields["name"]["width"] = 100 self.grid.fields["badgenumber"]["width"] = 100 self.grid.fields["DeptName"]["width"] = 100 self.grid.fields["code"]["width"] = 100 self.grid.fields["areaname"]["width"] = 300 self.grid.fields["areaid"]["width"] = 10 self.grid.fields["pname"]["width"] = 300 self.grid.fields["pid"]["width"] = 10 self.grid.fields["userid"]["hide"] = True self.grid.fields["defaultdeptid"]["hide"] = True self.grid.fields["areaid"]["hide"] = True self.grid.fields["pid"]["hide"] = True def MakeData(self, request, **arg): #添加数据 def GetIds(sql): cursor = connection.cursor() cursor.execute(sql) rows = cursor.fetchall() return [str(row[0]) for row in rows] emp_ids = [] areaid = request.params.get("areaid", '') if areaid: emp_ids += GetIds( "select employee_id from userinfo_attarea where area_id in (%s)" % areaid) pid = request.params.get("pid", '') if pid: emp_ids += GetIds( "select employee_id from userinfo_position where position_id in (%s)" % pid) if emp_ids: m_emp = ','.join(set(emp_ids)) self.grid.sql += " and userid in (%s)" % m_emp else: if areaid or pid: self.grid.sql += " and 1=2 " #deptids = GetAuthoIDs(request.user,1) defaultdeptid = request.params.get("defaultdeptid", '') if defaultdeptid: self.grid.sql += " and defaultdeptid in (%s)" % defaultdeptid # elif deptids: # self.grid.sql += " and defaultdeptid in (%s)"%deptids name = request.params.get('name', '') if name: self.grid.sql += " and name like '%%%%%s%%%%'" % name badgenumber = request.params.get('badgenumber', '') if badgenumber: self.grid.sql += " and badgenumber like '%%%%%s%%%%'" % badgenumber pass
class SumReport(GridModel): ''' 出勤汇总 ''' from django.utils.translation import ugettext as _ verbose_name = u'出勤报表' app_menu = "att" menu_index = 20 visible = False template = 'sum_report.html' head = [ ('userid', u'userid'), ('DeptID', u'DeptID'), ('name', u'姓名'), ('badgenumber', u'身份证号'), ('DeptName', u'组织名称'), ('attTimes_sum', u'累计时长'), ('attDays_sum', u'累计工作日'), ('overtimes_sum', u'加班时间'), ('leaveimes_sum', u'请假时长'), ('stopWorkTimes_sum', u'停工时长'), ('completionRate', u'完成率'), ] search_form = [ ('userid', forms.CharField( label=u'人员', widget=MultySelectFieldWidget( attrs={'url': '/page/personnel/EmpSelect/?pure'}))), ('DeptID', forms.CharField( label=u'组织', widget=MultySelectFieldWidget( attrs={'url': '/page/personnel/DeptSelect/?pure'}))), ('badgenumber', forms.CharField(label=u'身份证号')), ('startDate', forms.DateTimeField( label=u'开始日期', widget=FormatDateTimeFieldWidget(attrs={ 'format': 'yyyy-MM-dd', 'readonly': 'true' }), initial=datetime.datetime.now().strftime('%Y-%m-01'))), ('endDate', forms.DateTimeField( label=u'结束日期', widget=FormatDateTimeFieldWidget(attrs={ 'format': 'yyyy-MM-dd', 'readonly': 'true' }), initial=datetime.datetime.now().strftime('%Y-%m-%d'))), ] option = { "usepager": True, "useRp": True, "rp": 20, "height": 290, 'checkbox': False, "showTableToggleBtn": False, "onToggleCol": False, "buttons": [ { "name": '导出', "bclass": 'export', "onpress": '$do_export$' }, ], } def __init__(self, request): super(SumReport, self).__init__() #设置sql self.grid.sql = ''' select u.userid,d.DeptID,u.name,u.badgenumber,d.DeptName, SUM(ar.attTimes) attTimes_sum, SUM(ar.attDays) attDays_sum, SUM(ar.overtimes) overtimes_sum, SUM(ar.leaveimes) leaveimes_sum, SUM(ar.stopWorkTimes) stopWorkTimes_sum, 1 completionRate from attResult ar left join userinfo u on u.userid = ar.userid left join departments d on u.defaultdeptid = d.DeptID where 1=1 group by u.userid,u.name,u.badgenumber,d.DeptName,d.DeptID ''' def isZJ(pos): """判断用户是否有总监的职位""" for p in pos: if p.id == 1: return True return False def fooRate(r): """ 完成率颜色变化 """ val = r[10] #出勤率对应sql语句中的第2列,如果sql语句中发生变化,请注意调整该处 useid = r[0] #员工工号 attTimes = r[5] #出勤时长 attDays = r[6] #工作日 leaveimes = r[8] # 请假 stopWorkTimes = r[9] # 停工 rate = 0 sum = attDays * 8 - leaveimes - stopWorkTimes if sum <> 0: rate = attTimes / sum emp = Employee.all_objects.get(id=useid) pos = emp.position.all() flag = isZJ(pos) if flag: if rate < 0.5: return u"<font color=red>%10.2f(不达标)</font>" % rate else: if rate < 0.8: return u"<font color=red>%10.2f(不达标)</font>" % rate return rate def fooName(r): """ 姓名转化 """ val = r[2] #人员姓名对应sql语句中的第2列,如果sql语句中发生变化,请注意调整该处 val_id = r[0] return '<a href="javascript:showDetail(%s);" title="点击查看详情">%s</a>' % ( val_id, val) #设置 colum 属性 self.grid.fields["name"]["width"] = 100 self.grid.fields["badgenumber"]["width"] = 150 self.grid.fields["DeptName"]["width"] = 100 self.grid.fields["attTimes_sum"]["width"] = 80 self.grid.fields["attDays_sum"]["width"] = 80 self.grid.fields["overtimes_sum"]["width"] = 80 self.grid.fields["leaveimes_sum"]["width"] = 80 self.grid.fields["stopWorkTimes_sum"]["width"] = 80 self.grid.fields["completionRate"]["width"] = 150 self.grid.fields["attTimes_sum"]["sortable"] = True self.grid.fields["attDays_sum"]["sortable"] = True self.grid.colum_trans["completionRate"] = fooRate self.grid.colum_trans["name"] = fooName self.grid.fields["userid"]["hide"] = True self.grid.fields["DeptID"]["hide"] = True def MakeData(self, request, **arg): #添加数据 self.grid.sql = self.grid.sql.replace( "group by u.userid,u.name,u.badgenumber,d.DeptName,d.DeptID", "") UserID_id = request.params.get("userid", '') if UserID_id: self.grid.sql += " and u.userid in (%s)" % UserID_id deptids = GetAuthoIDs(request.user, 1) defaultdeptid = request.params.get("DeptID", '') if defaultdeptid: self.grid.sql += " and d.DeptID in (%s)" % defaultdeptid elif deptids: self.grid.sql += " and d.DeptID in (%s)" % deptids badgenumber = request.params.get("badgenumber", '') if badgenumber: self.grid.sql += " and u.badgenumber like ('%%%%%s%%%%')" % badgenumber startDate = request.params.get("startDate", '') endDate = request.params.get("endDate", '') if startDate: startDate = datetime.datetime.strptime(startDate, '%Y-%m-%d') self.grid.sql += " and ar.attdate >= '%s'" % startDate if endDate: endDate = datetime.datetime.strptime((endDate + " 23:59:59"), '%Y-%m-%d %H:%M:%S') self.grid.sql += " and ar.attdate <= '%s'" % endDate self.grid.sql += " group by u.userid,u.name,u.badgenumber,d.DeptName,d.DeptID" pass
class SumAttReport(GridModel): ''' 出勤汇总 ''' from django.utils.translation import ugettext as _ verbose_name = u'出勤报表' icon_class = "menu_pathing" menu_grup = 'att_report' app_menu = "att" menu_index = 20 visible = True template = 'attResult_report.html' head = [ ('userid', u'userid'), ('DeptID', u'DeptID'), ('name', u'姓名'), ('badgenumber', u'工号'), ('DeptName', u'组织名称'), ('attTimes_sum', u'应到'), ('attDays_sum', u'实到'), ('overtimes_sum', u'加班时间'), ('leaveimes_sum', u'出勤时长'), ('stopWorkTimes_sum', u'应到时长'), ('completionRate', u'出勤率'), ] search_form = [ ('userid', forms.CharField( label=u'人员', widget=MultySelectFieldWidget( attrs={'url': '/page/personnel/EmpSelect/?pure'}))), ('DeptID', forms.CharField( label=u'组织', widget=MultySelectFieldWidget( attrs={'url': '/page/personnel/DeptSelect/?pure'}))), ('badgenumber', forms.CharField(label=u'工号')), ('startDate', forms.DateTimeField( label=u'开始日期', widget=FormatDateTimeFieldWidget(attrs={ 'format': 'yyyy-MM-dd', 'readonly': 'true' }), initial=datetime.datetime.now().strftime('%Y-%m-01'))), ('endDate', forms.DateTimeField( label=u'结束日期', widget=FormatDateTimeFieldWidget(attrs={ 'format': 'yyyy-MM-dd', 'readonly': 'true' }), initial=datetime.datetime.now().strftime('%Y-%m-%d'))), ] option = { "usepager": True, "useRp": True, "rp": 20, "height": 290, 'checkbox': False, "showTableToggleBtn": False, "onToggleCol": False, "buttons": [ { "name": '导出', "bclass": 'export', "onpress": '$do_export$' }, ], } def __init__(self, request): super(SumAttReport, self).__init__() #设置sql from mosys.sql_utils import get_sql self.grid.sql = get_sql("attResult", "SumAttReport") def fooRate(r): """ 出勤率 """ if int(r[5]) == 0: rate = "100%" else: rate = float(r[6]) / float(r[5]) return u"<font color=red>%10.2f</font>" % rate return rate def fooName(r): """ 姓名转化 """ val = r[2] #人员姓名对应sql语句中的第2列,如果sql语句中发生变化,请注意调整该处 val_id = r[0] return '<a href="javascript:showDetail(%s);" title="">%s</a>' % ( val_id, val) #设置 colum 属性 self.grid.fields["name"]["width"] = 100 self.grid.fields["badgenumber"]["width"] = 150 self.grid.fields["DeptName"]["width"] = 100 self.grid.fields["attTimes_sum"]["width"] = 80 self.grid.fields["attDays_sum"]["width"] = 80 self.grid.fields["overtimes_sum"]["width"] = 80 self.grid.fields["leaveimes_sum"]["width"] = 80 self.grid.fields["stopWorkTimes_sum"]["width"] = 80 self.grid.fields["completionRate"]["width"] = 150 self.grid.fields["attTimes_sum"]["sortable"] = True self.grid.fields["attDays_sum"]["sortable"] = True self.grid.colum_trans["completionRate"] = fooRate self.grid.colum_trans["name"] = fooName self.grid.fields["userid"]["hide"] = True self.grid.fields["DeptID"]["hide"] = True def MakeData(self, request, **arg): #添加数据 self.grid.sql = self.grid.sql.replace( "group by u.userid,u.name,u.badgenumber,d.DeptName,d.DeptID", "") UserID_id = request.params.get("userid", '') if UserID_id: self.grid.sql += " and u.userid in (%s)" % UserID_id deptids = GetAuthoIDs(request.user, 1) defaultdeptid = request.params.get("DeptID", '') if defaultdeptid: self.grid.sql += " and d.DeptID in (%s)" % defaultdeptid elif deptids: self.grid.sql += " and d.DeptID in (%s)" % deptids badgenumber = request.params.get("badgenumber", '') if badgenumber: self.grid.sql += " and u.badgenumber like ('%%%%%s%%%%')" % badgenumber startDate = request.params.get("startDate", '') endDate = request.params.get("endDate", '') if startDate: startDate = datetime.datetime.strptime(startDate, '%Y-%m-%d') self.grid.sql += " and ar.attdate >= '%s'" % startDate if endDate: endDate = datetime.datetime.strptime((endDate + " 23:59:59"), '%Y-%m-%d %H:%M:%S') self.grid.sql += " and ar.attdate <= '%s'" % endDate self.grid.sql += " group by u.userid,u.name,u.badgenumber,d.DeptName,d.DeptID" pass
class AreaSelect(GridModel): ''' 项目区域选择 ''' verbose_name = u'项目区域选择' app_menu = "personnel" menu_index = 15 visible = False # template = 'TransInfo_GridModel.html' head = [('id', u'id'), ('areaid', u'区域名称'), ('areaname', u'区域编号')] search_form = [ ('areaid', forms.CharField(label=u'区域名称')), ('areaname', forms.CharField(label=u'区域编号')), ] option = { "usepager": True, # "title": 'Countries', "useRp": True, "rp": 20, "height": 190, 'checkbox': True, "showTableToggleBtn": False, "onToggleCol": False, 'sortorder': "asc", "buttons": [ { "name": '选择', "bclass": 'select', "onpress": '$do_select$' }, ], } def __init__(self, request): super(AreaSelect, self).__init__() #设置sql from mosys.sql_utils import get_sql self.grid.sql = get_sql("sqls", "area_select") #设置 colum 属性 self.grid.fields["id"]["width"] = 10 self.grid.fields["areaid"]["width"] = 120 self.grid.fields["areaname"]["width"] = 120 self.grid.fields["id"]["hide"] = True def MakeData(self, request, **arg): #添加数据 self.ParseLike(request) areaids = GetAuthoIDs(request.user, 2) if areaids: self.grid.sql += " and id in (%s)" % areaids pass