Esempio n. 1
0
def ajax_get_weeklys(request):
    user = request.user
    result = {}
    
    today = datetime.date.today()
    #本周一
    monday = today - datetime.timedelta(today.weekday())
    #本周五
    friday = today + datetime.timedelta(4 - today.weekday())
    
    departments = get_department_list_by_user(user)
    result['department'] = [d.name for d in departments]
        
    department_name = request.POST.get('department_name','')
    start_time = request.POST.get('start_time','')
    end_time = request.POST.get('end_time','')
    
    weekly_list = []
    if departments:
        if department_name:
            department = _report.get_department_by_params(name=department_name)
        else:
            department = departments[0]
    
        weeklys = _report.get_weeklys_by_params(department=department).order_by('-id')
        if start_time:
            start_time = datetime.datetime.strptime(start_time,'%Y-%m-%d')
            weeklys = weeklys.filter(start_time__gte=start_time)
        else:
            weeklys = weeklys.filter(start_time__gte=monday)
        if end_time:
            end_time = datetime.datetime.strptime(end_time,'%Y-%m-%d')
            weeklys = weeklys.filter(end_time__lte=end_time)
        else:
            weeklys = weeklys.filter(end_time__lte=friday)
        for weekly in weeklys:
            editable = False
            if user == weekly.user:
                editable = True
            id = weekly.id
            author = weekly.user.username
            time = datetime.datetime.strftime(weekly.updated,'%Y-%m-%d')
            
            weekly_progress_list = _report.get_weeklyProgresss_by_params(weekly=weekly)
            weekly_plan_list = _report.get_weeklyPlans_by_params(weekly=weekly)
            progress_list = [progress.content for progress in weekly_progress_list]
            plan_list = [plan.content for plan in weekly_plan_list]
            weekly_list.append({'id':id, 'progress':progress_list, 'plan':plan_list, 'author': author, 'time':time, 'editable':editable})
    
    result['list'] = weekly_list
    
    result['start_time'] = datetime.datetime.strftime(monday,'%Y-%m-%d')
    result['end_time'] = datetime.datetime.strftime(friday,'%Y-%m-%d')
    
    return HttpResponse(json.dumps(result), content_type="application/json")
Esempio n. 2
0
def ajax_edit_monthly(request):
    user = request.user
    sdicts = {'result': 0}

    today = datetime.date.today()

    monthly_id = request.POST.get("id", '')
    department_name = request.POST.get("department_name", '')

    info_list = request.POST.get('info_list', '')

    department = _report.get_department_by_params(name=department_name)
    if department:
        try:
            #修改
            if monthly_id:
                monthly = _report.get_monthly_by_params(id=int(monthly_id))

            #新建
            else:
                monthly = _report.get_or_create_monthly_by_params(
                    department=department,
                    user=user,
                    time=datetime.datetime(today.year, today.month, 1))[0]
            monthly.save()

            monthly_info_list = _report.get_monthlyInfos_by_params(
                monthly=monthly)
            for m_info in monthly_info_list:
                m_info.delete()

            if info_list:
                info_list = json.loads(info_list)
                for info in info_list:
                    product_name = info.get('product')
                    product = _report.get_product_by_params(name=product_name)

                    monthly_info = _report.create_monthlyInfo_by_params(
                        monthly=monthly, product=product)
                    monthly_info.hard_num = info.get('hardware')
                    monthly_info.soft_num = info.get('software')
                    monthly_info.human_num = info.get('human')
                    monthly_info.safe_num = info.get('safe')
                    monthly_info.service_num = info.get('serviceNum')
                    monthly_info.service_time = info.get('serviceTime')
                    monthly_info.server_num = info.get('area')
                    monthly_info.space_percent = info.get('contain')
                    monthly_info.machine_num = info.get('machine')

                    monthly_info.save()

            sdicts["result"] = 1
        except Exception, e:
            print e
Esempio n. 3
0
def ajax_edit_weekly(request):
    user = request.user
    sdicts = {'result': 0}
    weekly_id = request.POST.get("id", '')
    department_name = request.POST.get("department_name", '')
    start_time = request.POST.get("start_time")
    end_time = request.POST.get("end_time")
    progress_list = request.POST.getlist("progress_list[]", [])
    plan_list = request.POST.getlist("plan_list[]", [])

    department = _report.get_department_by_params(name=department_name)
    if department:
        try:
            #修改
            if weekly_id:
                weekly = _report.get_weekly_by_params(id=int(weekly_id))

                weekly_progress_list = _report.get_weeklyProgresss_by_params(
                    weekly=weekly)
                weekly_plan_list = _report.get_weeklyPlans_by_params(
                    weekly=weekly)
                for w_progress in weekly_progress_list:
                    w_progress.delete()
                for w_plan in weekly_plan_list:
                    w_plan.delete()

            #新建
            else:
                weekly = _report.create_weekly_by_params(department=department,
                                                         user=user)

            weekly.start_time = datetime.datetime.strptime(
                start_time, '%Y-%m-%d')
            weekly.end_time = datetime.datetime.strptime(end_time, '%Y-%m-%d')
            weekly.save()

            for progress in progress_list:
                weekly_progress = _report.create_weeklyProgress_by_params(
                    weekly=weekly)
                weekly_progress.content = progress
                weekly_progress.save()

            for plan in plan_list:
                weekly_plan = _report.create_weeklyPlan_by_params(
                    weekly=weekly)
                weekly_plan.content = plan
                weekly_plan.save()

            sdicts["result"] = 1
        except Exception, e:
            print e
Esempio n. 4
0
def ajax_edit_monthly(request):
    user = request.user
    sdicts = {'result':0}
    
    today = datetime.date.today()
    
    monthly_id = request.POST.get("id",'')
    department_name = request.POST.get("department_name",'')

    info_list = request.POST.get('info_list','')
        
    department = _report.get_department_by_params(name=department_name)
    if department:
        try:
            #修改
            if monthly_id:
                monthly = _report.get_monthly_by_params(id=int(monthly_id))
                
            #新建    
            else:
                monthly = _report.get_or_create_monthly_by_params(department=department,user=user,time = datetime.datetime(today.year,today.month,1))[0]
            monthly.save()
            
            monthly_info_list =  _report.get_monthlyInfos_by_params(monthly=monthly)
            for m_info in monthly_info_list:
                m_info.delete()
            
            if info_list:
                info_list = json.loads(info_list)
                for info in info_list:
                    product_name = info.get('product')
                    product = _report.get_product_by_params(name=product_name)
                    
                    monthly_info =  _report.create_monthlyInfo_by_params(monthly=monthly,product=product)
                    monthly_info.hard_num = info.get('hardware')
                    monthly_info.soft_num = info.get('software')
                    monthly_info.human_num = info.get('human')
                    monthly_info.safe_num = info.get('safe')
                    monthly_info.service_num = info.get('serviceNum')
                    monthly_info.service_time = info.get('serviceTime')
                    monthly_info.server_num = info.get('area')
                    monthly_info.space_percent = info.get('contain')
                    monthly_info.machine_num = info.get('machine')
                    
                    monthly_info.save()
            
            sdicts["result"] = 1
        except Exception,e:
            print e
Esempio n. 5
0
def ajax_edit_department(request):
    user = request.user
    sdicts = {'result':0}
    department_name = request.POST.get("department_name",'')
    content = request.POST.get("content",'')
    department = _report.get_department_by_params(name=department_name)
    if department:
        try:
            rule,create = _report.get_or_create_rule_by_params(department=department)
            if create:
                rule.create_user = user
            rule.update_user = user
            rule.content = content
            rule.save()
            sdicts["result"] = 1
        except Exception,e:
            print e
Esempio n. 6
0
def ajax_edit_weekly(request):
    user = request.user
    sdicts = {'result':0}
    weekly_id = request.POST.get("id",'')
    department_name = request.POST.get("department_name",'')
    start_time = request.POST.get("start_time")
    end_time = request.POST.get("end_time")
    progress_list = request.POST.getlist("progress_list[]",[])
    plan_list = request.POST.getlist("plan_list[]",[])
    
    department = _report.get_department_by_params(name=department_name)
    if department:
        try:
            #修改
            if weekly_id:
                weekly = _report.get_weekly_by_params(id=int(weekly_id))
                
                weekly_progress_list =  _report.get_weeklyProgresss_by_params(weekly=weekly)
                weekly_plan_list =  _report.get_weeklyPlans_by_params(weekly=weekly)
                for w_progress in weekly_progress_list:
                    w_progress.delete()
                for w_plan in weekly_plan_list:
                    w_plan.delete()
                
            #新建    
            else:
                weekly = _report.create_weekly_by_params(department=department,user=user)
                
            weekly.start_time = datetime.datetime.strptime(start_time,'%Y-%m-%d')
            weekly.end_time = datetime.datetime.strptime(end_time,'%Y-%m-%d')
            weekly.save()
                
            for progress in progress_list:
                weekly_progress =  _report.create_weeklyProgress_by_params(weekly=weekly)
                weekly_progress.content = progress
                weekly_progress.save()
            
            for plan in plan_list:
                weekly_plan =  _report.create_weeklyPlan_by_params(weekly=weekly)
                weekly_plan.content = plan
                weekly_plan.save()
            
            sdicts["result"] = 1
        except Exception,e:
            print e
Esempio n. 7
0
def ajax_edit_department(request):
    user = request.user
    sdicts = {'result': 0}
    department_name = request.POST.get("department_name", '')
    content = request.POST.get("content", '')
    department = _report.get_department_by_params(name=department_name)
    if department:
        try:
            rule, create = _report.get_or_create_rule_by_params(
                department=department)
            if create:
                rule.create_user = user
            rule.update_user = user
            rule.content = content
            rule.save()
            sdicts["result"] = 1
        except Exception, e:
            print e
Esempio n. 8
0
def ajax_get_routines(request):
    user = request.user
    result = {}
    result['user'] = request.user.username
    
    departments = get_department_list_by_user(user)
    result['department'] = [d.name for d in departments]
        
    department_name = request.POST.get('department_name','')
    time_filter = request.POST.get('time_filter','')
    status_filter = request.POST.get('status_filter','')
    length = request.POST.get('length', 10)
    
    routine_list = []
    if departments:
        if department_name:
            department = _report.get_department_by_params(name=department_name)
        else:
            department = departments[0]
    
        routines = _group.get_routines_by_params(department=department).order_by('-id')
        if time_filter:
            date_list = time_filter.split('-')
            year = int(date_list[0])
            month = int(date_list[1])
            day = int(date_list[2])
            routines = routines.filter(updated__year=year,updated__month=month,updated__day=day)
        if status_filter:
            routines = routines.filter(status=status_filter)
        
        for routine in routines:
            id = routine.id
            content = routine.content
            author = routine.update_user.username
            time = datetime.datetime.strftime(routine.updated,'%Y-%m-%d %H:%M')
            status = routine.status
            routine_list.append({'id':id, 'content':content, 'author': author, 'time':time, 'status':status})
    if length:
        routine_list = routine_list[:int(length)]
    
    result['list'] = routine_list
    
    return HttpResponse(json.dumps(result), content_type="application/json")
Esempio n. 9
0
def ajax_get_weeklys(request):
    user = request.user
    result = {}
    
    today = datetime.date.today()
    #本周一
    monday = today - datetime.timedelta(today.weekday())
    #本周日
    sunday = today + datetime.timedelta(6 - today.weekday())
    
    departments = get_department_list_by_user(user)
    result['department'] = [d.name for d in departments]
        
    department_name = request.POST.get('department_name','')
    
    weekly_list = []
    if departments:
        if department_name:
            department = _report.get_department_by_params(name=department_name)
        else:
            department = departments[0]
    
        weeklys = _report.get_weeklys_by_params(department=department,start_time__gte=monday,end_time__lte=sunday)
        for weekly in weeklys:
            author = weekly.user.username
            time = datetime.datetime.strftime(weekly.updated,'%Y-%m-%d')
            
            weekly_progress_list = _report.get_weeklyProgresss_by_params(weekly=weekly)
            weekly_plan_list = _report.get_weeklyPlans_by_params(weekly=weekly)
            progress_list = [progress.content for progress in weekly_progress_list]
            plan_list = [plan.content for plan in weekly_plan_list]
            weekly_list.append({
                                'progress':progress_list, 
                                'plan':plan_list, 
                                'author': author, 
                                'time':time
                                })
    
    result['list'] = weekly_list
    
    return HttpResponse(json.dumps(result), content_type="application/json")
Esempio n. 10
0
def ajax_edit_routine(request):
    user = request.user
    sdicts = {'result':0}
    routine_id = request.POST.get("id",'')
    department_name = request.POST.get("department_name",'')
    content = request.POST.get("content",'')
    status = request.POST.get("status",0)
    
    department = _report.get_department_by_params(name=department_name)
    if department:
        try:
            if routine_id:
                routine = _group.get_routine_by_params(id=int(routine_id))
            else:
                routine = _group.create_routine_by_params(department=department)
                routine.create_user = user
            routine.content = content
            routine.status = status
            routine.update_user = user
            routine.save()
            sdicts["result"] = 1
        except Exception,e:
            print e
Esempio n. 11
0
def ajax_get_weeklys(request):
    user = request.user
    result = {}

    today = datetime.date.today()
    #本周一
    monday = today - datetime.timedelta(today.weekday())
    #本周五
    friday = today + datetime.timedelta(4 - today.weekday())

    departments = get_department_list_by_user(user)
    result['department'] = [d.name for d in departments]

    department_name = request.POST.get('department_name', '')
    start_time = request.POST.get('start_time', '')
    end_time = request.POST.get('end_time', '')

    weekly_list = []
    if departments:
        if department_name:
            department = _report.get_department_by_params(name=department_name)
        else:
            department = departments[0]

        weeklys = _report.get_weeklys_by_params(
            department=department).order_by('-id')
        if start_time:
            start_time = datetime.datetime.strptime(start_time, '%Y-%m-%d')
            weeklys = weeklys.filter(start_time__gte=start_time)
        else:
            weeklys = weeklys.filter(start_time__gte=monday)
        if end_time:
            end_time = datetime.datetime.strptime(end_time, '%Y-%m-%d')
            weeklys = weeklys.filter(end_time__lte=end_time)
        else:
            weeklys = weeklys.filter(end_time__lte=friday)
        for weekly in weeklys:
            editable = False
            if user == weekly.user:
                editable = True
            id = weekly.id
            author = weekly.user.username
            time = datetime.datetime.strftime(weekly.updated, '%Y-%m-%d')

            weekly_progress_list = _report.get_weeklyProgresss_by_params(
                weekly=weekly)
            weekly_plan_list = _report.get_weeklyPlans_by_params(weekly=weekly)
            progress_list = [
                progress.content for progress in weekly_progress_list
            ]
            plan_list = [plan.content for plan in weekly_plan_list]
            weekly_list.append({
                'id': id,
                'progress': progress_list,
                'plan': plan_list,
                'author': author,
                'time': time,
                'editable': editable
            })

    result['list'] = weekly_list

    result['start_time'] = datetime.datetime.strftime(monday, '%Y-%m-%d')
    result['end_time'] = datetime.datetime.strftime(friday, '%Y-%m-%d')

    return HttpResponse(json.dumps(result), content_type="application/json")
Esempio n. 12
0
def ajax_get_monthlys(request):
    user = request.user
    result = {}

    today = datetime.date.today()
    result['time'] = datetime.datetime.strftime(today, '%Y-%m')

    departments = get_department_list_by_user(user)
    result['department'] = [d.name for d in departments]

    cnname = user.first_name
    if user.username in SPECIAL_USERS:
        cnname = SPECIAL_USER_NAME
    product_names = get_product_list_by_user(cnname)
    products = _report.get_products_by_params(name__in=product_names)
    result['product'] = [p.name for p in products]

    department_name = request.POST.get('department_name', '')
    time_filter = request.POST.get('time_filter', '')

    monthly_list = []
    if departments:
        if department_name:
            department = _report.get_department_by_params(name=department_name)
        else:
            department = departments[0]

        monthlys = _report.get_monthlys_by_params(department=department,
                                                  time__year=today.year,
                                                  time__month=today.month)
        if time_filter:
            time_filter_list = time_filter.split('-')
            year = int(time_filter_list[0])
            month = int(time_filter_list[1])
            monthlys = _report.get_monthlys_by_params(department=department,
                                                      time__year=year,
                                                      time__month=month)
        for monthly in monthlys:
            editable = False
            if user == monthly.user:
                editable = True
            id = monthly.id
            author = monthly.user.username
            time = datetime.datetime.strftime(monthly.time, '%Y-%m')

            monthly_info_list = []
            monthly_infos = _report.get_monthlyInfos_by_params(monthly=monthly)
            length = len(monthly_infos)
            for monthly_info in monthly_infos:
                monthly_info_dict = {}

                monthly_info_dict['product'] = monthly_info.product.name
                monthly_info_dict['hardware'] = monthly_info.hard_num
                monthly_info_dict['software'] = monthly_info.soft_num
                monthly_info_dict['human'] = monthly_info.human_num
                monthly_info_dict['safe'] = monthly_info.safe_num
                monthly_info_dict['serviceNum'] = monthly_info.service_num
                monthly_info_dict['serviceTime'] = monthly_info.service_time
                monthly_info_dict['area'] = monthly_info.server_num
                monthly_info_dict['contain'] = monthly_info.space_percent
                monthly_info_dict['machine'] = monthly_info.machine_num

                monthly_info_list.append(monthly_info_dict)

            monthly_list.append({
                'id': id,
                'author': author,
                'time': time,
                'editable': editable,
                'length': length,
                'list': monthly_info_list,
            })

    result['list'] = monthly_list

    return HttpResponse(json.dumps(result), content_type="application/json")
Esempio n. 13
0
def ajax_get_monthlys(request):
    user = request.user
    result = {}
    
    today = datetime.date.today()
    result['time'] = datetime.datetime.strftime(today,'%Y-%m')
    
    departments = get_department_list_by_user(user)
    result['department'] = [d.name for d in departments]
    
    cnname = user.first_name
    if user.username in SPECIAL_USERS:
        cnname = SPECIAL_USER_NAME
    product_names = get_product_list_by_user(cnname)
    products = _report.get_products_by_params(name__in=product_names)
    result['product'] = [p.name for p in products]
        
    department_name = request.POST.get('department_name','')
    time_filter = request.POST.get('time_filter','')
    
    monthly_list = []
    if departments:
        if department_name:
            department = _report.get_department_by_params(name=department_name)
        else:
            department = departments[0]
    
        monthlys = _report.get_monthlys_by_params(department=department, time__year=today.year, time__month=today.month)
        if time_filter:
            time_filter_list = time_filter.split('-')
            year = int(time_filter_list[0])
            month = int(time_filter_list[1])
            monthlys =  _report.get_monthlys_by_params(department=department, time__year=year, time__month=month)
        for monthly in monthlys:
            editable = False
            if user == monthly.user:
                editable = True
            id = monthly.id
            author = monthly.user.username
            time = datetime.datetime.strftime(monthly.time,'%Y-%m')
            
            monthly_info_list = []
            monthly_infos = _report.get_monthlyInfos_by_params(monthly=monthly)
            length = len(monthly_infos)
            for monthly_info in monthly_infos:
                monthly_info_dict = {}
                
                monthly_info_dict['product'] = monthly_info.product.name
                monthly_info_dict['hardware'] = monthly_info.hard_num
                monthly_info_dict['software'] = monthly_info.soft_num
                monthly_info_dict['human'] = monthly_info.human_num
                monthly_info_dict['safe'] = monthly_info.safe_num
                monthly_info_dict['serviceNum'] = monthly_info.service_num
                monthly_info_dict['serviceTime'] = monthly_info.service_time
                monthly_info_dict['area'] = monthly_info.server_num
                monthly_info_dict['contain'] = monthly_info.space_percent
                monthly_info_dict['machine'] = monthly_info.machine_num
                
                monthly_info_list.append(monthly_info_dict)
                
            monthly_list.append({
                                 'id':id, 
                                 'author': author, 
                                 'time':time, 
                                 'editable':editable,
                                 'length':length,
                                 'list':monthly_info_list, 
                                 })
    
    result['list'] = monthly_list

    return HttpResponse(json.dumps(result), content_type="application/json")