-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated html and added views for sleep details on frontend
- Loading branch information
1 parent
41b9932
commit d02a68a
Showing
9 changed files
with
88 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |