diff --git a/sleep/admin.py b/sleep/admin.py index dd81c06..b7f40af 100644 --- a/sleep/admin.py +++ b/sleep/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin # Register your models here. -from .models import Sleep, SleepInterruption +from .models import Participant, Sleep, SleepInterruption class SleepInterruptionInline(admin.TabularInline): model = SleepInterruption @@ -20,3 +20,4 @@ class SleepAdmin(admin.ModelAdmin): search_fields = ['sleep_date'] admin.site.register(Sleep, SleepAdmin) +admin.site.register(Participant) diff --git a/sleep/migrations/0002_auto_20180203_1953.py b/sleep/migrations/0002_auto_20180203_1953.py new file mode 100644 index 0000000..243b556 --- /dev/null +++ b/sleep/migrations/0002_auto_20180203_1953.py @@ -0,0 +1,33 @@ +# Generated by Django 2.0.2 on 2018-02-03 19:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sleep', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='sleep', + name='time_start_preparing_for_sleep', + field=models.DateTimeField(blank=True, null=True, verbose_name='time started getting ready for bed'), + ), + migrations.AlterField( + model_name='sleep', + name='time_went_into_bed', + field=models.DateTimeField(blank=True, null=True, verbose_name='time in bed'), + ), + migrations.AlterField( + model_name='sleep', + name='time_went_to_sleep', + field=models.DateTimeField(blank=True, null=True, verbose_name='time asleep'), + ), + migrations.AlterField( + model_name='sleep', + name='time_woke_in_morning', + field=models.DateTimeField(blank=True, verbose_name='time woke in morning'), + ), + ] diff --git a/sleep/migrations/0003_auto_20180203_1954.py b/sleep/migrations/0003_auto_20180203_1954.py new file mode 100644 index 0000000..08cbff7 --- /dev/null +++ b/sleep/migrations/0003_auto_20180203_1954.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.2 on 2018-02-03 19:54 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sleep', '0002_auto_20180203_1953'), + ] + + operations = [ + migrations.AlterField( + model_name='sleep', + name='time_woke_in_morning', + field=models.DateTimeField(blank=True, null=True, verbose_name='time woke in morning'), + ), + ] diff --git a/sleep/migrations/0004_participant.py b/sleep/migrations/0004_participant.py new file mode 100644 index 0000000..67bb179 --- /dev/null +++ b/sleep/migrations/0004_participant.py @@ -0,0 +1,26 @@ +# Generated by Django 2.0.2 on 2018-02-05 23:11 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('sleep', '0003_auto_20180203_1954'), + ] + + operations = [ + migrations.CreateModel( + name='Participant', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('individual_name', models.CharField(blank=True, max_length=100, null=True)), + ('age', models.IntegerField(blank=True, max_length=3, null=True)), + ('favourite_color', models.CharField(blank=True, max_length=60, null=True)), + ('login_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/sleep/migrations/0005_auto_20180205_2312.py b/sleep/migrations/0005_auto_20180205_2312.py new file mode 100644 index 0000000..081e6b4 --- /dev/null +++ b/sleep/migrations/0005_auto_20180205_2312.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.2 on 2018-02-05 23:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sleep', '0004_participant'), + ] + + operations = [ + migrations.AlterField( + model_name='participant', + name='age', + field=models.IntegerField(blank=True, null=True), + ), + ] diff --git a/sleep/models.py b/sleep/models.py index 9dd9d9f..9cc81f6 100644 --- a/sleep/models.py +++ b/sleep/models.py @@ -5,16 +5,46 @@ # Create your models here. +class Participant(models.Model): + login_user = models.ForeignKey ('auth.User', on_delete=models.CASCADE) + individual_name = models.CharField (max_length=100, blank=True, null=True) + age = models.IntegerField (blank=True, null=True) + favourite_color = models.CharField (max_length=60, blank=True, null=True) +# TODO: Generate random unique_name that can be shared to discuss participant + """ + def generate_unique_name(self): + with open('/usr/share/dict/words') as f: + words = [word.strip() for word in f] + random_name = ' '.join(choice(words) for i in range(4)) + return random_name + + self.unique_name = generate_unique_name() + """ + def __str__(self): + return str(self.login_user) + class Sleep(models.Model): sleep_date = models.DateField('sleep date') - time_start_preparing_for_sleep = models.DateTimeField('time started getting ready for bed') - time_went_into_bed = models.DateTimeField('time in bed') - time_went_to_sleep = models.DateTimeField('time asleep') + time_start_preparing_for_sleep = models.DateTimeField('time started getting ready for bed', blank=True, null=True) + time_went_into_bed = models.DateTimeField('time in bed', blank=True, null=True) + time_went_to_sleep = models.DateTimeField('time asleep', blank=True, null=True) - time_woke_in_morning = models.DateTimeField('time woke in morning') + time_woke_in_morning = models.DateTimeField('time woke in morning', blank=True, null=True) + def check_time_went_to_sleep_is_before_time_woke_in_morning(self): + """ + Checks that time went to sleep is before waking time in the morning + + """ + # TODO: ? add value error check as well + if self.time_woke_in_morning < self.time_went_to_sleep: + return False + else: + return True + check_time_went_to_sleep_is_before_time_woke_in_morning.boolean = True + #TODO: Run function to check and raise error if entered incorrectly def total_time_asleep(self): """ @@ -22,11 +52,22 @@ def total_time_asleep(self): compared to time woke in the time woke in morning This does NOT include any interruptions. """ - wake = self.time_woke_in_morning - sleep = self.time_went_to_sleep - timediff = wake - sleep + # TODO: Add in calculation of sum of Sleep interruptions ? need to add time back to sleep + if ((self.time_went_to_sleep != None) and (self.time_woke_in_morning != None)): + + wake = self.time_woke_in_morning + sleep = self.time_went_to_sleep + timediff = wake - sleep + if (timediff > datetime.timedelta(0) ): + return timediff + else: + return ValueError, "Time waking must be AFTER time going to sleep" + else: + response = "Missing data: Please make sure time went to sleep and time woke in morning are entered" + return response - return timediff + def __str__(self): + return str(self.sleep_date) class SleepInterruption(models.Model): @@ -38,3 +79,5 @@ class SleepInterruption(models.Model): intervention.short_description= 'What intervention happened?' time_taken_to_sleep = models.IntegerField(default=10) + + # TODO: Missing variable to track total amount of time taken to get to sleep diff --git a/sleep/static/templates/css/sleep.css b/sleep/static/templates/css/sleep.css new file mode 100644 index 0000000..f88cba6 --- /dev/null +++ b/sleep/static/templates/css/sleep.css @@ -0,0 +1,60 @@ +.page-header { + background-color: teal; + margin-top: 0; + padding: 20px 20px 20px 40px; +} + +.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 { + margin-left: 40px; +} + +h1, h2, h3, h4 { + font-family: 'lobster', cursive; +} + +.date { + color: #828282; +} + +.save { + float: right; +} + +.post-form textarea, .post-form input { + width: 100%; +} + +.top-menu, .top-menu:hover, .top-menu:visited { + color: #ffffff; + float: right; + font-size: 26pt; + margin-right: 20px; +} + +.post { + margin-bottom: 70px; +} + +.post h1 a, .post h1 a:visited { + color: #000000; +} + +h1 a { + color: #FCA205; + font-family: 'Lobster'; + transition: .5; +} + +body { + padding-left: 15px; +} + +.comment { + margin: 20px 0px 20px 20px; +} diff --git a/sleep/static/templates/sleep/base.html b/sleep/static/templates/sleep/base.html new file mode 100644 index 0000000..36e7a30 --- /dev/null +++ b/sleep/static/templates/sleep/base.html @@ -0,0 +1,27 @@ +{% load staticfiles %} + + +
+