Commit fb40149f authored by dorothee.kueppers's avatar dorothee.kueppers
Browse files

Ein kleiner Fortschritt: Selection kann angelegt werden

parent d775b86c
No preview for this file type
......@@ -21,6 +21,6 @@ from todo.views import get_landing_page, get_selection_page
urlpatterns = [
path('admin/', admin.site.urls),
path('start/', get_landing_page, name='landing_page'),
path('', get_landing_page),
path('selection/', get_selection_page, name='get_selection_page'),
path('', get_landing_page, name='landing_page'),
path('selection/', get_selection_page, name='selection_page'),
]
{% extends 'todo/base.html' %}
{% load static %}
{% load bootstrap4 %}
{% block content %}
<div class="row">
<form action="" enctype="multipart/form-data" method="POST">
{% csrf_token %}
<div class="col-sm todo-box">
<div class="row justify-content-center">
<h3>Wie viel Zeit hast du?</h3>
</div>
<div class="row justify-content-center">
<input type="time"/>
{% bootstrap_form form %}
</div>
<div class="row justify-content-center">
<input type="submit" class="btn btn-danger" value="submit">
</div>
</div>
</form>
<div class="col-sm todo-box">
<div class="row justify-content-center">
<img src="{% static "todo/mole.png" %}" width="100px" height="100px"/>
<img alt="some image" src="{% static "todo/mole.png" %}" width="100px" height="100px"/>
</div>
</div>
</div>
......
from django.forms import *
from todo.models import *
from django import forms
class SelectionForm(forms.Form):
duration_hours = forms.IntegerField(
label='Stunden',
max_value=24,
min_value=0,
widget=forms.NumberInput(attrs={'max': 24, 'min': 0, 'style': 'width: 200px;'})
)
duration_minutes = forms.IntegerField(
label='Minuten',
max_value=59,
min_value=0,
widget=forms.NumberInput(attrs={'max': 55, 'min': 0, 'step': 5, 'style': 'width: 200px;'})
)
def calc_total_time(self):
cleaned_data = super(SelectionForm, self).clean()
hours = cleaned_data['duration_hours']
minutes = cleaned_data['duration_minutes']
return hours * 60 + minutes
# Generated by Django 3.0.7 on 2020-07-01 18:05
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Todo',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('text', models.CharField(max_length=200)),
('complete', models.BooleanField(default=False)),
],
),
migrations.CreateModel(
name='Selection',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(default='name', max_length=30)),
('total_time', models.TimeField(default=0)),
('items', models.ManyToManyField(to='todo.Todo')),
],
),
]
# Generated by Django 3.0.7 on 2020-07-01 18:20
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('todo', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='selection',
name='name',
),
]
# Generated by Django 3.0.7 on 2020-07-01 18:21
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('todo', '0002_remove_selection_name'),
]
operations = [
migrations.AddField(
model_name='selection',
name='name',
field=models.CharField(default='name', max_length=30),
),
]
from django.db import models
# Create your models here.
class Todo(models.Model):
text=models.CharField(max_length=200)
complete=models.BooleanField(default=False)
text = models.CharField(max_length=200)
complete = models.BooleanField(default=False)
def __str__(self):
return self.text
class Selection(models.Model):
name = models.CharField(max_length=30)
name = models.CharField(max_length=30, default="name")
items = models.ManyToManyField(Todo)
total_time = models.TimeField(default=0)
total_time = models.IntegerField(default=0) # in minutes
def __str__(self):
return f'{self.name} , duration: {self.total_time.__str__()}'
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.contrib import messages
from django.urls import reverse_lazy
from todo.forms import *
from todo.models import *
def get_landing_page(request):
todo_list = Todo.objects.order_by('id')
context ={'todo_list' : todo_list}
return render(request, 'todo/landing_page.html', {'page_title':'Feierabend!'})
context = {'todo_list': todo_list}
return render(request, 'todo/landing_page.html', {'page_title': 'Feierabend!'})
def get_selection_page(request):
selection = Selection()
return render(request, 'todo/selection_page.html', {'page_title': 'Leg eine Liste an!',
'selection': selection})
if request.method == 'POST':
form = SelectionForm(request.POST)
if form.is_valid():
selection.total_time = form.calc_total_time()
selection.save()
messages.success(request, 'Selection saved')
return HttpResponseRedirect(reverse_lazy('landing_page'))
else:
print('Data incorrect')
messages.error(request, 'Data incorrect')
else:
form = SelectionForm()
return render(request, 'todo/selection_page.html', {'page_title': 'Leg eine Liste an!',
'form': form})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment