-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63c979d
commit b710791
Showing
11 changed files
with
272 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
default_app_config = 'ads.apps.AdsConfig' | ||
|
||
__version__ = '0.2.2' | ||
__version__ = '1.0.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from django.http import JsonResponse | ||
|
||
|
||
class JSONResponseMixin: | ||
""" | ||
A mixin that can be used to render a JSON response. | ||
""" | ||
def render_to_json_response(self, context, **response_kwargs): | ||
""" | ||
Returns a JSON response, transforming 'context' to make the payload. | ||
""" | ||
return JsonResponse( | ||
self.get_data(context), | ||
**response_kwargs | ||
) | ||
|
||
def get_data(self, context): | ||
""" | ||
Returns an object that will be serialized as JSON by json.dumps(). | ||
""" | ||
# Note: This is *EXTREMELY* naive; in reality, you'll need | ||
# to do much more complex handling to ensure that arbitrary | ||
# objects -- such as Django model instances or querysets | ||
# -- can be serialized as JSON. | ||
return context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
$(function() { | ||
var zones = []; | ||
$('div[data-django-ads-zone]').each(function() { | ||
var zone = $(this).data('django-ads-zone'); | ||
zones.push(zone); | ||
}); | ||
var url = Urls['ads:ad-impression'](); | ||
$.get(url, { zones: zones }, function( data ) { | ||
var viewports = data.viewports; | ||
Object.keys(data.zones).forEach(key => { | ||
var $ad_container = $('div[data-django-ads-zone="'+key+'"]'); | ||
var zone = data.zones[key]; | ||
var html = ''; | ||
if(zone.ad !== null) { | ||
ad = zone.ad; | ||
html = '<a href="'+ad.url+'" target="_blank">'; | ||
Object.keys(ad['images']).forEach(key => { | ||
var img = ad['images'][key]; | ||
html += '<img src="'+img.url+'" class="'+viewports[key]+'"/>'; | ||
}); | ||
html += '</a>'; | ||
$ad_container.html(html); | ||
} else if ('google_adsense_slot' in zone.conf && 'google_adsense_format' in zone.conf) { | ||
var google_adsense_client = data.google_adsense_client; | ||
var google_adsense_slot = zone.conf.google_adsense_slot; | ||
var google_adsense_format = zone.conf.google_adsense_format; | ||
html = '<ins class="adsbygoogle" \ | ||
style="display:block" \ | ||
data-ad-client="'+google_adsense_client+'" \ | ||
data-ad-slot="'+google_adsense_slot+'" \ | ||
data-ad-format="'+google_adsense_format+'"></ins>'; | ||
$ad_container.html(html); | ||
(adsbygoogle = window.adsbygoogle || []).push({}); | ||
} | ||
if(html !== '') { | ||
var extra_classes = $ad_container.data('django-ads-extra-classes'); | ||
$ad_container.addClass(extra_classes); | ||
} | ||
}); | ||
/* | ||
<ins class="adsbygoogle" | ||
style="display:block" | ||
data-ad-client="{{ google_adsense_client }}" | ||
data-ad-slot="{{ zone.google_adsense_slot }}" | ||
data-ad-format="{{ zone.google_adsense_format|default:'auto' }}"></ins> | ||
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script> | ||
*/ | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,3 @@ | ||
{% load sekizai_tags %}{% spaceless %} | ||
{% if ad %} | ||
{% for image in ad.images.all %} | ||
<a href="{% url 'ads:ad-click' ad.id %}" target="_blank" rel="nofollow" title="{{ ad.title }}" class="django-ads-ad visible-{{ image.device }}"> | ||
<img src="{{ image.image.url }}" class="img-responsive" /> | ||
</a> | ||
{% endfor %} | ||
{% elif google_adsense_client and zone.google_adsense_slot %} | ||
{% addtoblock "js" %}<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>{% endaddtoblock %} | ||
<ins class="adsbygoogle" | ||
style="display:block" | ||
data-ad-client="{{ google_adsense_client }}" | ||
data-ad-slot="{{ zone.google_adsense_slot }}" | ||
data-ad-format="{{ zone.google_adsense_format|default:'auto' }}"></ins> | ||
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script> | ||
{% endif %} | ||
{% endspaceless %} | ||
{% load static sekizai_tags %} | ||
<div data-django-ads-zone="{{ zone|safe }}" data-django-ads-extra-classes="{{ extra_classes|safe }}"></div> | ||
{% addtoblock "js" %}<script defer src='{% static 'ads/ads.js' %}'></script>{% endaddtoblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
from ads.views import AdClickView | ||
from ads.views import AdImpressionView, AdClickView | ||
from django.conf.urls import url | ||
|
||
|
||
app_name = 'ads' | ||
urlpatterns = [ | ||
url(r'^(?P<pk>\d+)/$', AdClickView.as_view(), name='ad-click'), | ||
url(r'^(?P<pk>\d+)/$', | ||
AdClickView.as_view(), name='ad-click'), | ||
url(r'^get-ads-by-zones/$', | ||
AdImpressionView.as_view(), name='ad-impression'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.