Beispiel #1
0
    def save_model(self, request, obj, form, change):
        user = request.user
        from service.core._user import has_tran_perm, has_manage_perm, has_input_perm, get_user_max_perm
        from service.core._user import has_fw_input_perm, has_fh_input_perm, has_fh_audit_perm, has_perm_define

        max_perm = get_user_max_perm(user)
        #        if not has_manage_perm(user) and not has_input_perm(user) and not has_tran_perm(user) and max_perm < obj.status:
        #            return
        if not obj.id:
            pass
        elif has_tran_perm(user):
            pass
        elif obj.is_public or obj.status == enums.PAPER_STATUS_FINISH:
            return
        elif max_perm < obj.status:
            #权限比状态大的能修改问卷
            return
        #其他人都可以修改问卷

        part = request.GET.get('p', 'basic')
        respondent = obj.respondent
        respondent = save_paper_part_data(request, part, respondent, obj)

        #获得期数,经销商
        obj.dealer = respondent.dealer
        obj.term = respondent.term
        obj.survey_code = respondent.survey_code
        obj.visit_begin = respondent.visit_begin
        obj.visit_end = respondent.visit_end
        obj.visitor_num = respondent.visitor_numb
        obj.project = respondent.project

        if not obj.status:
            if has_fw_input_perm(user):
                obj.status = enums.FW_PAPER_STATUS_INIT
                obj.paper_type = enums.FW_PAPER_TYPE
            elif has_fh_input_perm(user):
                obj.status = enums.FH_PAPER_STATUS_INPUT
                obj.paper_type = enums.FH_PAPER_TYPE

        obj.respondent = respondent
        if hasattr(obj, 'user'):
            if obj.user is None:
                obj.user = request.user
        else:
            obj.user = request.user
        obj.save()
        #统计得
        from service.core._report import calculate_paper_total_score
        calculate_paper_total_score(obj)
        obj.save()

        from mc import save_paper_audit_status
        if obj.status == enums.FW_PAPER_STATUS_INIT:
            #记录初始审核记录
            save_paper_audit_status(obj, request.user,
                                    enums.FW_PAPER_STATUS_INIT)
        elif obj.status == enums.FH_PAPER_STATUS_INPUT:
            #记录初始审核记录
            save_paper_audit_status(obj, request.user,
                                    enums.FH_PAPER_STATUS_INPUT)
Beispiel #2
0
def fh_end_audit(modeladmin, request, queryset):
    """
    """
    opts = modeladmin.model._meta
    app_label = opts.app_label
    
    # Populate modifiable_objects, a data structure of all related objects that will also be deleted.
    modifiable_objects, perms_needed = get_deleted_objects(queryset, opts, request.user, modeladmin.admin_site, levels_to_root=2)
    
    can_audit = validate_false_paper_have_type(queryset, [enums.FW_PAPER_TYPE, enums.BMW_PAPER_TYPE])
    if can_audit == False:
        messages.error(request, msg_paper_not_belong_fht)
        return None
    paper_st_right = validate_false_paper_status(request, queryset, [enums.FH_PAPER_STATUS_WAIT_AUDIT_2], u'独立复核团队终审')
    if paper_st_right == False:
        return None
    # The user has already confirmed the deletion.
    # Do the deletion and return a None to display the change list view again.    
    if request.POST.get('post'):
        user = request.user
        # 权限判定
        if not has_fh_end_audit_perm(user) and not has_manage_perm(user):
            raise PermissionDenied
        n = queryset.count()
        passed_papers = []
        if n:
            perm = enums.PAPER_STATUS_FINISH
            for obj in queryset :
                obj_display = force_unicode(obj)
                if obj.status < perm:
                    from mc import save_paper_audit_status
                    save_paper_audit_status(obj, request.user, perm)
                    
                    obj.status = perm
                    obj.save()
                    passed_papers.append(obj)
                    # change
                    modeladmin.log_change(request, obj, obj_display)
                else:
                    n -= 1
            
            modeladmin.message_user(request, u'独立复核终审通过 %(count)d %(items)s 报告.' % {
                "count": n, "items": model_ngettext(modeladmin.opts, n)
            })
            if len(passed_papers) > 0:
                from service.core._report import generate_report_by_paper
                generate_report_by_paper(queryset)
                conflicts_msg = []
                for paper in queryset:
                    no_conflict, diff = paperdiff.do_dealer_paper_diff(paper, user)
#                    if not no_conflict:
#                        conflicts_msg.append(u'%s(FW团队问卷: %s 与 复核团队问卷: %s 比较,产生BMW审核问卷: %s)' % (paper.dealer.name, diff.fw_paper.survey_code, diff.fh_paper.survey_code, diff.final_paper.survey_code))
#                if len(conflicts_msg) > 0:
#                    modeladmin.message_user(request, u'产生问卷差异的经销商及相关问卷信息如下:')
#                    for tmpmsg in conflicts_msg:
#                        modeladmin.message_user(request, tmpmsg)
#                else:
#                    modeladmin.message_user(request, u'并未产生问卷差异.')
        
        # Return None to display the change list page again.
        return None
    
    context = {
        "title": _("Are you sure?"),
        "object_name": force_unicode(opts.verbose_name),
        "modifiable_objects": modifiable_objects,
        'queryset': queryset,
        
        "opts": opts,
        "root_path": modeladmin.admin_site.root_path,
        "app_label": app_label,
        'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME,
    }
    
    # Display the confirmation page
    return render_to_response('fh_finish_audit_confirmation.html', context, context_instance=template.RequestContext(request))
Beispiel #3
0
def fh_end_audit(modeladmin, request, queryset):
    """
    """
    opts = modeladmin.model._meta
    app_label = opts.app_label

    # Populate modifiable_objects, a data structure of all related objects that will also be deleted.
    modifiable_objects, perms_needed = get_deleted_objects(
        queryset, opts, request.user, modeladmin.admin_site, levels_to_root=2)

    can_audit = validate_false_paper_have_type(
        queryset, [enums.FW_PAPER_TYPE, enums.BMW_PAPER_TYPE])
    if can_audit == False:
        messages.error(request, msg_paper_not_belong_fht)
        return None
    paper_st_right = validate_false_paper_status(
        request, queryset, [enums.FH_PAPER_STATUS_WAIT_AUDIT_2], u'独立复核团队终审')
    if paper_st_right == False:
        return None
    # The user has already confirmed the deletion.
    # Do the deletion and return a None to display the change list view again.
    if request.POST.get('post'):
        user = request.user
        # 权限判定
        if not has_fh_end_audit_perm(user) and not has_manage_perm(user):
            raise PermissionDenied
        n = queryset.count()
        passed_papers = []
        if n:
            perm = enums.PAPER_STATUS_FINISH
            for obj in queryset:
                obj_display = force_unicode(obj)
                if obj.status < perm:
                    from mc import save_paper_audit_status
                    save_paper_audit_status(obj, request.user, perm)

                    obj.status = perm
                    obj.save()
                    passed_papers.append(obj)
                    # change
                    modeladmin.log_change(request, obj, obj_display)
                else:
                    n -= 1

            modeladmin.message_user(
                request, u'独立复核终审通过 %(count)d %(items)s 报告.' % {
                    "count": n,
                    "items": model_ngettext(modeladmin.opts, n)
                })
            if len(passed_papers) > 0:
                from service.core._report import generate_report_by_paper
                generate_report_by_paper(queryset)
                conflicts_msg = []
                for paper in queryset:
                    no_conflict, diff = paperdiff.do_dealer_paper_diff(
                        paper, user)
#                    if not no_conflict:
#                        conflicts_msg.append(u'%s(FW团队问卷: %s 与 复核团队问卷: %s 比较,产生BMW审核问卷: %s)' % (paper.dealer.name, diff.fw_paper.survey_code, diff.fh_paper.survey_code, diff.final_paper.survey_code))
#                if len(conflicts_msg) > 0:
#                    modeladmin.message_user(request, u'产生问卷差异的经销商及相关问卷信息如下:')
#                    for tmpmsg in conflicts_msg:
#                        modeladmin.message_user(request, tmpmsg)
#                else:
#                    modeladmin.message_user(request, u'并未产生问卷差异.')

# Return None to display the change list page again.
        return None

    context = {
        "title": _("Are you sure?"),
        "object_name": force_unicode(opts.verbose_name),
        "modifiable_objects": modifiable_objects,
        'queryset': queryset,
        "opts": opts,
        "root_path": modeladmin.admin_site.root_path,
        "app_label": app_label,
        'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME,
    }

    # Display the confirmation page
    return render_to_response(
        'fh_finish_audit_confirmation.html',
        context,
        context_instance=template.RequestContext(request))
Beispiel #4
0
def fh_audit(modeladmin, request, queryset):
    """
    """
    opts = modeladmin.model._meta
    app_label = opts.app_label
    
    # Populate modifiable_objects, a data structure of all related objects that will also be deleted.
    modifiable_objects, perms_needed = get_deleted_objects(queryset, opts, request.user, modeladmin.admin_site, levels_to_root=2)

    can_audit = validate_false_paper_have_type(queryset, [enums.FW_PAPER_TYPE, enums.BMW_PAPER_TYPE])
    if can_audit == False:
        messages.error(request, msg_paper_not_belong_fht)
        return None
    paper_st_right = validate_false_paper_status(request, queryset, [enums.FH_PAPER_STATUS_INPUT, enums.FH_PAPER_STATUS_WAIT_AUDIT_1], u'独立复核团队审核')
    if paper_st_right == False:
        return None
    # The user has already confirmed the deletion.
    # Do the deletion and return a None to display the change list view again.    
    if request.POST.get('post'):
        user = request.user
        # 权限判定
        if not has_fh_audit_perm(user) and not has_manage_perm(user):
            raise PermissionDenied
        
        n = queryset.count()
        if n:
            perm = enums.FH_PAPER_STATUS_WAIT_AUDIT_2
            for obj in queryset :
                obj_display = force_unicode(obj)
                if obj.status < perm:
                    from mc import save_paper_audit_status
                    save_paper_audit_status(obj, request.user, perm)
                    
                    obj.status = perm
                    obj.save()
                    
                    # change
                    modeladmin.log_change(request, obj, obj_display)
                else:
                    n -= 1

            modeladmin.message_user(request, u'独立复核审核通过 %(count)d %(items)s 报告.' % {
                "count": n, "items": model_ngettext(modeladmin.opts, n)
            })
        
        # Return None to display the change list page again.
        return None
    
    context = {
        "title": _("Are you sure?"),
        "object_name": force_unicode(opts.verbose_name),
        "modifiable_objects": modifiable_objects,
        'queryset': queryset,
        
        "opts": opts,
        "root_path": modeladmin.admin_site.root_path,
        "app_label": app_label,
        'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME,
    }
    
    # Display the confirmation page
    return render_to_response('fh_audit_confirmation.html', context, context_instance=template.RequestContext(request))
Beispiel #5
0
def fh_audit(modeladmin, request, queryset):
    """
    """
    opts = modeladmin.model._meta
    app_label = opts.app_label

    # Populate modifiable_objects, a data structure of all related objects that will also be deleted.
    modifiable_objects, perms_needed = get_deleted_objects(
        queryset, opts, request.user, modeladmin.admin_site, levels_to_root=2)

    can_audit = validate_false_paper_have_type(
        queryset, [enums.FW_PAPER_TYPE, enums.BMW_PAPER_TYPE])
    if can_audit == False:
        messages.error(request, msg_paper_not_belong_fht)
        return None
    paper_st_right = validate_false_paper_status(
        request, queryset,
        [enums.FH_PAPER_STATUS_INPUT, enums.FH_PAPER_STATUS_WAIT_AUDIT_1],
        u'独立复核团队审核')
    if paper_st_right == False:
        return None
    # The user has already confirmed the deletion.
    # Do the deletion and return a None to display the change list view again.
    if request.POST.get('post'):
        user = request.user
        # 权限判定
        if not has_fh_audit_perm(user) and not has_manage_perm(user):
            raise PermissionDenied

        n = queryset.count()
        if n:
            perm = enums.FH_PAPER_STATUS_WAIT_AUDIT_2
            for obj in queryset:
                obj_display = force_unicode(obj)
                if obj.status < perm:
                    from mc import save_paper_audit_status
                    save_paper_audit_status(obj, request.user, perm)

                    obj.status = perm
                    obj.save()

                    # change
                    modeladmin.log_change(request, obj, obj_display)
                else:
                    n -= 1

            modeladmin.message_user(
                request, u'独立复核审核通过 %(count)d %(items)s 报告.' % {
                    "count": n,
                    "items": model_ngettext(modeladmin.opts, n)
                })

        # Return None to display the change list page again.
        return None

    context = {
        "title": _("Are you sure?"),
        "object_name": force_unicode(opts.verbose_name),
        "modifiable_objects": modifiable_objects,
        'queryset': queryset,
        "opts": opts,
        "root_path": modeladmin.admin_site.root_path,
        "app_label": app_label,
        'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME,
    }

    # Display the confirmation page
    return render_to_response(
        'fh_audit_confirmation.html',
        context,
        context_instance=template.RequestContext(request))