Skip to content

Commit

Permalink
Added hidden field
Browse files Browse the repository at this point in the history
  • Loading branch information
Nasef Khan committed Sep 4, 2018
1 parent 76890a8 commit 9bf6079
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/task_list/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ class AddTaskForm(forms.ModelForm):
"""Form for adding a Task"""
class Meta:
model = Task
fields = ("title", "description")
fields = ("title", "description", "is_hidden")
26 changes: 26 additions & 0 deletions src/task_list/migrations/0004_auto_20180904_2232.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('task_list', '0003_auto_20170216_1221'),
]

operations = [
migrations.AddField(
model_name='task',
name='is_hidden',
field=models.BooleanField(default=False),
preserve_default=True,
),
migrations.AlterField(
model_name='task',
name='description',
field=models.TextField(max_length=20480),
preserve_default=True,
),
]
3 changes: 2 additions & 1 deletion src/task_list/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ class Task(models.Model):
"""Task Datamodel"""
user = models.ForeignKey(User, related_name="creator")
title = models.CharField(max_length=128)
description = models.TextField()
description = models.TextField(max_length=20480)
created = models.DateTimeField(auto_now_add=True, blank=True)
is_done = models.BooleanField(default=False)
status_changed_by = models.ForeignKey(User, default=None, null=True,
blank=True,
related_name="changed_by")
is_hidden = models.BooleanField(default=False)

def __unicode__(self):
return self.title
9 changes: 9 additions & 0 deletions src/task_list/templates/add_task.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ <h2 class="form-signin-heading">Add Task</h2>
</p>
</div>

<div class="radio">
<label><input type="radio" name="is_hidden" value="0" checked="checked">Visible to others</label>
</div>

<div class="radio">
<label><input type="radio" name="is_hidden" value="1">Invisible to others</label>
</div>


{% if form_errors %}
<p>{{form_errors}}</p>
{% endif %}
Expand Down
20 changes: 20 additions & 0 deletions src/task_list/templates/edit_task.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ <h2 class="form-signin-heading">Edit Task</h2>
</div>
{% endif %}

<div></div>

{% if task.is_hidden %}
<div class="radio">
<label><input type="radio" name="is_hidden" value="0">Visible to others</label>
</div>

<div class="radio">
<label><input type="radio" name="is_hidden" value="1" checked="checked">Invisible to others</label>
</div>
{%else %}
<div class="radio">
<label><input type="radio" name="is_hidden" value="0" checked="checked">Visible to others</label>
</div>

<div class="radio">
<label><input type="radio" name="is_hidden" value="1">Invisible to others</label>
</div>
{% endif %}

{% if form_errors %}
<p>{{form_errors}}</p>
{% endif %}
Expand Down
7 changes: 5 additions & 2 deletions src/task_list/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def task_list(request):

if filter_completed:
user_tasks.append({"user": user, "tasks": Task.objects
.filter(user=user, is_done=False)})
.filter(user=user, is_done=False, is_hidden=False)})
else:
user_tasks.append({"user": user, "tasks": Task.objects
.filter(user=user)})
.filter(user=user, is_hidden=False)})
return render(request, "index.html", {"user_tasks": user_tasks,
"filter_completed": filter_completed})

Expand Down Expand Up @@ -113,6 +113,7 @@ def add_task(request):
if request.method == "POST":
task_form = AddTaskForm(data=request.POST)
if task_form.is_valid():
import ipdb; ipdb.set_trace()
task = task_form.save(commit=False)
task.user = request.user
task.save()
Expand Down Expand Up @@ -150,7 +151,9 @@ def edit_task(request, task_id):
task = task_form.save(commit=False)
# Get radio button values from POST data as we're re-using the
# AddTaskForm
import ipdb; ipdb.set_trace()
task.is_done = True if int(request.POST["task_status"]) else False
task.is_hidden = True if not int(request.POST["is_hidden"]) else False
task.save()
task_edited = True
else:
Expand Down

0 comments on commit 9bf6079

Please sign in to comment.