Fakultas Ilmu Komputer UI

Commit a28b4bef authored by Yumna Pratista's avatar Yumna Pratista
Browse files

new url + view for adding existing files

parent 4bfc7216
# Generated by Django 2.2.1 on 2019-10-10 03:40
# Generated by Django 2.2.1 on 2019-10-10 04:09
from django.db import migrations, models
import django.db.models.deletion
......
......@@ -5,7 +5,7 @@
</head>
<body>
<h1>Your To-Do list</h1>
<form method="POST" action="/lists/new">>
<form method="POST" action="/lists/{{ list.id }}/add_item">
<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />
{% csrf_token %}
</form>
......
......@@ -18,9 +18,9 @@ class HomePageTest(TestCase):
new_item = Item.objects.first()
self.assertEqual(new_item.text, 'A new list item')
def test_redirects_after_POST(self):
response = self.client.post('/lists/new', data={'item_text': 'A new list item'})
self.assertRedirects(response, '/lists/the-only-list-in-the-world/')
# def test_redirects_after_POST(self):
# response = self.client.post('/lists/new', data={'item_text': 'A new list item'})
# self.assertRedirects(response, '/lists/the-only-list-in-the-world/')
# def test_if_item_smaller_than_5(self):
# response = self.client.get('/')
......@@ -75,19 +75,25 @@ class ListAndItemModelTest(TestCase):
class ListViewTest(TestCase):
def test_uses_list_template(self):
response = self.client.get('/lists/the-only-list-in-the-world/')
list_ = List.objects.create()
response = self.client.get(f'/lists/{list_.id}/')
self.assertTemplateUsed(response, 'app/list.html')
def test_displays_all_items(self):
list_ = List.objects.create()
Item.objects.create(text='itemey 1', list = list_)
def test_displays_only_items_for_that_list(self):
correct_list = List.objects.create()
Item.objects.create(text='itemey 1', list=correct_list)
Item.objects.create(text='itemey 2', list=correct_list)
other_list = List.objects.create()
Item.objects.create(text='other list item 1', list=other_list)
Item.objects.create(text='other list item 2', list=other_list)
Item.objects.create(text='itemey 2', list = list_)
response = self.client.get('/lists/the-only-list-in-the-world/')
self.assertContains(response, 'itemey 1')
response = self.client.get(f'/lists/{correct_list.id}/')
self.assertContains(response, 'itemey 1')
self.assertContains(response, 'itemey 2')
self.assertNotContains(response, 'other list item 1')
self.assertNotContains(response, 'other list item 2')
class NewListTest(TestCase):
......@@ -100,6 +106,38 @@ class NewListTest(TestCase):
def test_redirects_after_POST(self):
response = self.client.post('/lists/new', data={'item_text': 'A new list item'})
self.assertEqual(response.status_code, 302)
self.assertEqual(response['location'], '/lists/the-only-list-in-the-world/')
self.assertRedirects(response, '/lists/the-only-list-in-the-world/')
\ No newline at end of file
new_list = List.objects.first()
self.assertRedirects(response, f'/lists/{new_list.id}/')
class NewItemTest(TestCase):
def test_can_save_a_POST_request_to_an_existing_list(self):
other_list = List.objects.create()
correct_list = List.objects.create()
self.client.post(
f'/lists/{correct_list.id}/add_item',
data={'item_text': 'A new item for an existing list'}
)
self.assertEqual(Item.objects.count(), 1)
new_item = Item.objects.first()
self.assertEqual(new_item.text, 'A new item for an existing list')
self.assertEqual(new_item.list, correct_list)
def test_redirects_to_list_view(self):
other_list = List.objects.create()
correct_list = List.objects.create()
response = self.client.post(
f'/lists/{correct_list.id}/add_item',
data={'item_text': 'A new item for an existing list'}
)
self.assertRedirects(response, f'/lists/{correct_list.id}/')
def test_passes_correct_list_to_template(self):
other_list = List.objects.create()
correct_list = List.objects.create()
response = self.client.get(f'/lists/{correct_list.id}/')
self.assertEqual(response.context['list'], correct_list)
\ No newline at end of file
......@@ -14,11 +14,17 @@ def home_page(request):
# state = "oh tidak"
# return render(request, 'app/home.html', {'items':items, 'state':state})
def view_list(request):
items = Item.objects.all()
return render(request, 'app/list.html', {'items': items})
def view_list(request, list_id):
list_ = List.objects.get(id=list_id)
items = Item.objects.filter(list=list_)
return render(request, 'app/list.html', {'items': items, 'list':list_})
def new_list(request):
list_ = List.objects.create()
Item.objects.create(text=request.POST['item_text'], list=list_)
return redirect('/lists/the-only-list-in-the-world/')
\ No newline at end of file
return redirect(f'/lists/{list_.id}/')
def add_item(request, list_id):
list_ = List.objects.get(id=list_id)
Item.objects.create(text=request.POST['item_text'], list=list_)
return redirect(f'/lists/{list_.id}/')
\ No newline at end of file
......@@ -56,8 +56,8 @@ class NewVisitorTest(LiveServerTestCase):
time.sleep(5)
# The page updates again, and now shows both items on her list
self.wait_for_row_in_list_table('1: Buy peacock feathers')
self.wait_for_row_in_list_table('2: Use peacock feathers to make a fly')
self.wait_for_row_in_list_table('1: Buy peacock feathers')
# Edith wonders whether the site will remember her list. Then she sees
# that the site has generated a unique URL for her -- there is some
......
......@@ -4831,3 +4831,117 @@ JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't fin
6
###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv
 
1570680953447 mozrunner::runner INFO Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\YUMNAP~1\\AppData\\Local\\Temp\\rust_mozprofile2sj63h"
1570680957710 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1570680957711 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry
1570680957712 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1570680957712 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
1570680965628 Marionette INFO Listening on port 50095
1570680966067 Marionette WARN TLS certificate errors will be ignored for this session
1570680988651 Marionette INFO Stopped listening on port 50095
[Parent 6476, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 18492, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 18492,[Child 9576, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 9576,
###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost
[GPU 4048, Ch
###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv
1570680996433 mozrunner::runner INFO Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\YUMNAP~1\\AppData\\Local\\Temp\\rust_mozprofileJqCKGB"
1570680998460 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1570680998460 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry
1570680998460 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1570680998460 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
1570681003834 Marionette INFO Listening on port 50165
1570681004262 Marionette WARN TLS certificate errors will be ignored for this session
1570681010331 Marionette INFO Stopped listening on port 50165
[Parent 20284, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 20376, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 20376, Chrome_Chi[Parent 20284, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 11108, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 11108, Chro
###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost
[GPU 6716,
###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv
1570681018840 mozrunner::runner INFO Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\YUMNAP~1\\AppData\\Local\\Temp\\rust_mozprofile9HaGDI"
1570681021190 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1570681021190 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry
1570681021190 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1570681021190 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
1570681025213 Marionette INFO Listening on port 50203
1570681025676 Marionette WARN TLS certificate errors will be ignored for this session
1570681031904 Marionette INFO Stopped listening on port 50203
[Child 12128, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 121[Parent 10540, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost
[GPU 1
###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv
1570681170438 mozrunner::runner INFO Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\YUMNAP~1\\AppData\\Local\\Temp\\rust_mozprofilejCLcnh"
1570681171681 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1570681171682 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry
1570681171682 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1570681171682 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
1570681176071 Marionette INFO Listening on port 50254
1570681176162 Marionette WARN TLS certificate errors will be ignored for this session
1570681197882 Marionette INFO Stopped listening on port 50254
[Parent 1416, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 10660, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 10660, Chrome_ChildThread] WA[Parent 1416, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 9844, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 9844,
###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost
[GPU 2296, Ch
###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv
1570681204347 mozrunner::runner INFO Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\YUMNAP~1\\AppData\\Local\\Temp\\rust_mozprofileoXTyMX"
1570681205488 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1570681205488 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry
1570681205488 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1570681205489 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
1570681209343 Marionette INFO Listening on port 50289
1570681209572 Marionette WARN TLS certificate errors will be ignored for this session
1570681215583 Marionette INFO Stopped listening on port 50289
[Parent 15428, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 14112, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 14112[Parent 15428, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 3184, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 3184, C[Parent 15428, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 16724, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 16724,
###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost
[GPU 1804,
###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv
1570681225628 mozrunner::runner INFO Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\YUMNAP~1\\AppData\\Local\\Temp\\rust_mozprofileBZPSx1"
1570681226820 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1570681226820 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry
1570681226820 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1570681226820 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
1570681231112 Marionette INFO Listening on port 50323
1570681231356 Marionette WARN TLS certificate errors will be ignored for this session
1570681237366 Marionette INFO Stopped listening on port 50323
[Child 13752, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 137[Parent 1088, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 5428, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 5428, Ch[Parent 1088, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 8876, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 887
###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost
[GPU 1674
###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv
......@@ -16,10 +16,11 @@ Including another URLconf
from django.contrib import admin
from django.urls import path
from django.conf.urls import url
from app_homepage import views
from app_homepage import views
urlpatterns = [
url(r'^$', views.home_page, name='home'),
url(r'^lists/new$', views.new_list, name='new_list'),
url(r'^lists/the-only-list-in-the-world/$', views.view_list, name='view_list'),
url(r'^lists/(\d+)/$', views.view_list, name='view_list'),
url(r'^lists/(\d+)/add_item$', views.add_item, name='add_item'),
]
\ No newline at end of file
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