diff --git a/functional_tests/__pycache__/base.cpython-38.pyc b/functional_tests/__pycache__/base.cpython-38.pyc index 11a3958d80ba6f5832b5886830e62cdde4a4196f..f7e6983780b5a8120870e4316e2f1174e2a58820 100644 Binary files a/functional_tests/__pycache__/base.cpython-38.pyc and b/functional_tests/__pycache__/base.cpython-38.pyc differ diff --git a/functional_tests/__pycache__/test_list_item_validation.cpython-38.pyc b/functional_tests/__pycache__/test_list_item_validation.cpython-38.pyc index 9238b98c92eb623d974e52f9733a53d33a8ff0c1..02d94cdcfba46af1242205265bd60b148abd9568 100644 Binary files a/functional_tests/__pycache__/test_list_item_validation.cpython-38.pyc and b/functional_tests/__pycache__/test_list_item_validation.cpython-38.pyc differ diff --git a/lists/__pycache__/models.cpython-38.pyc b/lists/__pycache__/models.cpython-38.pyc index b7fec9e670e052c9ae2a8eff0df2774ca09f7d8d..0f82ec9bf001a8dd922d4b624d0882f40b59ed26 100644 Binary files a/lists/__pycache__/models.cpython-38.pyc and b/lists/__pycache__/models.cpython-38.pyc differ diff --git a/lists/__pycache__/views.cpython-38.pyc b/lists/__pycache__/views.cpython-38.pyc index 5a803dfc2b75600d004059d438df3ee50b66d17a..ffa0cd182ad3db3e663a231f183559267de1ab6e 100644 Binary files a/lists/__pycache__/views.cpython-38.pyc and b/lists/__pycache__/views.cpython-38.pyc differ diff --git a/lists/templates/list.html b/lists/templates/list.html index 6df7ceaeefa0d9fa275175bf919c3eb1612c1321..81facb5d87de222fd119902e522372447f21a3af 100644 --- a/lists/templates/list.html +++ b/lists/templates/list.html @@ -1,18 +1,17 @@ + {% extends 'base.html' %} -{% block header_text %}To-Do list{% endblock %} + +{% block header_text %}Your To-Do list{% endblock %} + {% block form_action %}/lists/{{ list.id }}/add_item{% endblock %} + {% block table %} - + {{ comment }} +
{% for item in list.item_set.all %} - + {% endfor %} -
{{ forloop.counter }}: {{ item.text }}
{{ forloop.counter }}: {{ item.text }}
- {% if list.item_set.all|length < 1 %} -

yey, waktunya berlibur

- {% elif list.item_set.all|length > 0 and items|length < 5 %} -

sibuk tapi santai

- {% else %} -

oh tidak

- {% endif %} + + {% endblock %} diff --git a/lists/tests/__pycache__/__init__.cpython-38.pyc b/lists/tests/__pycache__/__init__.cpython-38.pyc index ae6c3e1154dfe7f2ef567703d906bcc5bd93fcab..614573ec4d6f8e827170e02aac44d09e0638be5e 100644 Binary files a/lists/tests/__pycache__/__init__.cpython-38.pyc and b/lists/tests/__pycache__/__init__.cpython-38.pyc differ diff --git a/lists/tests/__pycache__/test_models.cpython-38.pyc b/lists/tests/__pycache__/test_models.cpython-38.pyc index 3567afd232eee1185e4598ffefa134c42e793675..6b23394a539cc7852787000f675c59efbf27fb56 100644 Binary files a/lists/tests/__pycache__/test_models.cpython-38.pyc and b/lists/tests/__pycache__/test_models.cpython-38.pyc differ diff --git a/lists/tests/__pycache__/test_views.cpython-38.pyc b/lists/tests/__pycache__/test_views.cpython-38.pyc index 7e58641e916623dc4b53f05300546ecb1182157b..843a94aa48818311c6328257e91349968004d643 100644 Binary files a/lists/tests/__pycache__/test_views.cpython-38.pyc and b/lists/tests/__pycache__/test_views.cpython-38.pyc differ diff --git a/lists/tests/test_views.py b/lists/tests/test_views.py index e460908944a4f1e42eb671c77097c06a01cfe3dc..fc5310a6082acc8183fa8276c33fbfd5addd42f5 100644 --- a/lists/tests/test_views.py +++ b/lists/tests/test_views.py @@ -5,6 +5,7 @@ from django.http import HttpRequest from lists.views import home_page from lists.models import Item +from lists.views import count class HomePageTest(TestCase): @@ -13,17 +14,17 @@ class HomePageTest(TestCase): self.assertEqual(found.func, home_page) def test_home_page_returns_correct_html(self): - request = HttpRequest() - response = home_page(request) - html = response.content.decode('utf8') - self.assertTrue(html.startswith('')) - self.assertIn('To-Do lists', html) + request = HttpRequest() + response = home_page(request) + html = response.content.decode('utf8') + self.assertTrue(html.startswith('')) + self.assertIn('To-Do lists', html) self.assertTrue(html.endswith('')) def test_uses_home_template(self): response = self.client.get('/') self.assertTemplateUsed(response, 'home.html') - + def test_can_save_a_POST_request(self): response = self.client.post('/', data={'item_text': 'A new list item'}) self.assertEqual(Item.objects.count(), 1) @@ -33,4 +34,18 @@ class HomePageTest(TestCase): self.assertEqual(response['location'], '/') def test_only_saves_items_when_necessary(self): self.client.get('/') - self.assertEqual(Item.objects.count(), 0) \ No newline at end of file + self.assertEqual(Item.objects.count(), 0) + +class GenerateCommentTest(TestCase): + + def test_0(self): + result = count(0) + self.assertEqual(result, 'yey, waktunya berlibur') + + def test_1(self): + result = count(1) + self.assertEqual(result, 'sibuk tapi santai') + + def test_5(self): + result = count(5) + self.assertEqual(result, 'oh tidak') diff --git a/lists/views.py b/lists/views.py index 396d6505817e2e4394f79d6daa6a035a0ff00cd1..2c276e2136de98d52c4cb6402971061662049eaf 100644 --- a/lists/views.py +++ b/lists/views.py @@ -2,9 +2,21 @@ from django.shortcuts import redirect, render from lists.models import Item from lists.models import Item, List -def view_list(request, list_id): +def home_page(request): + return render(request, 'home.html') + +def view_list(request, list_id, error=''): list_ = List.objects.get(id=list_id) - return render(request, 'list.html', {'list': list_}) + items = Item.objects.filter(list=list_) + + if len(items) > 4: + comment = 'oh tidak' + elif len(items) >= 1: + comment = 'sibuk tapi santai' + else: + comment = 'yey, waktunya berlibur' + + return render(request, 'list.html', {'list': list_, 'comment': comment, 'error': error}) def new_list(request): list_ = List.objects.create() @@ -16,5 +28,13 @@ def add_item(request, list_id): Item.objects.create(text=request.POST['item_text'], list=list_) return redirect(f'/lists/{list_.id}/') -def home_page(request): - return render(request, 'home.html') +def count(number): + list_ = List.objects.get(id=list_id) + items = Item.objects.filter(list=list_) + if len(items) > 4: + comment = 'oh tidak' + elif len(items) >= 1: + comment = 'sibuk tapi santai' + else: + comment = 'yey, waktunya berlibur' + return comment diff --git a/superlists/__pycache__/settings.cpython-38.pyc b/superlists/__pycache__/settings.cpython-38.pyc index 2dce4ffa4d4fb0c998dbfe54cdd849b53177a55e..d2166de9c4d0e671fb9a86b5effd4bd4d8f509df 100644 Binary files a/superlists/__pycache__/settings.cpython-38.pyc and b/superlists/__pycache__/settings.cpython-38.pyc differ