Esempio n. 1
0
def check_object_list(request, template_name='my.html', next='/', check_object_page='1',):
    """
    检查对象查询视图
    """
    page_title = u'查询检查对象'
    if request.method == 'POST':

        post_data = request.POST.copy()
        submit_value = post_data.get(u'submit', False)
        if submit_value == u'查询':
            check_object_search_form = CheckObjectSearchForm(post_data)
            if check_object_search_form.is_valid():
                check_object_search_form.data_to_session(request)
                check_object_search_form.init_from_session(request)
                query_set = check_object_search_form.search()
                results_page = pagination_results(check_object_page, query_set, settings.CHECK_OBJECT_PER_PAGE)
            else:
                results_page = None
            return render_to_response(template_name,
                                      {'search_form': check_object_search_form,
                                       'page_title': page_title,
                                       'results_page': results_page,
                                       },
                                      context_instance=RequestContext(request))
        else:
            if submit_value == u'打印检查对象报表':
                check_object_search_form = CheckObjectSearchForm(post_data)
                if check_object_search_form.is_valid():
                    check_object_search_form.data_to_session(request)
                    check_object_search_form.init_from_session(request)
                    query_set = check_object_search_form.search()
                    return download.down_zipfile(request, check_object_report(query_set, request))
                else:
                    results_page = None
                    return render_to_response(template_name,
                                              {'search_form': check_object_search_form,
                                               'page_title': page_title,
                                               'results_page': results_page,
                                               },
                                              context_instance=RequestContext(request))
            else:
                raise Http404('Invalid Request!')
    else:
        check_object_search_form = CheckObjectSearchForm(CheckObjectSearchForm().data_from_session(request))
        check_object_search_form.init_from_session(request)
        if check_object_search_form.is_valid():
            query_set = check_object_search_form.search()
            results_page = pagination_results(check_object_page, query_set, settings.CHECK_OBJECT_PER_PAGE)
        else:
            results_page = None
        return render_to_response(template_name,
                                  {'search_form': check_object_search_form,
                                   'page_title': page_title,
                                   'results_page': results_page,
                                   },
                                  context_instance=RequestContext(request))
Esempio n. 2
0
def department_list(request, template_name='my.html', next='/', department_page='1',):
    """
    单位部门查询视图
    """
    page_title = u'查询单位部门'
    if request.method == 'POST':
        post_data = request.POST.copy()
        department_search_form = DepartmentSearchForm(post_data)
        if department_search_form.is_valid():

            department_search_form.save_to_session(request)
            if department_search_form.is_null() is False:
                if department_search_form.fuzzy_search() is False:
                    query_set = Department.objects.filter(Q(is_active = True) & 
                                                           Q(name__startswith=department_search_form.cleaned_data['department_name']))
                else:
                    department_search_form.fields['is_fuzzy'].widget.attrs['checked'] = u'true'
                    query_set = Department.objects.filter(Q(is_active = True) &
                                                       Q(name__icontains=department_search_form.cleaned_data['department_name']))
            else:
                query_set = Department.objects.filter(Q(is_active = True))

        else:
            query_set = None
        if query_set is not None:
            results_page = pagination_results(department_page, query_set, settings.DEPARTMENT_PER_PAGE)
        else:
            results_page = None
        return render_to_response(template_name,
                                  {'search_form': department_search_form,
                                   'page_title': page_title,
                                   'results_page': results_page,
                                   },
                                  context_instance=RequestContext(request))
    else:
        data = {'department_name':request.session.get(gl.session_department_name, u''),
                'is_fuzzy':request.session.get(gl.session_department_is_fuzzy, False),
                }        
#       print data['is_fuzzy']

        department_search_form = DepartmentSearchForm(data)
        if department_search_form.is_valid():
            if department_search_form.is_null() is False:
                if department_search_form.fuzzy_search() is False:
                    query_set = Department.objects.filter(Q(is_active = True) & 
                                                           Q(name__startswith=department_search_form.cleaned_data['department_name']))
                else:
#                    print '********'
                    department_search_form.fields['is_fuzzy'].widget.attrs['checked'] = u'true'
                    query_set = Department.objects.filter(Q(is_active = True) &
                                                       Q(name__icontains=department_search_form.cleaned_data['department_name']))
            else:
                query_set = Department.objects.filter(Q(is_active = True))

        else:
            query_set = Department.objects.filter(Q(is_active = True))
        results_page = pagination_results(department_page, query_set, settings.DEPARTMENT_PER_PAGE)
        return render_to_response(template_name,
                                  {'search_form': department_search_form,
                                   'page_title': page_title,
                                   'results_page': results_page,
                                   },
                                  context_instance=RequestContext(request))
Esempio n. 3
0
def check_object_modify(request, template_name='my.html', next_template_name='my.html', check_object_page='1',):
    """
    检查对象修改视图
    """
    page_title = u'编辑检查对象'
    user = get_user(request)
    if request.method == 'POST':
        post_data = request.POST.copy()
        submit_value = post_data.get(u'submit', False)
        if submit_value == u'编辑':
            check_object_modify_form = CheckObjectModifyForm(post_data)
            if check_object_modify_form.is_valid():
                check_object_modify_object = check_object_modify_form.object()
#                print check_object_modify_object.id_number
                check_object_data = CheckObjectDetailModifyForm().data_from_object(check_object_modify_object, user)
                request.session[gl.session_check_object_detail_modify_id_number] = check_object_data[u'id_number']
                request.session[gl.session_check_object_detail_modify_uploader] = ""
                check_object_detail_modify_form = CheckObjectDetailModifyForm(check_object_data)
                if check_object_detail_modify_form.is_valid():
                    check_object_detail_modify_form.init_from_object(check_object_modify_object, user)
                    page_title = u'修改检查对象'
                    return render_to_response(next_template_name,
                                              {'detail_modify_form': check_object_detail_modify_form,
                                               'check_object': check_object_modify_object,
                                               'page_title': page_title,
                                               },
                                              context_instance=RequestContext(request))
                else:
                    check_object_detail_modify_form.init_from_object(check_object_modify_object, user)
                    page_title = u'修改检查对象'
                    return render_to_response(next_template_name,
                                              {'detail_modify_form': check_object_detail_modify_form,
                                               'check_object': check_object_modify_object,
                                               'page_title': page_title,
                                               },
                                              context_instance=RequestContext(request))
            else:
                pass
            check_object_search_form = CheckObjectSearchForm(CheckObjectSearchForm().data_from_session(request))
            check_object_search_form.init_from_session(request)
            if check_object_search_form.is_valid():
                query_set = check_object_search_form.search()
                results_page = pagination_results(check_object_page, query_set, settings.CHECK_OBJECT_PER_PAGE)
            else:
                results_page = None
        else:
            if submit_value == u'查询':
                check_object_search_form = CheckObjectSearchForm(post_data)
                check_object_modify_form = CheckObjectModifyForm()
                if check_object_search_form.is_valid():
                    check_object_search_form.data_to_session(request)
                    check_object_search_form.init_from_session(request)
                    query_set = check_object_search_form.search()
                    results_page = pagination_results(check_object_page, query_set, settings.CHECK_OBJECT_PER_PAGE)
                else:
                    results_page = None
            else:
                if submit_value == u'打印检查对象报表':
                    check_object_search_form = CheckObjectSearchForm(post_data)
                    if check_object_search_form.is_valid():
                        check_object_search_form.data_to_session(request)
                        check_object_search_form.init_from_session(request)
                        query_set = check_object_search_form.search()
                        return check_object_report(query_set, request)
                    else:
                        results_page = None
                        return render_to_response(template_name,
                                                  {'search_form': check_object_search_form,
                                                   'page_title': page_title,
                                                   'results_page': results_page,
                                                   },
                                                  context_instance=RequestContext(request))
                else:
                    raise Http404('Invalid Request!')
        return render_to_response(template_name,
                                  {'search_form': check_object_search_form,
                                   'modify_form': check_object_modify_form,
                                   'page_title': page_title,
                                   'results_page':results_page,
                                   },
                                  context_instance=RequestContext(request))
    else:
        check_object_modify_form = CheckObjectModifyForm()
        check_object_search_form = CheckObjectSearchForm(CheckObjectSearchForm().data_from_session(request))
        check_object_search_form.init_from_session(request)
        if check_object_search_form.is_valid():
            query_set = check_object_search_form.search()
            results_page = pagination_results(check_object_page, query_set, settings.CHECK_OBJECT_PER_PAGE)
        else:
            results_page = None
        return render_to_response(template_name,
                                  {'search_form': check_object_search_form,
                                   'modify_form': check_object_modify_form,
                                   'page_title': page_title,
                                   'results_page':results_page,
                                   },
                                  context_instance=RequestContext(request))
Esempio n. 4
0
def check_result_special_add(request, template_name='my.html', next_template_name='my.html', next_error='my.html', check_object_page='1',):
    """
    特殊检查结果添加视图
    """
    user = get_user(request)

    page_title = u'选择检查对象'

    if request.method == 'POST':
        post_data = request.POST.copy()
        submit_value = post_data.get(u'submit', False)
        if submit_value == u'特殊情况检查':
            try:
                check_project = CheckProject.objects.get(is_setup=True, is_active=True)
            except ObjectDoesNotExist:
                check_project = None
            if check_project is not None:
                today = datetime.datetime.now().date()
                if check_project.start_time <= today and today <= check_project.end_time:

                    check_result_special_add_form = CheckResultSpecialAddForm(post_data)
                    if check_result_special_add_form.is_valid():
                        check_result_special_add_object = check_result_special_add_form.object()
#                        print check_result_special_add_object
#                        print check_result_special_add_object.id_number
                        check_result_special_detail_add_form = CheckResultSpecialDetailAddForm()
                        check_result_special_detail_add_form.init_value(user, check_result_special_add_object)
                        page_title = u'添加特殊情况检查结果'
                        return render_to_response(next_template_name,
                                                  {'special_detail_add_form': check_result_special_detail_add_form,
                                                   'result': check_result_special_add_object,
                                                   'page_title': page_title,
                                                   },
                                                  context_instance=RequestContext(request))
                    else:
                        raise Http404('Invalid Request!')
                else:
                    page_title = u'检查受限制'
                    return render_to_response(next_error,
                                              {'check_project': check_project,
                                               'page_title': page_title,
                                               },
                                              context_instance=RequestContext(request))
            else:
                page_title = u'检查受限制'
                return render_to_response(next_error,
                                          {'check_project': check_project,
                                           'page_title': page_title,
                                           },
                                          context_instance=RequestContext(request))
        else:
            if submit_value == u'查询':
                check_object_search_form = CheckObjectSearchForm(post_data)
                check_result_special_add_form = CheckResultSpecialAddForm()
                if check_object_search_form.is_valid():
                    check_object_search_form.data_to_session(request)
                    check_object_search_form.init_from_session(request)
                    query_set = check_object_search_form.search()
                    results_page = pagination_results(check_object_page, query_set, settings.CHECK_OBJECT_PER_PAGE)
                else:
                    results_page = None
                return render_to_response(template_name,
                                          {'search_form': check_object_search_form,
                                           'add_form': check_result_special_add_form,
                                           'page_title': page_title,
                                           'results_page':results_page,
                                           },
                                          context_instance=RequestContext(request))

            else:
                if submit_value == u'打印检查对象报表':
                    check_object_search_form = CheckObjectSearchForm(post_data)
                    if check_object_search_form.is_valid():
                        check_object_search_form.data_to_session(request)
                        check_object_search_form.init_from_session(request)
                        query_set = check_object_search_form.search()
                        return check_object_report(query_set, request)
                    else:
                        results_page = None
                        return render_to_response(template_name,
                                                  {'search_form': check_object_search_form,
                                                   'page_title': page_title,
                                                   'results_page': results_page,
                                                   },
                                                  context_instance=RequestContext(request))
                else:
                    raise Http404('Invalid Request!')
    else:
        check_result_special_add_form = CheckResultSpecialAddForm()
        check_object_search_form = CheckObjectSearchForm(CheckObjectSearchForm().data_from_session(request))
        check_object_search_form.init_from_session(request)
        if check_object_search_form.is_valid():
            query_set = check_object_search_form.search()
            results_page = pagination_results(check_object_page, query_set, settings.CHECK_OBJECT_PER_PAGE)
        else:
            results_page = None
        return render_to_response(template_name,
                                  {'search_form': check_object_search_form,
                                   'add_form': check_result_special_add_form,
                                   'page_title': page_title,
                                   'results_page':results_page,
                                   },
                                  context_instance=RequestContext(request))
Esempio n. 5
0
def department_add(request, template_name='my.html', next='/', department_page='1'):
    """
    单位部门添加视图,带添加预览功能!
    """
    page_title = u'添加单位部门'
    user = get_user(request)

    if request.method == 'POST':
        post_data = request.POST.copy()
        submit_value = post_data.get(u'submit', False)
        if submit_value == u'添加':
            department_add_form = DepartmentAddForm(post_data)
            if department_add_form.is_valid():
                department_add_form.department_add(user)
            else:
                pass
            data = {'department_name':request.session.get(gl.session_department_name, u''),
                    'is_fuzzy':request.session.get(gl.session_department_is_fuzzy, False),
                    }
#            print data['department_name']
#            print data['is_fuzzy']
            department_search_form = DepartmentSearchForm(data)
            if department_search_form.is_valid():
                if department_search_form.is_null() is False:
                    if department_search_form.fuzzy_search() is False:
                        query_set = Department.objects.filter(Q(is_active = True) & 
                                                               Q(name__startswith=department_search_form.cleaned_data['department_name']))
                    else:
                        department_search_form.fields['is_fuzzy'].widget.attrs['checked'] = u'true'
                        query_set = Department.objects.filter(Q(is_active = True) &
                                                               Q(name__icontains=department_search_form.cleaned_data['department_name']))
                else:
                    query_set = Department.objects.filter(Q(is_active = True))
            else:
                raise Http404('search form error!')
        else:
            department_add_form = DepartmentAddForm()
            if submit_value == u'查询':
                department_search_form = DepartmentSearchForm(post_data)
                if department_search_form.is_valid():
                    department_search_form.save_to_session(request)
                    if department_search_form.is_null() is False:
                        if department_search_form.fuzzy_search() is False:
                            query_set = Department.objects.filter(Q(is_active = True) & 
                                                                   Q(name__startswith=department_search_form.cleaned_data['department_name']))
                        else:
                            department_search_form.fields['is_fuzzy'].widget.attrs['checked'] = u'true'
                            query_set = Department.objects.filter(Q(is_active = True) &
                                                       Q(name__icontains=department_search_form.cleaned_data['department_name']))
                    else:
                        query_set = Department.objects.filter(Q(is_active = True))

                else:
#                    query_set = Department.objects.filter(Q(is_active = True))
                    query_set = None
            else:
                raise Http404('search form error!')
        if query_set is not None:
            results_page = pagination_results(department_page, query_set, settings.DEPARTMENT_PER_PAGE)
        else:
            results_page = None
        return render_to_response(template_name,
                                  {'search_form': department_search_form,
                                   'add_form': department_add_form,
                                   'page_title': page_title,
                                   'results_page':results_page,
                                   },
                                  context_instance=RequestContext(request))
    else:
        department_add_form = DepartmentAddForm()
        data = {'department_name':request.session.get(gl.session_department_name, u''),
                'is_fuzzy':request.session.get(gl.session_department_is_fuzzy, False),
                }
        department_search_form = DepartmentSearchForm(data)
        if department_search_form.is_valid():
            if department_search_form.is_null() is False:
                if department_search_form.fuzzy_search() is False:
                    query_set = Department.objects.filter(Q(is_active = True) & 
                                                           Q(name__startswith=department_search_form.cleaned_data['department_name']))
                else:
                    department_search_form.fields['is_fuzzy'].widget.attrs['checked'] = u'true'
                    query_set = Department.objects.filter(Q(is_active = True) &
                                                       Q(name__icontains=department_search_form.cleaned_data['department_name']))
            else:
                query_set = Department.objects.filter(Q(is_active = True))

        else:
            query_set = Department.objects.filter(Q(is_active = True))
        results_page = pagination_results(department_page, query_set, settings.DEPARTMENT_PER_PAGE)

        return render_to_response(template_name,
                                  {'search_form': department_search_form,
                                   'add_form': department_add_form,
                                   'page_title': page_title,
                                   'results_page':results_page,
                                   },
                                  context_instance=RequestContext(request))
Esempio n. 6
0
def check_result_list(request, template_name='my.html', next='/', check_result_page='1',):
    """
    检查结果查询视图
    """
    page_title = u'查询检查结果'

    if request.method == 'POST':
        post_data = request.POST.copy()
        submit_value = post_data.get(u'submit', False)
        if submit_value == u'查询':
            check_result_search_form = CheckResultSearchForm(post_data)
            check_result_search_form.init_check_project()
            if check_result_search_form.is_valid():
                check_result_search_form.data_to_session(request)
                check_result_search_form.init_from_session(request)
                query_set = check_result_search_form.search()
                results_page = pagination_results(check_result_page, query_set, settings.CHECK_RESULT_PER_PAGE)
            else:
                results_page = None
            return render_to_response(template_name,
                                      {'search_form': check_result_search_form,
                                       'page_title': page_title,
                                       'results_page': results_page,
                                       },
                                      context_instance=RequestContext(request))
        else:
            if submit_value == u'打印检查结果报表':
                check_result_search_form = CheckResultSearchForm(post_data)
                check_result_search_form.init_check_project()
                if check_result_search_form.is_valid():
                    check_result_search_form.data_to_session(request)
                    check_result_search_form.init_from_session(request)
                    query_set = check_result_search_form.search()
                    filename = check_result_report(query_set, request)
                    #filename = '/home/bright/nanopb-0.3.1-linux-x86.tar.gz'
                    #print __file__
                    #wrapper = FileWrapper(file(filename))
                    #response = HttpResponse(wrapper, content_type='text/plain')
                    #response['Content-Length'] = os.path.getsize(filename)
                    #
                    return download.down_zipfile(request, filename)
                else:
                    results_page = None
                    return render_to_response(template_name,
                                              {'search_form': check_result_search_form,
                                               'page_title': page_title,
                                               'results_page': results_page,
                                               },
                                              context_instance=RequestContext(request))
    else:
        check_result_search_form = CheckResultSearchForm(CheckResultSearchForm().data_from_session(request))
        check_result_search_form.init_check_project()
        check_result_search_form.init_from_session(request)
        if check_result_search_form.is_valid():
            query_set = check_result_search_form.search()
            results_page = pagination_results(check_result_page, query_set, settings.CHECK_RESULT_PER_PAGE)
        else:
            results_page = None
        return render_to_response(template_name,
                                  {'search_form': check_result_search_form,
                                   'page_title': page_title,
                                   'results_page': results_page,
                                   },
                                  context_instance=RequestContext(request))
Esempio n. 7
0
def service_area_department_list(request, template_name='my.html', next='/', service_area_department_page='1', service_area_index='1',):
    """
    服务区域单位部门列表视图,带添加预览功能!
    """
    page_title = u'显示关联单位部门列表'

    try:
        service_area = ServiceArea.objects.get(is_active=True, pk=int(service_area_index))
    except:
        raise Http404('search form error!')

    department_query_set = Department.objects.filter(is_active=True)

    if request.method == 'POST':
        post_data = request.POST.copy()
        submit_value = post_data.get(u'submit', False)
        service_area_department_search_form = ServiceAreaDepartmentSearchForm(post_data)
        if service_area_department_search_form.is_valid():
            service_area_department_search_form.save_to_session(request)
            query_set_temp = department_query_set.filter(department_to_service_area__service_area__pk=service_area.pk,
                                                         department_to_service_area__is_active=True)
            if service_area_department_search_form.is_null() is False:
                if service_area_department_search_form.fuzzy_search() is False:
                    query_set = query_set_temp.filter(name__startswith=service_area_department_search_form.cleaned_data['service_area_department_name'])
                else:
                    service_area_department_search_form.fields['is_fuzzy'].widget.attrs['checked'] = u'true'
                    query_set = query_set_temp.filter(name__icontains=service_area_department_search_form.cleaned_data['service_area_department_name'])
            else:
                query_set = query_set_temp
                
        else:
#                    query_set = Service_Area_Department.objects.filter(Q(is_active = True))
            query_set = None
        if query_set is not None:
            results_page = pagination_results(service_area_department_page, query_set, settings.SERVICE_AREA_DEPARTMENT_PER_PAGE)
        else:
            results_page = None
        return render_to_response(template_name,
                                  {'search_form': service_area_department_search_form,
                                   'page_title': page_title,
                                   'results_page':results_page,
                                   'service_area_index':service_area_index,
                                   'service_area_name':service_area.name,
                                   },
                                  context_instance=RequestContext(request))
    else:
        data = {'service_area_department_name':request.session.get(gl.session_service_area_department_name, u''),
                'is_fuzzy':request.session.get(gl.session_service_area_department_is_fuzzy, False),
                }
        service_area_department_search_form = ServiceAreaDepartmentSearchForm(data)
        if service_area_department_search_form.is_valid():
            query_set_temp = department_query_set.filter(department_to_service_area__service_area__pk=service_area.pk,
                                                         department_to_service_area__is_active=True)
            if service_area_department_search_form.is_null() is False:
                if service_area_department_search_form.fuzzy_search() is False:
                    query_set = query_set_temp.filter(name__startswith=service_area_department_search_form.cleaned_data['service_area_department_name'])
                else:
                    service_area_department_search_form.fields['is_fuzzy'].widget.attrs['checked'] = u'true'
                    query_set = query_set_temp.filter(name__icontains=service_area_department_search_form.cleaned_data['service_area_department_name'])
            else:
                query_set = query_set_temp

        else:
            query_set = None

        if query_set is not None:
            results_page = pagination_results(service_area_department_page, query_set, settings.SERVICE_AREA_DEPARTMENT_PER_PAGE)
        else:
            results_page = None
        return render_to_response(template_name,
                                  {'search_form': service_area_department_search_form,
                                   'page_title': page_title,
                                   'results_page':results_page,
                                   'service_area_index':service_area_index,
                                   'service_area_name':service_area.name,
                                   },
                                  context_instance=RequestContext(request))
Esempio n. 8
0
def service_area_department_add(request, template_name='my.html', next='/', service_area_department_page='1', service_area_index='1',):
    """
    服务区域单位部门添加视图,带添加预览功能!
    """
    page_title = u'关联单位部门'
    user = get_user(request)

    try:
        service_area = ServiceArea.objects.get(is_active=True, pk=int(service_area_index))
        service_area_department = ServiceAreaDepartment.objects.all()
    except:
        raise Http404('search form error!')
    #query_set_not_check_object_in_department = query_set_not_check_object_in_department.exclude(id__in = qs_check_result.filter(check_project=check_project, is_latest=True).values_list('check_object__id', flat=True))

    department_query_set = Department.objects.filter(is_active=True)
    #query_set_choices = department_query_set.exclude(department_to_service_area__service_area__pk=service_area.pk,
    #                                                 department_to_service_area__is_active=True)
    query_set_choices = department_query_set.exclude(id__in = service_area_department.filter(service_area=service_area, is_active=True).values_list('department__id', flat=True))
    choices = ()
    for query in query_set_choices:
#        print str(query.pk), query.name
        choices += (str(query.pk), query.name),

    
    if request.method == 'POST':
        post_data = request.POST.copy()
        submit_value = post_data.get(u'submit', False)
        if submit_value == u'添加关联':
            service_area_department_add_form = ServiceAreaDepartmentAddForm(post_data)
            service_area_department_add_form.fields['service_area_department_name'].choices = choices
            if service_area_department_add_form.is_valid():
                service_area_department_add_form.service_area_department_add(service_area)
                query_set_choices = department_query_set.exclude(department_to_service_area__service_area__pk=service_area.pk,
                                                     department_to_service_area__is_active=True)
                choices = ()
                for query in query_set_choices:
#                    print str(query.pk), query.name
                    choices += (str(query.pk), query.name),
                service_area_department_add_form.fields['service_area_department_name'].choices = choices
            else:
                pass
                                   
            data = {'service_area_department_name':request.session.get(gl.session_service_area_department_name, u''),
                    'is_fuzzy':request.session.get(gl.session_service_area_department_is_fuzzy, False),
                    }

            service_area_department_search_form = ServiceAreaDepartmentSearchForm(data)
            if service_area_department_search_form.is_valid():
                query_set_temp = department_query_set.filter(department_to_service_area__service_area__pk=service_area.pk,
                                                             department_to_service_area__is_active=True)
                if service_area_department_search_form.is_null() is False:
                    if service_area_department_search_form.fuzzy_search() is False:
                        query_set = query_set_temp.filter(name__startswith=service_area_department_search_form.cleaned_data['service_area_department_name'])
                    else:
                        service_area_department_search_form.fields['is_fuzzy'].widget.attrs['checked'] = u'true'
                        query_set = query_set_temp.filter(name__icontains=service_area_department_search_form.cleaned_data['service_area_department_name'])
                else:
                    query_set = query_set_temp
            else:
                raise Http404('search form error!')
        else:
            service_area_department_add_form = ServiceAreaDepartmentAddForm()
            service_area_department_add_form.fields['service_area_department_name'].choices = choices
            if submit_value == u'查询':
                service_area_department_search_form = ServiceAreaDepartmentSearchForm(post_data)
                if service_area_department_search_form.is_valid():
                    service_area_department_search_form.save_to_session(request)
                    query_set_temp = department_query_set.filter(department_to_service_area__service_area__pk=service_area.pk,
                                                                 department_to_service_area__is_active=True)
                    if service_area_department_search_form.is_null() is False:
                        if service_area_department_search_form.fuzzy_search() is False:
                            query_set = query_set_temp.filter(name__startswith=service_area_department_search_form.cleaned_data['service_area_department_name'])
                        else:
                            service_area_department_search_form.fields['is_fuzzy'].widget.attrs['checked'] = u'true'
                            query_set = query_set_temp.filter(name__icontains=service_area_department_search_form.cleaned_data['service_area_department_name'])
                    else:
                        query_set = query_set_temp

                else:
#                    query_set = Service_Area_Department.objects.filter(Q(is_active = True))
                    query_set = None
            else:
                raise Http404('search form error!')
        if query_set is not None:
            results_page = pagination_results(service_area_department_page, query_set, settings.SERVICE_AREA_DEPARTMENT_PER_PAGE)
        else:
            results_page = None
        return render_to_response(template_name,
                                  {'search_form': service_area_department_search_form,
                                   'add_form': service_area_department_add_form,
                                   'page_title': page_title,
                                   'results_page':results_page,
                                   'service_area_index':service_area_index,
                                   'service_area_name':service_area.name,
                                   },
                                  context_instance=RequestContext(request))
    else:
        service_area_department_add_form = ServiceAreaDepartmentAddForm()
        service_area_department_add_form.fields['service_area_department_name'].choices = choices
        data = {'service_area_department_name':request.session.get(gl.session_service_area_department_name, u''),
                'is_fuzzy':request.session.get(gl.session_service_area_department_is_fuzzy, False),
                }
        service_area_department_search_form = ServiceAreaDepartmentSearchForm(data)
        if service_area_department_search_form.is_valid():
            query_set_temp = department_query_set.filter(department_to_service_area__service_area__pk=service_area.pk,
                                                         department_to_service_area__is_active=True)
            if service_area_department_search_form.is_null() is False:
                if service_area_department_search_form.fuzzy_search() is False:
                    query_set = query_set_temp.filter(name__startswith=service_area_department_search_form.cleaned_data['service_area_department_name'])
                else:
                    service_area_department_search_form.fields['is_fuzzy'].widget.attrs['checked'] = u'true'
                    query_set = query_set_temp.filter(name__icontains=service_area_department_search_form.cleaned_data['service_area_department_name'])
            else:
                query_set = query_set_temp

        else:
            query_set = None

        if query_set is not None:
            results_page = pagination_results(service_area_department_page, query_set, settings.SERVICE_AREA_DEPARTMENT_PER_PAGE)
        else:
            results_page = None
        return render_to_response(template_name,
                                  {'search_form': service_area_department_search_form,
                                   'add_form': service_area_department_add_form,
                                   'page_title': page_title,
                                   'results_page':results_page,
                                   'service_area_index':service_area_index,
                                   'service_area_name':service_area.name,
                                   },
                                  context_instance=RequestContext(request))
Esempio n. 9
0
def service_area_list(request, template_name='my.html', next='/', service_area_page='1',):
    """
    服务区域查询视图
    """
    page_title = u'查询服务区域'

    if request.method == 'POST':
        post_data = request.POST.copy()
        service_area_search_form = ServiceAreaSearchForm(post_data)
        if service_area_search_form.is_valid():
            service_area_search_form.save_to_session(request)
            if service_area_search_form.is_null() is False:
                if service_area_search_form.fuzzy_search() is False:
                    query_set = ServiceArea.objects.filter(Q(is_active = True) & 
                                                           Q(name__startswith=service_area_search_form.cleaned_data['service_area_name']))
                else:
                    service_area_search_form.fields['is_fuzzy'].widget.attrs['checked'] = u'true'
                    query_set = ServiceArea.objects.filter(Q(is_active = True) &
                                                       Q(name__icontains=service_area_search_form.cleaned_data['service_area_name']))
            else:
                query_set = ServiceArea.objects.filter(Q(is_active = True))

        else:
            query_set = None
        if query_set is not None:
            results_page = pagination_results(service_area_page, query_set, settings.SERVICE_AREA_PER_PAGE)
        else:
            results_page = None
        return render_to_response(template_name,
                                  {'search_form': service_area_search_form,
                                   'page_title': page_title,
                                   'results_page': results_page,
                                   },
                                  context_instance=RequestContext(request))
    else:
        data = {'service_area_name':request.session.get(gl.session_service_area_name, u''),
                'is_fuzzy':request.session.get(gl.session_service_area_is_fuzzy, False),
                }        
#       print data['is_fuzzy']

        service_area_search_form = ServiceAreaSearchForm(data)
        if service_area_search_form.is_valid():
            if service_area_search_form.is_null() is False:
                if service_area_search_form.fuzzy_search() is False:
                    query_set = ServiceArea.objects.filter(Q(is_active = True) & 
                                                           Q(name__startswith=service_area_search_form.cleaned_data['service_area_name']))
                else:
#                    print '********'
                    service_area_search_form.fields['is_fuzzy'].widget.attrs['checked'] = u'true'
                    query_set = ServiceArea.objects.filter(Q(is_active = True) &
                                                       Q(name__icontains=service_area_search_form.cleaned_data['service_area_name']))
            else:
                query_set = ServiceArea.objects.filter(Q(is_active = True))

        else:
            query_set = ServiceArea.objects.filter(Q(is_active = True))
        results_page = pagination_results(service_area_page, query_set, settings.SERVICE_AREA_PER_PAGE)
        return render_to_response(template_name,
                                  {'search_form': service_area_search_form,
                                   'page_title': page_title,
                                   'results_page': results_page,
                                   },
                                  context_instance=RequestContext(request))
Esempio n. 10
0
def check_project_delete(request, template_name='my.html', next='/', check_project_page='1',):
    """
    检查项目删除视图
    """
    page_title = u'删除检查项目'

    if request.method == 'POST':
        post_data = request.POST.copy()
        submit_value = post_data.get(u'submit', False)
        if submit_value == u'删除':
            check_project_delete_form = CheckProjectDeleteForm(post_data)
            if check_project_delete_form.is_valid():
                check_project_delete_form.check_project_delete()
            else:
                pass
            data = {'check_project_name':request.session.get(gl.session_check_project_name, u''),
                    'is_fuzzy':request.session.get(gl.session_check_project_is_fuzzy, False),
                    }        
            check_project_search_form = CheckProjectSearchForm(data)
            if check_project_search_form.is_valid():
                if check_project_search_form.is_null() is False:
                    if check_project_search_form.fuzzy_search() is False:
                        query_set = CheckProject.objects.filter(Q(is_active = True) & 
                                                               Q(name__startswith=check_project_search_form.cleaned_data['check_project_name']))
                    else:
                        check_project_search_form.fields['is_fuzzy'].widget.attrs['checked'] = u'true'
                        query_set = CheckProject.objects.filter(Q(is_active = True) &
                                                               Q(name__icontains=check_project_search_form.cleaned_data['check_project_name']))
                else:
                    query_set = CheckProject.objects.filter(Q(is_active = True))
            else:
                raise Http404('search form error!')
        else:
            check_project_delete_form = CheckProjectDeleteForm()
            if submit_value == u'查询':
                check_project_search_form = CheckProjectSearchForm(post_data)
                if check_project_search_form.is_valid():
                    check_project_search_form.save_to_session(request)
                    if check_project_search_form.is_null() is False:
                        if check_project_search_form.fuzzy_search() is False:
                            query_set = CheckProject.objects.filter(Q(is_active = True) & 
                                                                   Q(name__startswith=check_project_search_form.cleaned_data['check_project_name']))
                        else:
                            check_project_search_form.fields['is_fuzzy'].widget.attrs['checked'] = u'true'
                            query_set = CheckProject.objects.filter(Q(is_active = True) &
                                                       Q(name__icontains=check_project_search_form.cleaned_data['check_project_name']))
                    else:
                        query_set = CheckProject.objects.filter(Q(is_active = True))

                else:
                    query_set = None
            else:
                raise Http404('search form error!')
        if query_set is not None:
            results_page = pagination_results(check_project_page, query_set, settings.CHECK_PROJECT_PER_PAGE)
        else:
            results_page = None
        return render_to_response(template_name,
                                  {'search_form': check_project_search_form,
                                   'delete_form': check_project_delete_form,
                                   'page_title': page_title,
                                   'results_page':results_page,
                                   },
                                  context_instance=RequestContext(request))
    else:
        check_project_delete_form = CheckProjectDeleteForm()
        data = {'check_project_name':request.session.get(gl.session_check_project_name, u''),
                'is_fuzzy':request.session.get(gl.session_check_project_is_fuzzy, False),
                }        
        check_project_search_form = CheckProjectSearchForm(data)
        if check_project_search_form.is_valid():
            if check_project_search_form.is_null() is False:
                if check_project_search_form.fuzzy_search() is False:
                    query_set = CheckProject.objects.filter(Q(is_active = True) & 
                                                           Q(name__startswith=check_project_search_form.cleaned_data['check_project_name']))
                else:
                    check_project_search_form.fields['is_fuzzy'].widget.attrs['checked'] = u'true'
                    query_set = CheckProject.objects.filter(Q(is_active = True) &
                                                       Q(name__icontains=check_project_search_form.cleaned_data['check_project_name']))
            else:
                query_set = CheckProject.objects.filter(Q(is_active = True))

        else:
            query_set = CheckProject.objects.filter(Q(is_active = True))
        results_page = pagination_results(check_project_page, query_set, settings.CHECK_PROJECT_PER_PAGE)

        return render_to_response(template_name,
                                  {'search_form': check_project_search_form,
                                   'delete_form': check_project_delete_form,
                                   'page_title': page_title,
                                   'results_page':results_page,
                                   },
                                  context_instance=RequestContext(request))