mirror of
https://github.com/PokeAPI/pokeapi
synced 2024-11-25 04:40:21 +00:00
Add alerts model and UI (#252)
This commit is contained in:
parent
a706bfbd9a
commit
85dd999396
9 changed files with 73 additions and 6 deletions
0
alerts/__init__.py
Normal file
0
alerts/__init__.py
Normal file
5
alerts/admin.py
Normal file
5
alerts/admin.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from .models import Alert
|
||||
|
||||
admin.site.register(Alert)
|
24
alerts/migrations/0001_initial.py
Normal file
24
alerts/migrations/0001_initial.py
Normal file
|
@ -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,),
|
||||
),
|
||||
]
|
0
alerts/migrations/__init__.py
Normal file
0
alerts/migrations/__init__.py
Normal file
7
alerts/models.py
Normal file
7
alerts/models.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
class Alert(models.Model):
|
||||
|
||||
active = models.BooleanField()
|
||||
message = models.CharField(max_length=255)
|
|
@ -118,6 +118,7 @@ CUSTOM_APPS = (
|
|||
'pokemon',
|
||||
'pokemon_v2',
|
||||
'hits',
|
||||
'alerts',
|
||||
)
|
||||
|
||||
INSTALLED_APPS = (
|
||||
|
|
|
@ -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)
|
||||
)
|
||||
|
|
|
@ -33,6 +33,19 @@
|
|||
<h1>The RESTful Pokémon Data API</h1>
|
||||
|
||||
</div>
|
||||
{% if alert %}
|
||||
<div class="container">
|
||||
<div class="row" style="padding-top:20px;text-align:center;">
|
||||
<div class="col-md-2">
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="alert alert-danger" role="alert">{{ alert.message|safe }}</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
|
|
@ -33,19 +33,19 @@
|
|||
<h4>Over <span class="count">{{ total_views|intcomma }}</span> API calls received!</h4>
|
||||
</div>
|
||||
|
||||
{% if alert %}
|
||||
<div class="container">
|
||||
{% if update %}
|
||||
<div class="row" style="padding-top:80px;text-align:center;">
|
||||
<div class="row" style="padding-top:20px;text-align:center;">
|
||||
<div class="col-md-2">
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="alert alert-success">{{update.content|safe}}</div>
|
||||
<div class="alert alert-danger" role="alert">{{ alert.message|safe }}</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
</div>
|
||||
</div><!-- /.header row -->
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="cta">
|
||||
<p>Finally; all the Pokémon data you'll ever need, in one place,<br /> and easily accessible through a modern RESTful API.</p>
|
||||
|
|
Loading…
Reference in a new issue