示例#1
0
 def approval_query(self, stime, etime, userid):
     """自定义审批记录查询,注意此处返回是字典,key为日期"""
     max_query_day = DEFAULT_ATTENDENCE_RULE.get('MAX_QUERY_DAYS')
     s = Schedule()
     ret = {}
     if not stime or not etime or not userid:
         return ret
     days = [day for day in Schedule.iter_diffdays(stime, etime)]
     if len(days) > max_query_day:
         return ret
     try:
         approval_objs = self.filter(originator_userid=userid,
                                     status="COMPLETED",
                                     result='agree')
         for day in days:
             tmp = []
             for approval_obj in approval_objs:
                 stime = approval_obj.start_time.split()[0]
                 etime = approval_obj.end_time.split()[0]
                 if s.check_time_in_range(day, stime, etime):
                     tmp.append(approval_obj)
             ret[day] = tmp
     except ObjectDoesNotExist:
         pass
     return ret
示例#2
0
 def attendence_query(self, stime, etime, jobnumber):
     """自定义考勤查询,由于原始记录不存在未打卡的考勤,在此处补上(蛋疼,需要优化"""
     max_query_day = DEFAULT_ATTENDENCE_RULE.get('MAX_QUERY_DAYS')
     ret = []
     if not stime or not etime or not jobnumber:
         return ret
     days = [day for day in Schedule.iter_diffdays(stime, etime)]
     if len(days) > max_query_day:
         return ret
     try:
         attendence_id = User.objects.get(jobnumber=jobnumber).attendence_id
         ret = [
             recordobj
             for recordobj in self.filter(record_date__in=days,
                                          attendence_id=attendence_id)
         ]
         if len(ret) != len(days):
             result_range = {record.record_date for record in ret}
             for diff in set(days) - result_range:
                 diffobj = AttendenceRecord(attendence_id=attendence_id,
                                            record_date=diff,
                                            clockin_time='',
                                            clockout_time='',
                                            worktime='')
                 ret.append(diffobj)
         ret.sort(key=sort_key)
     except ObjectDoesNotExist:
         pass
     return ret
示例#3
0
 def clean(self):
     max_query_day = DEFAULT_ATTENDENCE_RULE.get('MAX_QUERY_DAYS')
     stime = self.cleaned_data['stime']
     etime = self.cleaned_data['etime']
     if stime and etime:
         days = [day for day in Schedule.iter_diffdays(stime, etime)]
         if len(days) > max_query_day:
             raise forms.ValidationError('最大查询记录需要小于%s天' % max_query_day)
         else:
             return self.cleaned_data
     if not stime and not etime:
         return self.cleaned_data
     raise forms.ValidationError('无效的起止日期')
示例#4
0
 def get_queryset(self):
     ret = []
     stime = self.request.GET.get('stime', None)
     etime = self.request.GET.get('etime', None)
     jobnumber = self.request.GET.dict().get('jobnumber', None)
     try:
         days = [day for day in Schedule.iter_diffdays(stime, etime)]
         userid = User.objects.get(jobnumber=jobnumber).userid
         leave = LeaveInfoFromMysql()
         for day in days:
             ret += leave.query_leave_info(userid, day)
     except Exception:
         pass
     return ret
示例#5
0
 def holiday_query(self, stime, etime):
     days = [day for day in Schedule.iter_diffdays(stime, etime)]
     return self.filter(day__in=days)
示例#6
0
 def get(self, request):
     records = None
     query_form = QueryFrom(request.GET)
     if query_form.is_valid():
         jobnumber = query_form.cleaned_data['jobnumber']
         stime = query_form.cleaned_data['stime']
         etime = query_form.cleaned_data['etime']
         record_dates = self.default_record_dates() if not stime and not etime else [day for day in Schedule.iter_diffdays(stime, etime)]
         records = self.person_query(jobnumber=jobnumber, record_dates=record_dates)
         holidayobjs = {obj.day: obj for obj in Holiday.objects.filter(day__in=record_dates)}
         execfilename = '-'.join([record_dates[0], record_dates[-1], jobnumber])
         return render(request, 'person_query_new.html', locals())
     else:
         errors = query_form.errors
         return render(request, 'person_query_new.html', locals())
示例#7
0
 def default_record_dates(self):
     """默认的查询日期范围"""
     s = Schedule()
     time_now = datetime.date.today().strftime('%Y-%m-%d')
     default_stime, default_etime = s.get_lastweek(time_now)
     return [day for day in Schedule.iter_diffdays(default_stime, default_etime)]