Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to I DRF render_ads_zone instead of traditional Django way? #10

Open
AfolabiOlaoluwa opened this issue Nov 14, 2017 · 4 comments
Open

Comments

@AfolabiOlaoluwa
Copy link

How do I get this logic available to DRF instead of the tradition django way?

def render_ads_zone(context, zone):

    # Retrieve random ad for the zone based on weight
    ad = Ad.objects.random_ad(zone)

    if ad is not None:
        request = context['request']
        if request.session.session_key:
            impression, created = Impression.objects.get_or_create(
                ad=ad,
                session_id=request.session.session_key,
                defaults={
                    'impression_date': timezone.now(),
                    'source_ip': get_client_ip(request),
                })
    context.update({
        'ad': ad,
        'google_adsense_client': settings.ADS_GOOGLE_ADSENSE_CLIENT,
        'zone': settings.ADS_ZONES.get(zone, None)
    })
    return context
@AfolabiOlaoluwa
Copy link
Author

Its not an issue per say, but using Django Rest Framework for this app, I couldn't just serialize this logic in my views.py so that my urls.py can calls this render_ads_zone logic in views.py

@AfolabiOlaoluwa
Copy link
Author

@ataylor32 @razisayyed ?

@vinyasmusic
Copy link

Why can't you call this function from the API view ?

@oesah
Copy link

oesah commented Jan 29, 2020

Yeah @vinyasmusic, I would also just create a seperate endpoint for this logic and then call it on my client (app or website) whenever I need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants