Esempio n. 1
0
def lookup_promo(request, project, theme):
    """Look up a promo to show for the given project.

    Return a dict of promo_data for inclusion in the footer response, or None
    if no promo should be shown.

    """
    gold_user = is_gold_user(request.user)
    gold_project = is_gold_project(project)
    community_only = is_community_only(request.user, project)

    # Don't show promos to gold users or on gold projects for now
    # (Some day we may show them something customised for them)
    if gold_user or gold_project:
        return None

    promo_obj = get_promo(
        country_code=get_user_country(request),
        programming_language=project.programming_language,
        theme=theme,
        gold_project=gold_project,
        gold_user=gold_user,
        community_only=community_only,
    )

    # If we don't have anything to show, don't show it.
    if not promo_obj:
        return None

    return offer_promo(
        promo_obj=promo_obj,
        project=project
    )
Esempio n. 2
0
def lookup_promo(request, project, theme):
    """Look up a promo to show for the given project.

    Return a dict of promo_data for inclusion in the footer response, or None
    if no promo should be shown.

    """
    gold_user = is_gold_user(request.user)
    gold_project = is_gold_project(project)
    community_only = is_community_only(request.user, project)

    # Don't show promos to gold users or on gold projects for now
    # (Some day we may show them something customised for them)
    if gold_user or gold_project:
        return None

    promo_obj = get_promo(
        country_code=get_user_country(request),
        programming_language=project.programming_language,
        theme=theme,
        gold_project=gold_project,
        gold_user=gold_user,
        community_only=community_only,
    )

    # If we don't have anything to show, don't show it.
    if not promo_obj:
        return None

    return offer_promo(promo_obj=promo_obj, project=project)
Esempio n. 3
0
def _add_promo_data(display_type):
    promo_queryset = SupporterPromo.objects.filter(live=True, display_type=display_type)
    promo_obj = promo_queryset.order_by('?').first()
    if promo_obj:
        promo_dict = offer_promo(promo_obj=promo_obj, project=None)
    else:
        promo_dict = None
    return promo_dict
Esempio n. 4
0
def _add_promo_data(display_type):
    promo_queryset = SupporterPromo.objects.filter(live=True,
                                                   display_type=display_type)
    promo_obj = promo_queryset.order_by('?').first()
    if promo_obj:
        promo_dict = offer_promo(promo_obj=promo_obj, project=None)
    else:
        promo_dict = None
    return promo_dict
Esempio n. 5
0
def attach_promo_data(sender, **kwargs):
    request = kwargs['request']
    context = kwargs['context']
    resp_data = kwargs['resp_data']

    project = context['project']
    theme = context['theme']

    # Bail out early if promo's are disabled.
    use_promo = getattr(settings, 'USE_PROMOS', True)
    if not use_promo:
        resp_data['promo'] = False
        return

    gold_user = gold_project = False
    promo_obj = country_code = None

    show_promo = project.allow_promos

    # The request is by a GoldUser
    if request.user.is_authenticated():
        if request.user.gold.count() or request.user.goldonce.count():
            gold_user = True

    # A GoldUser has mapped this project
    if project.gold_owners.count():
        gold_project = True

    # Don't show gold users promos.
    # This will get overridden if we have specific promos for them below.
    if gold_user or gold_project:
        show_promo = False

    if PROMO_GEO_PATH:
        # Get geo information from the IP, but don't record it anywhere
        ip = request.META.get('REMOTE_ADDR')
        if ip:
            try:
                geo_response = geo_reader.city(ip)
                country_code = geo_response.country.iso_code
            except (AddressNotFoundError, ValueError):  # Invalid IP
                country_code = None

    # Try to get a promo if we should be using one.
    if show_promo:
        promo_obj = get_promo(
            country_code=country_code,
            programming_language=project.programming_language,
            theme=theme,
            gold_project=gold_project,
            gold_user=gold_user,
        )

    # If we don't have anything to show, don't show it.
    if not promo_obj:
        show_promo = False

    if show_promo:
        promo_dict = offer_promo(promo_obj=promo_obj, project=project)
        resp_data['promo_data'] = promo_dict

    # Set promo object on return JSON
    resp_data['promo'] = show_promo