Skip to content

Commit

Permalink
Merge pull request #156 from readthedocs/show-client-code
Browse files Browse the repository at this point in the history
Add the basic embed code to the adserver dashboard for publishers.
  • Loading branch information
ericholscher committed Jul 3, 2020
2 parents eb2b99b + ad82fc3 commit ebdce8f
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 0 deletions.
11 changes: 11 additions & 0 deletions adserver/templates/adserver/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,23 @@ <h6 class="text-muted">{{ advertiser }}</h6>
<h6 class="text-muted">{{ publisher }}</h6>

<ul class="nav flex-column mb-2">

<li class="nav-item">
<a class="nav-link" href="{% url 'publisher_report' publisher.slug %}">
<span class="fa fa-bar-chart fa-fw mr-2 text-muted" aria-hidden="true"></span>
<span>{% trans 'Reports' %}</span>
</a>
</li>

{% if publisher.unauthed_ad_decisions %}
<li class="nav-item">
<a class="nav-link" href="{% url 'publisher_embed' publisher.slug %}">
<span class="fa fa-code fa-fw mr-2 text-muted" aria-hidden="true"></span>
<span>{% trans 'Client Embed Code' %}</span>
</a>
</li>
{% endif %}

</ul>
{% endif %}
</nav>
Expand Down
49 changes: 49 additions & 0 deletions adserver/templates/adserver/reports/publisher_embed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{% extends "adserver/reports/base.html" %}
{% load humanize %}
{% load i18n %}


{% block title %}{% trans 'Publisher Embed' %} - {{ publisher }}{% endblock %}


{% block heading %}{% blocktrans %}Publisher Embed for {{ publisher }}{% endblocktrans %}{% endblock heading %}

{% block filters %}
{% endblock %}

{% block breadcrumbs %}
{{ block.super }}
<li class="breadcrumb-item active">{{ publisher }}</li>
{% endblock breadcrumbs %}


{% block summary %}
<section>
<div>
<h2></h2>
<div class="row col-md-8">

<p>
This code will allow you to get started with showing ads on your site.
You publisher Id is <strong>{{ publisher.slug }}</strong>,
you can use this for all integrations.
</p>

<pre><code>&lt;script async src=&quot;https://media.ethicalads.io/media/client/ethicalads.min.js&quot;&gt;&lt;/script&gt;

&lt;!-- Show a text ad --&gt;
&lt;div data-ea-publisher=&quot;{{ publisher.slug }}&quot; data-ea-type=&quot;text&quot;&gt;&lt;/div&gt;

&lt;!-- Show an image ad --&gt;
&lt;div data-ea-publisher=&quot;{{ publisher.slug }}&quot; data-ea-type=&quot;image&quot;&gt;&lt;/div&gt;</code></pre>

<p>
You can find full documentation and more information about the client in our <a href="https://github.com/readthedocs/ethical-ad-client">GitHub repo</a>.
</p>

</div>
</section>
{% endblock summary %}


{% block report %}{% endblock report %}
13 changes: 13 additions & 0 deletions adserver/tests/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,16 @@ def test_publisher_report_export(self):
self.assertTrue(
response["Content-Disposition"].startswith("attachment; filename=")
)

def test_publisher_embed_code(self):
self.client.force_login(self.staff_user)

url = reverse("publisher_embed", args=[self.publisher1.slug])
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

self.publisher1.unauthed_ad_decisions = False
self.publisher1.save()

response = self.client.get(url)
self.assertEqual(response.status_code, 404)
6 changes: 6 additions & 0 deletions adserver/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .views import do_not_track_policy
from .views import FlightDetailView
from .views import FlightListView
from .views import PublisherEmbedView
from .views import PublisherMainView
from .views import PublisherReportView

Expand Down Expand Up @@ -114,6 +115,11 @@
PublisherReportView.as_view(),
name="publisher_report",
),
url(
r"^publisher/(?P<publisher_slug>[-a-zA-Z0-9_]+)/embed/$",
PublisherEmbedView.as_view(),
name="publisher_embed",
),
url(
r"^publisher/(?P<publisher_slug>[-a-zA-Z0-9_]+)/report\.csv$",
PublisherReportView.as_view(export=True),
Expand Down
19 changes: 19 additions & 0 deletions adserver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,25 @@ def get_context_data(self, **kwargs):
return context


class PublisherEmbedView(PublisherAccessMixin, BaseReportView):

"""A report for a single publisher."""

template_name = "adserver/reports/publisher_embed.html"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

publisher_slug = kwargs.get("publisher_slug", "")
publisher = get_object_or_404(
Publisher, slug=publisher_slug, unauthed_ad_decisions=True
)

context.update({"publisher": publisher})

return context


class AllPublisherReportView(BaseReportView):

"""A report for all publishers."""
Expand Down
6 changes: 6 additions & 0 deletions assets/src/scss/_theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ body {
padding: 0.75rem 1rem;
}

pre {
background-color: $gray-200;
padding: 1.5rem;
border: 1px solid $border-color;
}

/* Preview an advertisement - most of this custom CSS comes from Read the Docs' existing ad settings */
.advertisement-preview {
.ethical-callout {
Expand Down

0 comments on commit ebdce8f

Please sign in to comment.