diff --git a/alerts/__init__.py b/alerts/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/alerts/admin.py b/alerts/admin.py new file mode 100644 index 00000000..d8fb88af --- /dev/null +++ b/alerts/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin + +from .models import Alert + +admin.site.register(Alert) diff --git a/alerts/migrations/0001_initial.py b/alerts/migrations/0001_initial.py new file mode 100644 index 00000000..cd6d96f8 --- /dev/null +++ b/alerts/migrations/0001_initial.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Alert', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('active', models.BooleanField()), + ('message', models.CharField(max_length=255)), + ], + options={ + }, + bases=(models.Model,), + ), + ] diff --git a/alerts/migrations/__init__.py b/alerts/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/alerts/models.py b/alerts/models.py new file mode 100644 index 00000000..e331086d --- /dev/null +++ b/alerts/models.py @@ -0,0 +1,7 @@ +from django.db import models + + +class Alert(models.Model): + + active = models.BooleanField() + message = models.CharField(max_length=255) diff --git a/config/settings.py b/config/settings.py index cedf603b..1b2731b4 100755 --- a/config/settings.py +++ b/config/settings.py @@ -118,6 +118,7 @@ CUSTOM_APPS = ( 'pokemon', 'pokemon_v2', 'hits', + 'alerts', ) INSTALLED_APPS = ( diff --git a/config/views.py b/config/views.py index 6c94b5dd..e1395ad9 100755 --- a/config/views.py +++ b/config/views.py @@ -7,6 +7,7 @@ from django.shortcuts import render_to_response, redirect from django.template import RequestContext from django.views.decorators.csrf import csrf_exempt +from alerts.models import Alert from hits.models import ResourceView import stripe @@ -24,11 +25,19 @@ def about(request): average_day = int(round(total_views / ResourceView.objects.count())) cache.set('average_day', average_day) + alert = cache.get('alert') + if not alert: + active_alerts = Alert.objects.filter(active=True) + if active_alerts: + cache.set('alert', active_alerts.first()) + alert = active_alerts.first() + return render_to_response( 'pages/about.html', { 'total': total_views, 'average_day': average_day, + 'alert': alert }, context_instance=RequestContext(request) ) @@ -44,11 +53,19 @@ def home(request): stripe_key = settings.STRIPE_KEYS['publishable'] + alert = cache.get('alert') + if not alert: + active_alerts = Alert.objects.filter(active=True) + if active_alerts: + cache.set('alert', active_alerts.first()) + alert = active_alerts.first() + return render_to_response( 'pages/home.html', { 'total_views': total_views, - 'stripe_key': stripe_key + 'stripe_key': stripe_key, + 'alert': alert }, context_instance=RequestContext(request) ) diff --git a/templates/pages/about.html b/templates/pages/about.html index 26a72933..dea64cb8 100755 --- a/templates/pages/about.html +++ b/templates/pages/about.html @@ -33,6 +33,19 @@

The RESTful Pokémon Data API

+ {% if alert %} +
+
+
+
+
+ +
+
+
+
+
+ {% endif %}
diff --git a/templates/pages/home.html b/templates/pages/home.html index 9f2be810..ab291e8e 100755 --- a/templates/pages/home.html +++ b/templates/pages/home.html @@ -33,19 +33,19 @@

Over {{ total_views|intcomma }} API calls received!

+ {% if alert %}
- {% if update %} -
+
-
{{update.content|safe}}
+
-
- {% endif %} +
+ {% endif %}

Finally; all the Pokémon data you'll ever need, in one place,
and easily accessible through a modern RESTful API.