Commit 0e58a149 authored by James Esguerra's avatar James Esguerra

Added "Mark as done" button to today view

parent 61f8a525
......@@ -27,7 +27,7 @@ def ShowHome(request):
def ShowProfile(request):
form = UserForm()
if User.objects.count() == 0:
user = User(
user = User( #creates the default model instance for the User Model
nickname='Your nickname',
bio='A short description about yourself.',
profile_photo='default.jpg'
......@@ -46,33 +46,28 @@ def ShowProfile(request):
if form.is_valid():
form.save()
return redirect('profile')
return render(request, 'profile.html', context)
def ShowEditNickname(request):
user = User.objects.get(pk=1)
form = NicknameForm(instance=user)
if request.method == 'POST':
form = NicknameForm(request.POST, instance=user)
if form.is_valid():
form.save()
return redirect('profile')
return render(request, 'edit_nickname.html', {'form': form})
def ShowEditBio(request):
user = User.objects.get(pk=1)
form = BioForm(instance=user)
if request.method == 'POST':
form = BioForm(request.POST, instance=user)
if form.is_valid():
form.save()
return redirect('profile')
return render(request, 'edit_bio.html', {'form': form})
......@@ -88,22 +83,18 @@ def ShowAddKey(request):
if form.is_valid():
form.save()
return redirect('key')
return render(request, 'add_key.html', {'form': form})
def ShowThisWeek(request):
item_list = list(ItemsThisWeek.objects.all())
if request.method == 'POST':
for i in request.POST.keys():
name = i
name = i # i is equal to the 'name' from request.POST
for item in item_list:
if str(item.id) == name:
item.key_type.key_name = 'Task done'
break
return render(request, 'this_week.html', {'item_list': item_list})
......@@ -114,20 +105,17 @@ def ShowAddItemTW(request):
if form.is_valid():
form.save()
return redirect('this_week')
return render(request, 'add_itemTW.html', {'form': form})
def ShowEditItemTW(request, pk):
item = ItemsThisWeek.objects.get(id=pk)
form = ItemsThisWeekForm(instance=item)
if request.method == 'POST':
form = ItemsThisWeekForm(request.POST, instance=item)
if form.is_valid():
form.save()
return redirect('this_week')
return render(request, 'edit_itemTW.html', {'form': form})
......@@ -136,12 +124,18 @@ def ShowDeleteItemTW(request, pk):
item = ItemsThisWeek.objects.get(id=pk)
item.delete()
return redirect('this_week')
return render(request, 'delete_itemTW.html')
def ShowToday(request):
item_list = list(ItemsToday.objects.all())
if request.method == 'POST':
for i in request.POST.keys():
name = i # i is equal to the 'name' from request.POST
for item in item_list:
if str(item.id) == name:
item.key_type.key_name = 'Task done'
break
return render(request, 'today.html', {'item_list': item_list})
......@@ -152,20 +146,17 @@ def ShowAddItemT(request):
if form.is_valid():
form.save()
return redirect('today')
return render(request, 'add_itemT.html', {'form': form})
def ShowEditItemT(request, pk):
item = ItemsToday.objects.get(id=pk)
form = ItemsTodayForm(instance=item)
if request.method == 'POST':
form = ItemsTodayForm(request.POST, instance=item)
if form.is_valid():
form.save()
return redirect('today')
return render(request, 'edit_itemT.html', {'form': form})
......@@ -174,5 +165,4 @@ def ShowDeleteItemT(request, pk):
item = ItemsToday.objects.get(id=pk)
item.delete()
return redirect('today')
return render(request, 'delete_itemT.html')
......@@ -11,16 +11,17 @@
<h2>04.14.WED</h2>
<br>
{% for item in item_list %}
<p>
<form method='POST'>
<b>{{ item.key_type }}:</b> {{ item.details }}
<a href='{% url 'edit_itemT' item.pk %}'><button type='button'> Edit </button></a>
<a href='{% url 'delete_itemT' item.pk %}'><button type='button'> Delete </button></a>
{% if item.key_type.key_name == 'Task' %}
<input type='submit' name='Submit' method='POST' value='Mark as done'>
{% csrf_token %}
<input type='submit' name='{{ item.id }}' value='Mark as done'/>
{% endif %}
<p>
</form>
{% endfor %}
<a href='{% url 'add_itemT' %}'><button type='button'> Add Item </button></a>
</div>
</div>
{% endblock %}
Markdown is supported
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