示例#1
0
def is_sponsor(user):
    cache_key = get_key(user, 'is_sponsor')
    is_user_sponsor = cache.get(cache_key)

    if is_user_sponsor is None:
        donations_count = Donation.objects.filter(donor=user, state=DonationState.FINISHED).count()
        rents_count = RentVenue.objects.filter(donor=user, state=DonationState.FINISHED).count()

        is_user_sponsor = donations_count > 0 or rents_count > 0
        cache.set(cache_key, is_sponsor, CACHE_TIME)

    return is_user_sponsor
示例#2
0
def is_sponsor(user):
    cache_key = get_key(user, 'is_sponsor')
    is_user_sponsor = cache.get(cache_key)

    if is_user_sponsor is None:
        donations_count = Donation.objects.filter(
            donor=user, state=DonationState.FINISHED).count()
        rents_count = RentVenue.objects.filter(
            donor=user, state=DonationState.FINISHED).count()

        is_user_sponsor = donations_count > 0 or rents_count > 0
        cache.set(cache_key, is_sponsor, CACHE_TIME)

    return is_user_sponsor
    def process_request(request):
        if not request.user.is_authenticated():
            return None

        cache_key = get_key(request.user, 'is_sponsor')
        is_sponsor = cache.get(cache_key)

        if is_sponsor is None:
            donations = Donation.objects.filter(
                donor=request.user,
                state=DonationState.FINISHED
            )
            rents = RentVenue.objects.filter(
                donor=request.user,
                state=DonationState.FINISHED
            )

            is_sponsor = len(donations) > 0 or len(rents) > 0
            cache.set(cache_key, is_sponsor, CACHE_TIME)

        request.user.is_sponsor = is_sponsor

        return None