Skip to content

Commit

Permalink
Updated html and added views for sleep details on frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftypanda committed Feb 6, 2018
1 parent 41b9932 commit d02a68a
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 11 deletions.
4 changes: 2 additions & 2 deletions sensibdiary/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['localhost', '127.0.0.1', '.pythonanywhere.com']


# Application definition
Expand Down Expand Up @@ -109,7 +109,7 @@

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'
TIME_ZONE = 'GB'

USE_I18N = True

Expand Down
3 changes: 2 additions & 1 deletion sensibdiary/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import include, path

urlpatterns = [
path('admin/', admin.site.urls),
path('sleep-diary/', include('sleep.urls')),
]
2 changes: 1 addition & 1 deletion sleep/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __str__(self):


class SleepInterruption(models.Model):
sleep_date = models.ForeignKey(Sleep, on_delete=models.CASCADE)
sleep_date = models.ForeignKey(Sleep, on_delete=models.CASCADE, related_name='interruptions')

interruption_time = models.TimeField('time woke during sleep')

Expand Down
6 changes: 4 additions & 2 deletions sleep/static/templates/css/sleep.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
.page-header {
background-color: teal;
.base-header {

margin-top: 0;
padding: 20px 20px 20px 40px;
background-color: teal;
}

.page-header h1, .page-header h1 a, .page-header h1 a:visited, .page-header h1 a:active {
color: #ffffff;
font-size: 36pt;
text-decoration: none;

}

.content {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<link href="//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="{% static 'css/sleep.css' %}">
<link rel="stylesheet" href="{% static 'templates/css/sleep.css' %}">
</head>
<body>
<div class"page-header">
#<!-- TODO: Nav menu here for authenticated users -->
<div class"base-header">
<!-- TODO: Nav menu here for authenticated users -->
<!-- TODO: Nav menu here for anonymous users / login redirect -->

<h1><a href="/">SenSibDiary</a></h1>
</div>
<div class="content container">
<div class="row">
<div class="col-md-8">
{% blockcontent %}
{% block content %}
{% endblock%}
</div>
</div>
Expand Down
24 changes: 24 additions & 0 deletions sleep/templates/sleep/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends 'sleep/base.html' %}
{% block content %}

<h1 class="sleep-detail">{{ sleep.sleep_date|date:'d-m-Y'}}</h1>
{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
<div class="sleep">
<p class="date">Sleep date: {{ sleep.sleep_date|date:'d-m-Y'}}</p>
<div class="sleep-detail">
<table>
<tr>
<td>Time started preparing for bed: {{ sleep.time_start_preparing_for_sleep|date:'H:i e'}}</tr>
<tr>
<td>Time went to bed: {{ sleep.time_went_into_bed|date:'H:i e' }}</tr>
<tr>
<td>Time went to sleep: {{ sleep.time_went_to_sleep|date:'H:i e'}}</tr>
<div class="sleep-divider"></div>
<tr>
<td>Time woke in the morning: {{ sleep.time_woke_in_morning|date:'H:i e'}}</tr>
</table>
</div>
</div>


{% endblock %}
10 changes: 10 additions & 0 deletions sleep/templates/sleep/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends 'sleep/base.html' %}
{% block content %}
{% for sleep in latest_sleeps_lists %}

<p class="date">Sleep date: {{ sleep.sleep_date|date:'d-m-Y'}}</p>
<div class="sleep-divider"></div>

{% endfor %}

{% endblock %}
9 changes: 9 additions & 0 deletions sleep/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path

from . import views

app_name = 'sleep'
urlpatterns = [
path('', views.IndexView.as_view(), name='index'),
path('<int:pk>/', views.DetailView.as_view(), name='detail')
]
33 changes: 32 additions & 1 deletion sleep/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
from django.shortcuts import render
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.utils import timezone
from django.contrib.auth.decorators import login_required
from django.views import generic
from django.urls import reverse


from .models import Sleep, SleepInterruption
# Create your views here.


class IndexView(generic.ListView):
template_name = 'sleep/index.html'
context_object_name = 'latest_sleeps_list'

def get_queryset(self):
"""
Return the last seven sleeps
"""
return Sleep.objects.filter(
sleep_date__lte=timezone.now()
).order_by('-sleep_date')[:7]


class DetailView(generic.DetailView):
model = Sleep
template_name ='sleep/detail.html'

def get_queryset(self):
"""
Excludes any sleeps that haven't completed yet
"""
return Sleep.objects.filter(sleep_date__lte=timezone.now())

0 comments on commit d02a68a

Please sign in to comment.