28
28
29
29
def show_to_geo (promo , country_code ):
30
30
# Remove promo's that exclude this country.
31
- for geo_filter in promo .geo_geo_filters .all ():
32
- if geo_filter .geo_filter_type == INCLUDE :
31
+ for geo_filter in promo .geo_filters .all ():
32
+ if geo_filter .filter_type == INCLUDE :
33
33
if country_code in geo_filter .codes :
34
34
continue
35
35
else :
36
36
return False
37
- if geo_filter .geo_filter_type == EXCLUDE :
37
+ if geo_filter .filter_type == EXCLUDE :
38
38
if country_code in geo_filter .codes :
39
39
return False
40
40
@@ -90,7 +90,8 @@ def choose_promo(promo_list):
90
90
return None
91
91
92
92
93
- def get_promo (country_code , programming_language , theme , gold_project = False , gold_user = False ):
93
+ def get_promo (country_code , programming_language , theme ,
94
+ gold_project = False , gold_user = False , community_only = False ):
94
95
"""
95
96
Get a proper promo.
96
97
@@ -104,6 +105,9 @@ def get_promo(country_code, programming_language, theme, gold_project=False, gol
104
105
"""
105
106
promo_queryset = SupporterPromo .objects .filter (live = True , display_type = 'doc' )
106
107
108
+ if community_only :
109
+ promo_queryset = promo_queryset .filter (community = True )
110
+
107
111
filtered_promos = []
108
112
for promo in promo_queryset :
109
113
# Break out if we aren't meant to show to this language
@@ -157,6 +161,15 @@ def is_gold_project(project):
157
161
return project .gold_owners .count ()
158
162
159
163
164
+ def is_community_only (user , project ):
165
+ """Return True is this project or user should only be shown community ads"""
166
+ if user .is_authenticated () and user .profile .as_opt_out :
167
+ return True
168
+ if not project .allow_promos :
169
+ return True
170
+ return False
171
+
172
+
160
173
def get_user_country (request ):
161
174
"""Return the ISO country code from geo-IP data, or None if not found."""
162
175
if not PROMO_GEO_PATH :
@@ -200,11 +213,9 @@ def lookup_promo(request, project, theme):
200
213
if no promo should be shown.
201
214
202
215
"""
203
- if not project .allow_promos :
204
- return None
205
-
206
216
gold_user = is_gold_user (request .user )
207
217
gold_project = is_gold_project (project )
218
+ community_only = is_community_only (request .user , project )
208
219
209
220
# Don't show promos to gold users or on gold projects for now
210
221
# (Some day we may show them something customised for them)
@@ -217,6 +228,7 @@ def lookup_promo(request, project, theme):
217
228
theme = theme ,
218
229
gold_project = gold_project ,
219
230
gold_user = gold_user ,
231
+ community_only = community_only ,
220
232
)
221
233
222
234
# If we don't have anything to show, don't show it.
0 commit comments