Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Küppers, Dorothee
oos_2020_todo
Commits
fb40149f
Commit
fb40149f
authored
Jul 01, 2020
by
dorothee.kueppers
Browse files
Ein kleiner Fortschritt: Selection kann angelegt werden
parent
d775b86c
Changes
9
Hide whitespace changes
Inline
Side-by-side
db.sqlite3
View file @
fb40149f
No preview for this file type
oos_2020_todo/urls.py
View file @
fb40149f
...
...
@@ -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'
),
]
templates/todo/selection_page.html
View file @
fb40149f
{% extends 'todo/base.html' %}
{% load static %}
{% load bootstrap4 %}
{% block content %}
<div
class=
"row"
>
<div
class=
"col-sm todo-box"
>
<div
class=
"row justify-content-center"
>
<h3>
Wie viel Zeit hast du?
</h3>
<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"
>
{% bootstrap_form form %}
</div>
<div
class=
"row justify-content-center"
>
<input
type=
"submit"
class=
"btn btn-danger"
value=
"submit"
>
</div>
</div>
<div
class=
"row justify-content-center"
>
<input
type=
"time"
/>
</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>
...
...
todo/forms.py
0 → 100644
View file @
fb40149f
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
todo/migrations/0001_initial.py
0 → 100644
View file @
fb40149f
# 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'
)),
],
),
]
todo/migrations/0002_remove_selection_name.py
0 → 100644
View file @
fb40149f
# 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'
,
),
]
todo/migrations/0003_selection_name.py
0 → 100644
View file @
fb40149f
# 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
),
),
]
todo/models.py
View file @
fb40149f
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
.
Time
Field
(
default
=
0
)
total_time
=
models
.
Integer
Field
(
default
=
0
)
# in minutes
def
__str__
(
self
):
return
f
'
{
self
.
name
}
, duration:
{
self
.
total_time
.
__str__
()
}
'
todo/views.py
View file @
fb40149f
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
})
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment