Example #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))
Example #2
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))
Example #3
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))