first commit
This commit is contained in:
5
app/__init__.py
Normal file
5
app/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
"""
|
||||
License: MIT
|
||||
Copyright (c) 2019 - present AppSeed.us
|
||||
"""
|
||||
9
app/admin.py
Normal file
9
app/admin.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
"""
|
||||
License: MIT
|
||||
Copyright (c) 2019 - present AppSeed.us
|
||||
"""
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
10
app/config.py
Normal file
10
app/config.py
Normal file
@@ -0,0 +1,10 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
"""
|
||||
License: MIT
|
||||
Copyright (c) 2019 - present AppSeed.us
|
||||
"""
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
class MyConfig(AppConfig):
|
||||
name = 'cfg'
|
||||
5
app/migrations/__init__.py
Normal file
5
app/migrations/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
"""
|
||||
License: MIT
|
||||
Copyright (c) 2019 - present AppSeed.us
|
||||
"""
|
||||
11
app/models.py
Normal file
11
app/models.py
Normal file
@@ -0,0 +1,11 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
"""
|
||||
License: MIT
|
||||
Copyright (c) 2019 - present AppSeed.us
|
||||
"""
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
# Create your models here.
|
||||
|
||||
0
app/templatetags/__init__.py
Normal file
0
app/templatetags/__init__.py
Normal file
47
app/templatetags/trend.py
Normal file
47
app/templatetags/trend.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from django import template
|
||||
|
||||
register = template.Library()
|
||||
|
||||
GREEN = "text-success"
|
||||
RED = "text-danger"
|
||||
|
||||
ARROW_UP = "fa fa-angle-up"
|
||||
ARROW_DOWN = "fa fa-angle-down"
|
||||
|
||||
CONDITIONS = {
|
||||
'death_rate': {
|
||||
"GT_0": (RED, ARROW_UP),
|
||||
"LT_0": (GREEN, ARROW_DOWN)
|
||||
},
|
||||
'recovered': {
|
||||
"GT_0": (GREEN, ARROW_UP),
|
||||
"LT_0": (RED, ARROW_DOWN)
|
||||
},
|
||||
'confirmed': {
|
||||
"GT_0": (RED, ARROW_UP),
|
||||
"LT_0": (GREEN, ARROW_DOWN)
|
||||
},
|
||||
'deaths': {
|
||||
"GT_0": (RED, ARROW_UP),
|
||||
"LT_0": (GREEN, ARROW_DOWN)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def arrow(name, value):
|
||||
if value > 0:
|
||||
return CONDITIONS[name]["GT_0"][1]
|
||||
else:
|
||||
return CONDITIONS[name]["LT_0"][1]
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def color(name, value):
|
||||
if value > 0:
|
||||
return CONDITIONS[name]["GT_0"][0]
|
||||
else:
|
||||
return CONDITIONS[name]["LT_0"][0]
|
||||
|
||||
|
||||
|
||||
37
app/tests.py
Normal file
37
app/tests.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
"""
|
||||
License: MIT
|
||||
Copyright (c) 2019 - present AppSeed.us
|
||||
"""
|
||||
|
||||
|
||||
from django.test import TestCase
|
||||
from app.templatetags import trend
|
||||
|
||||
|
||||
class TestTrendTemplateTags(TestCase):
|
||||
def test_color_tag(self):
|
||||
self.assertEqual("text-danger", trend.color("deaths", 20))
|
||||
self.assertEqual("text-success", trend.color("deaths", -20))
|
||||
|
||||
self.assertEqual("text-danger", trend.color("confirmed", 20))
|
||||
self.assertEqual("text-success", trend.color("confirmed", -20))
|
||||
|
||||
self.assertEqual("text-danger", trend.color("recovered", -20))
|
||||
self.assertEqual("text-success", trend.color("recovered", 20))
|
||||
|
||||
self.assertEqual("text-danger", trend.color("death_rate", 20))
|
||||
self.assertEqual("text-success", trend.color("death_rate", -20))
|
||||
|
||||
def test_arrow_tag(self):
|
||||
self.assertEqual("fa fa-angle-up", trend.arrow("deaths", 20))
|
||||
self.assertEqual("fa fa-angle-down", trend.arrow("deaths", -20))
|
||||
|
||||
self.assertEqual("fa fa-angle-up", trend.arrow("confirmed", 20))
|
||||
self.assertEqual("fa fa-angle-down", trend.arrow("confirmed", -20))
|
||||
|
||||
self.assertEqual("fa fa-angle-down", trend.arrow("recovered", -20))
|
||||
self.assertEqual("fa fa-angle-up", trend.arrow("recovered", 20))
|
||||
|
||||
self.assertEqual("fa fa-angle-up", trend.arrow("death_rate", 20))
|
||||
self.assertEqual("fa fa-angle-down", trend.arrow("death_rate", -20))
|
||||
18
app/urls.py
Normal file
18
app/urls.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
"""
|
||||
License: MIT
|
||||
Copyright (c) 2019 - present AppSeed.us
|
||||
"""
|
||||
|
||||
from django.urls import path, re_path
|
||||
from app import views
|
||||
|
||||
urlpatterns = [
|
||||
# Matches any html file - to be used for gentella
|
||||
# Avoid using your .html in your resources.
|
||||
# Or create a separate django app.
|
||||
re_path(r'^.*\.html', views.pages, name='pages'),
|
||||
|
||||
# The home page
|
||||
path('', views.index, name='home'),
|
||||
]
|
||||
21
app/views.py
Normal file
21
app/views.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.template import loader
|
||||
from django.http import HttpResponse
|
||||
|
||||
|
||||
def index(request):
|
||||
return render(request, "index.html")
|
||||
|
||||
|
||||
def pages(request):
|
||||
context = {}
|
||||
# All resource paths end in .html.
|
||||
# Pick out the html file name from the url. And load that template.
|
||||
try:
|
||||
load_template = request.path.split('/')[-1]
|
||||
template = loader.get_template('pages/' + load_template)
|
||||
return HttpResponse(template.render(context, request))
|
||||
|
||||
except:
|
||||
template = loader.get_template( 'pages/error-404.html' )
|
||||
return HttpResponse(template.render(context, request))
|
||||
Reference in New Issue
Block a user