Add a basic Welcome page.

This commit is contained in:
Christopher Charbonneau Wells 2017-11-09 07:24:32 -05:00
parent b7de3999b9
commit 00d3cf65f5
8 changed files with 155 additions and 17 deletions

View File

@ -0,0 +1,69 @@
{% extends 'babybuddy/page.html' %}
{% load widget_tweaks %}
{% block title %}Welcome!{% endblock %}
{% block breadcrumbs %}
<li class="breadcrumb-item active" aria-current="page">Welcome!</li>
{% endblock %}
{% block content %}
<div class="jumbotron">
<h1 class="display-3">Welcome to Baby Buddy!</h1>
<p class="lead">
Learn about and predict baby's needs without (<em>as much</em>)
guess work by using Baby Buddy to track &mdash;
</p>
<hr class="my-4">
<div class="card-deck">
<div class="card card-diaperchange">
<div class="card-header text-center">
<i class="icon icon-2x icon-diaperchange" aria-hidden="true"></i>
</div>
<div class="card-body">
<h3 class="card-title text-center">Diaper Changes</h3>
</div>
</div>
<div class="card card-feeding">
<div class="card-header text-center">
<i class="icon icon-2x icon-feeding" aria-hidden="true"></i>
</div>
<div class="card-body">
<h3 class="card-title text-center">Feedings</h3>
</div>
</div>
<div class="card card-sleep">
<div class="card-header text-center">
<i class="icon icon-2x icon-sleep" aria-hidden="true"></i>
</div>
<div class="card-body">
<h3 class="card-title text-center">Sleep</h3>
</div>
</div>
<div class="card card-tummytime">
<div class="card-header text-center">
<i class="icon icon-2x icon-tummytime" aria-hidden="true"></i>
</div>
<div class="card-body">
<h3 class="card-title text-center">Tummy Time</h3>
</div>
</div>
</div>
<hr class="my-4">
<p class="lead">
As the amount of entries grows, Baby Buddy will help
parents and caregivers to identify small patterns in baby's habits
using the dashboard and graphs. Baby Buddy is mobile-friendly and
uses a dark theme to help weary moms and dads with 2AM feedings and
changings. To get started, just click the button below to add your
first (or second, third, etc.) child!
</p>
<p class="text-center">
{% if perms.core.add_child %}
<a href="{% url 'child-add' %}" class="btn btn-lg btn-success">
<i class="icon icon-child" aria-hidden="true"></i> Add a Child
</a>
{% endif %}
</p>
</div>
{% endblock %}

View File

View File

@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
from django.test import Client as HttpClient
from django.contrib.auth.models import User
from django.core.management import call_command
from faker import Factory
from core.models import Child
class ViewsTestCase(TestCase):
@classmethod
def setUpClass(cls):
super(ViewsTestCase, cls).setUpClass()
fake = Factory.create()
call_command('migrate', verbosity=0)
cls.c = HttpClient()
fake_user = fake.simple_profile()
cls.credentials = {
'username': fake_user['username'],
'password': fake.password()
}
cls.user = User.objects.create_user(
is_superuser=True, **cls.credentials)
cls.c.login(**cls.credentials)
def test_root_router(self):
page = self.c.get('/')
self.assertEqual(page.url, '/welcome/')
call_command('fake', verbosity=0, children=1, days=1)
child = Child.objects.first()
page = self.c.get('/')
self.assertEqual(
page.url, '/children/{}/dashboard/'.format(child.slug))
Child.objects.create(
first_name='Second',
last_name='Child',
birth_date='2000-01-01'
)
page = self.c.get('/')
self.assertEqual(page.url, '/dashboard/')

View File

@ -3,16 +3,21 @@ from __future__ import unicode_literals
from django.conf.urls import url, include
from django.contrib import admin
from django.contrib.auth import views
from django.contrib.auth import views as auth_views
from . import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^login/$', views.LoginView.as_view(), name='login'),
url(r'^logout/$', views.LogoutView.as_view(), name='logout'),
url('^password_reset/$', views.PasswordResetView.as_view(),
url(r'^login/$', auth_views.LoginView.as_view(), name='login'),
url(r'^logout/$', auth_views.LogoutView.as_view(), name='logout'),
url('^password_reset/$', auth_views.PasswordResetView.as_view(),
name='password_reset',),
url(r'^$', views.RootRouter.as_view(), name='root-router'),
url(r'^welcome/$', views.Welcome.as_view(), name='welcome'),
url(r'', include('api.urls', namespace='api')),
url(r'', include('core.urls')),
url(r'', include('dashboard.urls')),

25
babybuddy/views.py Normal file
View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse
from django.views.generic.base import TemplateView, RedirectView
from core.models import Child
class RootRouter(LoginRequiredMixin, RedirectView):
def get_redirect_url(self, *args, **kwargs):
children = Child.objects.count()
if children == 0:
self.url = reverse('welcome')
elif children == 1:
self.url = reverse(
'dashboard-child', args={Child.objects.first().slug})
else:
self.url = reverse('dashboard')
return super(RootRouter, self).get_redirect_url(self, *args, **kwargs)
class Welcome(LoginRequiredMixin, TemplateView):
template_name = 'babybuddy/welcome.html'

View File

@ -31,12 +31,8 @@ class ViewsTestCase(TestCase):
cls.c.login(**cls.credentials)
def test_dashboard_views(self):
"""Dashboard handles the root URL and redirects based on zero, one, or
more than one child is in the database."""
page = self.c.get('/')
self.assertEqual(page.url, '/dashboard/')
page = self.c.get('/dashboard/')
self.assertEqual(page.url, '/children/add/')
self.assertEqual(page.url, '/welcome/')
call_command('fake', verbosity=0, children=1, days=1)
child = Child.objects.first()

View File

@ -6,7 +6,6 @@ from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.DashboardRedirect.as_view(), name='dashboard-redirect'),
url(r'^dashboard/$', views.Dashboard.as_view(), name='dashboard'),
url(r'^children/(?P<slug>[^/.]+)/dashboard/$',
views.ChildDashboard.as_view(), name='dashboard-child'),

View File

@ -5,16 +5,12 @@ from django.contrib.auth.mixins import (LoginRequiredMixin,
PermissionRequiredMixin)
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.views.generic.base import TemplateView, RedirectView
from django.views.generic.base import TemplateView
from django.views.generic.detail import DetailView
from core.models import Child
class DashboardRedirect(LoginRequiredMixin, RedirectView):
url = '/dashboard/'
class Dashboard(LoginRequiredMixin, TemplateView):
# TODO: Use .card-deck in this template once BS4 is finalized.
template_name = 'dashboard/dashboard.html'
@ -23,8 +19,7 @@ class Dashboard(LoginRequiredMixin, TemplateView):
def get(self, request, *args, **kwargs):
children = Child.objects.count()
if children == 0:
# TODO: Create some sort of welcome page.
return HttpResponseRedirect(reverse('child-add'))
return HttpResponseRedirect(reverse('welcome'))
elif children == 1:
return HttpResponseRedirect(
reverse('dashboard-child', args={Child.objects.first().slug}))