(slug, **assignment)
return decorate
A version of the requires_privilege decorator which falls back
    to the insufficient privileges page with an HTTP Status Code
    of 402 that means "Payment Required"
A version of the requires_privilege decorator which falls back
    to the insufficient privileges page with an HTTP Status Code
    of 402 that means "Payment Required"
A version of the requires_privilege decorator which falls back to the insufficient privileges page with an HTTP Status Code of 402 that means Payment Required
def requires_privilege_with_fallback(slug, **assignment):
    """
    A version of the requires_privilege decorator which falls back
    to the insufficient privileges page with an HTTP Status Code
    of 402 that means "Payment Required"
    """
    def decorate(fn):
        @wraps(fn)
        def wrapped(request, *args, **kwargs):
            try:
                if (hasattr(request, 'subscription')
                    and request.subscription is not None
                    and request.subscription.is_trial
                    and request.subscription.date_end is not None
                ):
                    edition_req = DefaultProductPlan.get_lowest_edition([slug])
                    plan_name = request.subscription.plan_version.user_facing_description['name']
                    feature_name = privileges.Titles.get_name_from_privilege(slug)
                    request.show_trial_notice = True
                    request.trial_info = {
                        'current_plan': plan_name,
                        'feature_name': feature_name,
                        'required_plan': edition_req,
                        'date_end': request.subscription.date_end.strftime(USER_DATE_FORMAT)
                    }
                    request.is_domain_admin = (hasattr(request, 'couch_user') and
                                               request.couch_user.is_domain_admin(request.domain))

                return requires_privilege(slug, **assignment)(fn)(
                    request, *args, **kwargs
                )
            except PermissionDenied:
                request.show_trial_notice = False
                from corehq.apps.domain.views.accounting import SubscriptionUpgradeRequiredView
                return SubscriptionUpgradeRequiredView().get(
                    request, request.domain, slug
                )
        return wrapped
    return decorate
def requires_privilege_with_fallback ( slug , * * assignment ) : def decorate ( fn ) : @ wraps ( fn ) def wrapped ( request , * args , * * kwargs ) : try : if ( hasattr ( request , 'subscription' ) and request . subscription is not None and request . subscription . is_trial and request . subscription . date_end is not None ) : edition_req = DefaultProductPlan . get_lowest_edition ( [ slug ] ) plan_name = request . subscription . plan_version . user_facing_description [ 'name' ] feature_name = privileges . Titles . get_name_from_privilege ( slug ) request . show_trial_notice = True request . trial_info = { 'current_plan' : plan_name , 'feature_name' : feature_name , 'required_plan' : edition_req , 'date_end' : request . subscription . date_end . strftime ( USER_DATE_FORMAT ) } request . is_domain_admin = ( hasattr ( request , 'couch_user' ) and request . couch_user . is_domain_admin ( request . domain ) ) return requires_privilege ( slug , * * assignment ) ( fn ) ( request , * args , * * kwargs ) except PermissionDenied : request . show_trial_notice = False from corehq . apps . domain . views . accounting import SubscriptionUpgradeRequiredView return SubscriptionUpgradeRequiredView ( ) . get ( request , request . domain , slug ) return wrapped return decorate