Skip to content
GitLab
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
a165e78d
Commit
a165e78d
authored
Jul 05, 2020
by
dorothee.kueppers
Browse files
noch besserer Zwischenstand selection Seite
parent
a570f9c3
Changes
6
Hide whitespace changes
Inline
Side-by-side
templates/todo/selection_page.html
View file @
a165e78d
...
...
@@ -14,9 +14,6 @@
<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>
<ul
class=
"list-group"
>
<li
class=
"list-group-item"
id=
"chosen-todos"
>
Meine todos
</li>
...
...
@@ -27,6 +24,9 @@
{# {% endfor %}#}
</ul>
</div>
<div
class=
"row justify-content-center"
>
<input
type=
"submit"
class=
"btn btn-danger"
value=
"Auswahl speichern und loslegen!"
>
</div>
</form>
</div>
...
...
todo/forms.py
View file @
a165e78d
from
django
import
forms
from
todo.models
import
Todo
from
recurrence.fields
import
RecurrenceField
class
TodoForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Todo
exclude
=
[
'created'
,
'complete'
,
'rank'
]
exclude
=
[
'created'
,
'complete'
,
'rank'
,
'selection'
]
widgets
=
{
'text'
:
forms
.
TextInput
(
attrs
=
{
'placeholder'
:
'Küche putzen, Python lernen, Haare waschen...'
}),
# 'recurrences': RecurrenceField()
...
...
@@ -30,9 +29,18 @@ class SelectionForm(forms.Form):
min_value
=
0
,
widget
=
forms
.
NumberInput
(
attrs
=
{
'max'
:
55
,
'min'
:
0
,
'step'
:
5
,
'style'
:
'width: 150px;'
})
)
selection
=
forms
.
CharField
(
label
=
'Selection'
,
max_length
=
100
,
widget
=
forms
.
TextInput
(
attrs
=
{
'type'
:
'hidden'
,
'id'
:
'selection-hidden-input'
})
)
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
def
todos_string_to_list
(
self
):
cleaned_data
=
super
(
SelectionForm
,
self
).
clean
()
return
cleaned_data
[
'selection'
].
split
(
','
)
todo/migrations/0008_auto_20200705_0002.py
0 → 100644
View file @
a165e78d
# Generated by Django 3.0.7 on 2020-07-04 22:02
from
django.db
import
migrations
,
models
import
django.db.models.deletion
import
recurrence.fields
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'todo'
,
'0007_remove_todo_due_date'
),
]
operations
=
[
migrations
.
RemoveField
(
model_name
=
'selection'
,
name
=
'items'
,
),
migrations
.
AddField
(
model_name
=
'todo'
,
name
=
'selection'
,
field
=
models
.
ForeignKey
(
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
SET_NULL
,
to
=
'todo.Selection'
),
),
migrations
.
AlterField
(
model_name
=
'todo'
,
name
=
'recurrences'
,
field
=
recurrence
.
fields
.
RecurrenceField
(
blank
=
True
,
null
=
True
),
),
]
todo/models.py
View file @
a165e78d
...
...
@@ -4,6 +4,15 @@ from django.db import models
from
recurrence.fields
import
RecurrenceField
class
Selection
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
30
,
default
=
"name"
)
# items = models.ManyToManyField(Todo)
total_time
=
models
.
IntegerField
(
default
=
0
)
# in minutes
def
__str__
(
self
):
return
f
'
{
self
.
name
}
, total time:
{
self
.
total_time
.
__str__
()
}
'
class
Todo
(
models
.
Model
):
text
=
models
.
CharField
(
max_length
=
200
)
complete
=
models
.
BooleanField
(
default
=
False
)
...
...
@@ -11,14 +20,7 @@ class Todo(models.Model):
created
=
models
.
DateField
(
default
=
datetime
.
date
.
today
)
rank
=
models
.
IntegerField
(
default
=
1
)
recurrences
=
RecurrenceField
(
blank
=
True
,
null
=
True
)
selection
=
models
.
ForeignKey
(
Selection
,
on_delete
=
models
.
SET_NULL
,
null
=
True
)
def
__str__
(
self
):
return
self
.
text
class
Selection
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
30
,
default
=
"name"
)
items
=
models
.
ManyToManyField
(
Todo
)
total_time
=
models
.
IntegerField
(
default
=
0
)
# in minutes
def
__str__
(
self
):
return
f
'
{
self
.
name
}
, total time:
{
self
.
total_time
.
__str__
()
}
'
todo/static/js/selectionpage.js
View file @
a165e78d
let
selections
=
[];
// hide todo elements before setting timer
// $('#todo-choices').hide();
//event listener for choosing todos
$
(
'
.select-todo-grid
'
).
on
(
'
click
'
,
e
=>
{
//get node with class "select-todo-grid"
let
node
=
e
.
target
.
closest
(
"
.select-todo-grid
"
);
//get id for todo-item and add it to selections
let
id
=
node
.
lastElementChild
.
textContent
;
let
group
=
node
.
parentElement
.
id
;
switch
(
group
)
{
case
'
todo-late
'
:
selections
.
push
(
id
);
$
(
'
#selection-hidden-input
'
).
val
(
selections
.
toString
());
break
;
default
:
}
let
clonedNode
=
node
.
cloneNode
(
true
)
document
.
getElementById
(
'
chosen-todos
'
).
appendChild
(
clonedNode
);
node
.
style
.
display
=
"
none
"
;
...
...
todo/views.py
View file @
a165e78d
...
...
@@ -39,6 +39,27 @@ def add_todo(request):
def
get_selection_page
(
request
):
selection
=
Selection
()
if
request
.
method
==
'POST'
:
form
=
SelectionForm
(
request
.
POST
)
if
form
.
is_valid
():
selection
.
total_time
=
form
.
calc_total_time
()
# chosen_todos = Todo.objects.filter(pk__in=form.todos_string_to_list())
# selection.items.addAll(chosen_todos)
# selection.items.add(Todo.objects.get(id=31))
selection
.
save
()
for
id
in
form
.
todos_string_to_list
():
todo
=
Todo
.
objects
.
get
(
pk
=
id
)
todo
.
selection
=
selection
todo
.
save
()
messages
.
success
(
request
,
'Selection saved'
)
return
HttpResponseRedirect
(
reverse_lazy
(
'landing_page'
))
else
:
print
(
'Data incorrect'
)
messages
.
error
(
request
,
'Data incorrect'
)
form
=
SelectionForm
()
# für Anzeige - Anfang
todos_with_recurrence
=
Todo
.
objects
.
filter
(
complete
=
False
).
exclude
(
recurrences__exact
=
''
)
todos_without_recurrence
=
Todo
.
objects
.
filter
(
complete
=
False
).
filter
(
recurrences__exact
=
''
)
...
...
@@ -65,19 +86,6 @@ def get_selection_page(request):
todos_soon
.
append
(
recur_todo
)
# für Anzeige - Ende
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
()
content
=
{
'page_title'
:
'Leg eine Liste an'
,
'form'
:
form
,
'todos_today'
:
todos_today
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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