Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Django app #4

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
5187e48
Create Flask app
SolarLiner Nov 27, 2018
b03e2db
Fix typo in templates folder name
SolarLiner Nov 27, 2018
f199b28
Add dev dependencies for development tools
SolarLiner Nov 27, 2018
ad5734b
Add in todo HTML from node.js template
SolarLiner Nov 27, 2018
b8c5308
Add todos array in lieu of proper state management
SolarLiner Nov 27, 2018
3def19c
Fix not closing the if in home template
SolarLiner Nov 27, 2018
ba512cc
Copy static folder over from node.js implementation
SolarLiner Nov 27, 2018
3d37109
Reference todo.css file in template
SolarLiner Nov 27, 2018
addeee9
Create tasks for debugging server
SolarLiner Nov 27, 2018
ba31586
Create API routes
SolarLiner Nov 27, 2018
a2d4bf3
Remove pre-defined TODOs for development
SolarLiner Nov 27, 2018
e875418
Change port to run on port 3000
SolarLiner Nov 27, 2018
b71e696
Push ul out of todos loop
SolarLiner Nov 27, 2018
be8841f
Create Django project
SolarLiner Nov 27, 2018
acbffc5
Add note about manual scaffolding
SolarLiner Nov 27, 2018
41e1ed3
Add start script
SolarLiner Nov 27, 2018
275ca28
Copy home template from Flask app
SolarLiner Nov 27, 2018
09bb519
Add index view
SolarLiner Nov 27, 2018
3d49d36
Add templates to Django
SolarLiner Nov 27, 2018
6531d09
Add editor configuration
SolarLiner Nov 27, 2018
a1e791f
Enable templates
SolarLiner Nov 27, 2018
8cb4cb7
Use static files app
SolarLiner Nov 27, 2018
42bca55
Move static folder out of todomvp folder
SolarLiner Nov 27, 2018
5c0a4f8
Move templates out of todomvp folder
SolarLiner Nov 27, 2018
5ccafd6
Implement API routes
SolarLiner Nov 27, 2018
e2a12a5
Fix beginning slash in path routes
SolarLiner Nov 27, 2018
05fa7b5
Fix item not cast to int before used as lookup
SolarLiner Nov 27, 2018
f106475
Redirect to index page on API routes
SolarLiner Nov 27, 2018
67bde42
Use template URL name-matching instead of hard-coding URLs
SolarLiner Nov 27, 2018
8c91881
Remove pre-added todo for development purpose
SolarLiner Nov 27, 2018
f98aea3
Replace hardcoded URLs by templated name-matched ones
SolarLiner Nov 27, 2018
5d3e0b2
Drop VS Code and editor config files
SolarLiner Dec 19, 2018
819c900
Pass whitespace tests
SolarLiner Dec 19, 2018
464b036
Create Django project
SolarLiner Nov 27, 2018
a15e8c0
Add note about manual scaffolding
SolarLiner Nov 27, 2018
4f62a47
Add start script
SolarLiner Nov 27, 2018
7803093
Copy home template from Flask app
SolarLiner Nov 27, 2018
53a8bf4
Add index view
SolarLiner Nov 27, 2018
b3b632e
Add templates to Django
SolarLiner Nov 27, 2018
e7391a3
Add editor configuration
SolarLiner Nov 27, 2018
43fd409
Enable templates
SolarLiner Nov 27, 2018
a90742f
Use static files app
SolarLiner Nov 27, 2018
5ff74ba
Move static folder out of todomvp folder
SolarLiner Nov 27, 2018
fd368f2
Move templates out of todomvp folder
SolarLiner Nov 27, 2018
40754c3
Implement API routes
SolarLiner Nov 27, 2018
9c6ee94
Fix beginning slash in path routes
SolarLiner Nov 27, 2018
9d59614
Fix item not cast to int before used as lookup
SolarLiner Nov 27, 2018
5bfd1cd
Redirect to index page on API routes
SolarLiner Nov 27, 2018
2d5548d
Use template URL name-matching instead of hard-coding URLs
SolarLiner Nov 27, 2018
54409cf
Remove pre-added todo for development purpose
SolarLiner Nov 27, 2018
d841f84
Merge branch 'django' of github.com:SolarLiner/todo-mvp into django
SolarLiner Dec 19, 2018
f91d1e6
Remove VS Code and editor config files
SolarLiner Dec 19, 2018
13656b5
Pass whitespace tests
SolarLiner Dec 19, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions todos/django/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
django = "*"

[dev-packages]
"flake8" = "*"
"flake8-django" = "*"
"autopep8" = "*"

[requires]
python_version = "3.6"

[scripts]
start = "django-admin runserver --pythonpath=. --settings=todomvp"
81 changes: 81 additions & 0 deletions todos/django/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions todos/django/static/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions todos/django/static/plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added todos/django/static/tick.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
153 changes: 153 additions & 0 deletions todos/django/static/todo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
:root {
--text-color: rgb(20,20,20);
--border-color: black;
--title-color: rgb(60,60,60);
--done-color: rgb(200,200,200);
--background-color: white;
box-sizing: border-box;
padding: 0;
margin: 0;
}

body {
min-height: 100vh;
padding: 0;
align-content: center;
margin: 0;
font-family: sans-serif;
line-height: 1.3rem;
font-size: 24px;

background-color: var(--background-color);
color: var(--text-color);
}

label {
font-size: 0.8rem;
}

input {
box-sizing: border-box;
border: var(--border-color) solid 2px;
background-color: var(--background-color);
}

section {
padding: 1.5rem;
margin-left: auto;
margin-right: auto;
max-width: 40rem;
}

.new-todo form {
display: grid;
grid-template-columns: auto 29px;
grid-template-rows: auto;
column-gap: 1rem;
}

.new-todo label[for="new-item"] {
grid-row: 1 / span 1;
grid-column: 1 / span 2;
margin: auto 1rem;
}

.new-todo input#new-item {
grid-row: 1 / span 1;
grid-column: 1 / span 1;
padding: 0.5rem;
font-size: 1rem;
}

.new-todo form input#add-new-item {
grid-row: 1 / span 1;
grid-column: 2 / span 1;
margin: auto;
}

.button-container {
float: right;
display: flex;
flex-direction: column;
height: 100%;
}

ul {
margin: 0;
padding: 0;
}

ul:empty::after {
content: "You've not added any todos to the list. Use the box above to add a new todo.";
font-size: 1rem;
margin: 1rem;
font-style: italic;
border: 2px dotted black;
padding: 0.5rem;
display: block;
text-align: justify;
text-align-last: center;
}

li {
display: flex;
border-bottom: 1px dotted var(--border-color);
}

li:last-child {
border-bottom: none;
}

li .item-name {
flex: auto;
margin: auto;
padding: 0 1rem;
}

li form input,
.new-todo form input#add-new-item {
width: 30px;
height: 30px;
padding: 0;

background-repeat: no-repeat;
background-size: contain;
background-position: center;

/* hide text */
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
}

.todo form input {
margin: 1em;
}

.todo form input.delete {
background-image: url('trashcan.svg');
border: none;
}
input#add-new-item { background-image: url('plus.svg'); }
.todo form input.complete { background-image: none; }
.todo form input.uncomplete { background-image: url('check.svg'); }

.done {
color: var(--done-color);
}

.todo form {
display: contents;
}

h1 {
font-weight: 200;
color: var(--title-color);
margin: 2rem;
display: none;
}

h2 {
border-bottom: 1px solid black;
padding: 0 0 1rem 1rem;
}
1 change: 1 addition & 0 deletions todos/django/static/trashcan.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions todos/django/static/x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions todos/django/templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{% load static %}
<!DOCTYPE html>
<html>
<head>
<title>Todo MVP</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="{% static 'todo.css' %}" />
</head>
<body>
<h1>Todo MVP</h1>
<section class="new-todo">
<form method="POST">
<input
type="text"
id="new-item"
name="item"
pattern=".{3,}"
required
aria-label="Write a new todo item"
title="3 characters minimum"
/>
<input type="submit" value="Add new item" id="add-new-item" />
</form>
</section>

<section class="items">
<h2>Todo list</h2>
<ul>{% for todo in todos %}
{% if todo.done %}
<li class="todo done">
<span class="item-name">
<s>{{ todo.name }}</s>
</span>
<form method="post" action="{% url 'not-done' %}">
<input type="hidden" name="item" value="{{todo.id}}" />
<input
class="uncomplete"
type="submit"
value="Mark not done '{{todo.name}}'"
/>
</form>
<form method="post" action="{% url 'delete' %}">
<input type="hidden" name="item" value="{{todo.id}}" />
<input
class="delete"
type="submit"
value="Delete '{{todo.name}}'"
/>
</form>
</li>
{% else %}
<li class="todo">
<span class="item-name"> {{ todo.name }} </span>
<form method="post" action="{% url 'done' %}">
<input type="hidden" name="item" value="{{todo.id}}" />
<input
class="complete"
type="submit"
value="Mark done '{{todo.name}}'"
/>
</form>
<form method="post" action="{% url 'delete' %}">
<input type="hidden" name="item" value="{{todo.id}}" />
<input
class="delete"
type="submit"
value="Delete '{{todo.name}}'"
/>
</form>
</li>
{% endif %}
{% endfor %}</ul>
</section>
</body>
</html>
38 changes: 38 additions & 0 deletions todos/django/todomvp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Note: I am manually creating a tiny project here since Django is much more
# powerful and a bit too much of a powerhouse for this tiny project ;)
# Django's new project command adds a whole lot more stuff that make sense for a
# typical server, but not here.
import os

from todomvp.views import IndexView, todo_done, todo_undone, todo_delete
from django.urls import path

DEBUG = True
SECRET_KEY = '4l0ngs3cr3tstr1ngw3lln0ts0l0ngw41tn0w1tsl0ng3n0ugh'
ROOT_URLCONF = __name__
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")]
},
]

INSTALLED_APPS = [
"django.contrib.staticfiles"
]

STATIC_URL = "/static/"
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder'
]
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static")
]

urlpatterns = [
path("", IndexView.as_view(), name="index"),
path("done", todo_done, name="done"),
path("not-done", todo_undone, name="not-done"),
path("delete", todo_delete, name="delete")
]
Loading