mirror of https://github.com/snachodog/mybuddy.git
Make Timer instance.start field editable.
This commit is contained in:
parent
03dc139b0e
commit
5afc55ca31
|
@ -128,7 +128,13 @@ class SleepForm(forms.ModelForm):
|
||||||
class TimerForm(forms.ModelForm):
|
class TimerForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Timer
|
model = Timer
|
||||||
fields = ['name']
|
fields = ['name', 'start']
|
||||||
|
widgets = {
|
||||||
|
'start': forms.DateTimeInput(attrs={
|
||||||
|
'class': 'datepicker-input',
|
||||||
|
'data-target': '#datetimepicker_start',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.user = kwargs.pop('user')
|
self.user = kwargs.pop('user')
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.6 on 2017-10-28 16:57
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.utils.timezone
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='timer',
|
||||||
|
name='start',
|
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='Start Time'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -141,7 +141,11 @@ class Sleep(models.Model):
|
||||||
class Timer(models.Model):
|
class Timer(models.Model):
|
||||||
model_name = 'timer'
|
model_name = 'timer'
|
||||||
name = models.CharField(max_length=255, null=True, blank=True)
|
name = models.CharField(max_length=255, null=True, blank=True)
|
||||||
start = models.DateTimeField(auto_now_add=True)
|
start = models.DateTimeField(
|
||||||
|
default=timezone.now,
|
||||||
|
blank=False,
|
||||||
|
verbose_name='Start Time'
|
||||||
|
)
|
||||||
end = models.DateTimeField(blank=True, null=True, editable=False)
|
end = models.DateTimeField(blank=True, null=True, editable=False)
|
||||||
duration = models.DurationField(null=True, editable=False)
|
duration = models.DurationField(null=True, editable=False)
|
||||||
active = models.BooleanField(default=True, editable=False)
|
active = models.BooleanField(default=True, editable=False)
|
||||||
|
|
|
@ -20,4 +20,14 @@
|
||||||
<h1>Start Timer</h1>
|
<h1>Start Timer</h1>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% include 'babybuddy/form.html' %}
|
{% include 'babybuddy/form.html' %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block javascript %}
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(function () {
|
||||||
|
$('#datetimepicker_start').datetimepicker({
|
||||||
|
format: 'YYYY-MM-DD HH:mm:ss'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -1,10 +1,11 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
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.contrib.auth.models import User
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.test import Client as HttpClient
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
from faker import Factory
|
from faker import Factory
|
||||||
|
|
||||||
|
@ -89,9 +90,24 @@ class FormsTestCase(TestCase):
|
||||||
def test_timer_forms(self):
|
def test_timer_forms(self):
|
||||||
timer = models.Timer.objects.create(user=self.user)
|
timer = models.Timer.objects.create(user=self.user)
|
||||||
timer.save()
|
timer.save()
|
||||||
# Post to test custom get_success_url() method.
|
|
||||||
page = self.c.post('/timer/{}/edit/'.format(timer.id), {'name': 'New'})
|
params = {
|
||||||
|
'name': 'New',
|
||||||
|
'start': timer.start.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
}
|
||||||
|
page = self.c.post('/timer/{}/edit/'.format(timer.id), params)
|
||||||
self.assertEqual(page.status_code, 302)
|
self.assertEqual(page.status_code, 302)
|
||||||
|
timer.refresh_from_db()
|
||||||
|
self.assertEqual(timer.name, params['name'])
|
||||||
|
|
||||||
|
# Test changing the timer start time.
|
||||||
|
start_time = timer.start - timezone.timedelta(hours=1)
|
||||||
|
params['start'] = timezone.localtime(start_time).strftime(
|
||||||
|
'%Y-%m-%d %H:%M:%S')
|
||||||
|
page = self.c.post('/timer/{}/edit/'.format(timer.id), params)
|
||||||
|
self.assertEqual(page.status_code, 302)
|
||||||
|
timer.refresh_from_db()
|
||||||
|
self.assertEqual(timer.start, start_time)
|
||||||
|
|
||||||
def test_tummytime_forms(self):
|
def test_tummytime_forms(self):
|
||||||
params = {
|
params = {
|
||||||
|
|
Loading…
Reference in New Issue