Fakultas Ilmu Komputer UI

Commit ce0ddd0f authored by Dwi Nanda Susanto's avatar Dwi Nanda Susanto
Browse files

Merge branch 'testinggoat/ch7-8' into 'master'

Testinggoat/ch7 8

See merge request !7
parents 9130f186 a370b59b
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dwi-Homepage</title>
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/base.css" rel="stylesheet">
</head>
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3 jumbotron">
<div class="text-center">
<h1>{% block header_text %}{% endblock %}</h1>
<form method="POST" action="{% block form_action %}{% endblock %}">
<input name="item_text" id="id_new_item" class="form-control input-lg"
placeholder="Enter a to-do item" />
{% csrf_token %}
</form>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-3">
{% block table %}
{% endblock %}
</div>
</div>
</div>
</html>
<html>
<head>
<title>To-Do</title>
</head>
<body>
<h1>Dwi Nanda Susanto - 1506722720 - To-Do List</h1>
<form method="POST">
<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />
{% csrf_token %}
</form>
<table id="id_list_table">
{% for item in items %}
<tr>
<td>{{ forloop.counter }}: {{ item.text }}</td>
</tr>
{% endfor %}
</table>
<form action="reset-item/" method="GET">
<button type='submit'>RESET</button>
</form>
{% if items|length < 1 %}
<h3 style="color:green;">yey, waktunya berlibur</h3>
{% elif items|length > 0 and items|length < 5 %}
<h3 style="color:blue;">sibuk tapi santai</h3>
{% else %}
<h3 style="color:red;">oh tidak</h3>
{% endif %}
</body>
</html>
{% extends 'base.html' %}
{% block header_text %}Dwi Nanda Susanto - 1506722720 - To-Do List{% endblock %}
{% block form_action %}/lists/new{% endblock %}
{% extends 'base.html' %}
{% block header_text %}Dwi Nanda Susanto To-Do list{% endblock %}
{% block form_action %}/lists/{{ list.id }}/add_item{% endblock %}
{% block table %}
<table id="id_list_table" class="table">
{% for item in list.item_set.all %}
<tr><td>{{ forloop.counter }}: {{ item.text }}</td></tr>
{% endfor %}
</table>
{% if list.item_set.all|length < 1 %}
<h3 style="color:green;">yey, waktunya berlibur</h3>
{% elif list.item_set.all|length > 0 and items|length < 5 %}
<h3 style="color:blue;">sibuk tapi santai</h3>
{% else %}
<h3 style="color:red;">oh tidak</h3>
{% endif %}
{% endblock %}
\ No newline at end of file
from django.conf.urls import url
from lists import views
urlpatterns = [
url(r'^new$', views.new_list, name='new_list'),
url(r'^(\d+)/$', views.view_list, name='view_list'),
url(r'^(\d+)/add_item$', views.add_item, name='add_item'),
]
from django.shortcuts import render
from django.http import HttpResponse
from django.shortcuts import redirect, render
from lists.models import Item
# Create your views here.
from lists.models import Item, List
def home_page(req):
if req.method == 'POST':
Item.objects.create(text=req.POST['item_text'])
return redirect('/')
items = Item.objects.all()
return render(req, 'home.html', {'items': items})
def home_page(request):
return render(request, 'home.html')
def view_list(request, list_id):
list_ = List.objects.get(id=list_id)
return render(request, 'list.html', {'list': list_})
def new_list(request):
list_ = List.objects.create()
Item.objects.create(text=request.POST['item_text'], list=list_)
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}/')
def reset_items(req):
if req.method == 'GET':
......
"""superlists URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.urls import path
from django.contrib import admin
from lists import views
app_name = 'lists'
from django.conf.urls import include, url
from lists import views as list_views
from lists import urls as list_urls
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', views.home_page, name='home'),
path('reset-item/', views.reset_items),
url(r'^$', list_views.home_page, name='home'),
url(r'^lists/', include(list_urls)),
]
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