Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorErmakov committed Aug 19, 2021
0 parents commit 361ef20
Show file tree
Hide file tree
Showing 38 changed files with 751 additions and 0 deletions.
Binary file added db.sqlite3
Binary file not shown.
22 changes: 22 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'todowoo.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
Empty file added todo/__init__.py
Empty file.
Binary file added todo/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added todo/__pycache__/admin.cpython-39.pyc
Binary file not shown.
Binary file added todo/__pycache__/apps.cpython-39.pyc
Binary file not shown.
Binary file added todo/__pycache__/forms.cpython-39.pyc
Binary file not shown.
Binary file added todo/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file added todo/__pycache__/views.cpython-39.pyc
Binary file not shown.
7 changes: 7 additions & 0 deletions todo/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin
from .models import TodoItem

class TodoAdmin(admin.ModelAdmin):
readonly_fields = ('created_at', )

admin.site.register(TodoItem, TodoAdmin)
6 changes: 6 additions & 0 deletions todo/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class TodoConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'todo'
12 changes: 12 additions & 0 deletions todo/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.forms import ModelForm
from .models import TodoItem

class TodoForm(ModelForm):

class Meta:
model = TodoItem
fields = [
'name',
'memo',
'is_important',
]
29 changes: 29 additions & 0 deletions todo/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 3.2.6 on 2021-08-18 19:04

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='TodoItem',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('memo', models.TextField(blank=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('date_completed', models.DateTimeField(null=True)),
('is_important', models.BooleanField(default=False)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
18 changes: 18 additions & 0 deletions todo/migrations/0002_alter_todoitem_date_completed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.6 on 2021-08-18 19:06

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('todo', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='todoitem',
name='date_completed',
field=models.DateTimeField(blank=True, null=True),
),
]
Empty file added todo/migrations/__init__.py
Empty file.
Binary file not shown.
Binary file not shown.
Binary file added todo/migrations/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
14 changes: 14 additions & 0 deletions todo/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.db import models
from django.contrib.auth.models import User

class TodoItem(models.Model):
name = models.CharField(max_length = 100)
memo = models.TextField(blank=True)
created_at = models.DateTimeField(auto_now_add=True)
date_completed = models.DateTimeField(null=True, blank=True)
is_important = models.BooleanField(default=False)

user = models.ForeignKey(User, on_delete=models.CASCADE)

def __str__(self):
return str(self.id) + ' ' + self.name
63 changes: 63 additions & 0 deletions todo/templates/todo/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!doctype html>
{% load static %}
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">

<title>Plan for today</title>

<style>

</style>

</head>
<body>

{% if user.is_authenticated %}
<div class="alert alert-success" role="alert">
Things to accomplish for
<strong>{{ user.username }}</strong>
</div>
{% endif %}


<ul class="nav justify-content-center">

<li class="nav-item"><a class="nav-link active" aria-current="page" href="/">Home</a></li>

{% if user.is_authenticated %}
<li class="nav-item"><a class="nav-link active" aria-current="page" href="{% url 'completed_todos' %}">Completed</a></li>
<li class="nav-item"><a class="nav-link" aria-current="page" href="{% url 'current_todos' %}">Current items</a></li>
{% endif %}

{% if user.is_authenticated %}
<form method="POST" action="{% url 'logout'%}" style="display: inline-block; margin-left: auto; margin-right: 20px">
{% csrf_token %}
&nbsp;&nbsp;&nbsp;&nbsp;<button type="submit" class="btn btn-primary">Logout</button>
</form>

{% else %}
<li class="nav-item"><a class="nav-link active" aria-current="page" href="{% url 'login' %}">Login</a></li>
<li class="nav-item"><a class="nav-link active" aria-current="page" href="{% url 'signupuser' %}">Sign Up</a></li>
{% endif %}


</ul>

<!-- <img src="{% static 'portfolio/dino.jpg' %}" width="150" alt="dino"/> -->

<div class="content m-5">
{% block content %}{% endblock %}
</div>
<!-- Optional JavaScript; choose one of the two! -->

<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-U1DAWAznBHeqEIlVSCgzq+c9gqGAJn5c/t99JyeKa9xxaYpSvHU5awsuZVVFIhvj" crossorigin="anonymous"></script>

</body>
</html>
20 changes: 20 additions & 0 deletions todo/templates/todo/completed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends 'todo/base.html' %}
{% block content %}


<h1>COMPLETED</h1>
<a class="btn btn-primary mb-5" href="{% url 'create_todo' %}">+ Create</a>

<div class="list-group">
{% for itm in items %}
<a href="{% url 'view_item' itm.id %}" class="list-group-item list-group-item-action {% if itm.is_important %}active{% endif %}">
#{{ itm.id }} - {{ itm.name }}
{% if itm.memo %}
<div><small>{{ itm.memo | truncatechars:100}}</small></div>
<date>{{ itm.date_completed | date:"d M Y" }}</date>
{% endif %}
</a>
{% endfor %}
</div>

{% endblock %}
18 changes: 18 additions & 0 deletions todo/templates/todo/create_todo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends 'todo/base.html' %}
{% block content %}


<h1>Create a new entry</h1>

<h3>{{ error }}</h3>

<form method="POST">

{{ form.as_p }}
{% csrf_token %}

<button type="submit" class="btn btn-primary">Create</button>

</form>

{% endblock %}
19 changes: 19 additions & 0 deletions todo/templates/todo/current_todos.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends 'todo/base.html' %}
{% block content %}


<h1>Todos list</h1>
<a class="btn btn-primary mb-4" href="{% url 'create_todo' %}">+ Create</a>

<div class="list-group">
{% for itm in items %}
<a href="{% url 'view_item' itm.id %}" class="list-group-item list-group-item-action {% if itm.is_important %}active{% endif %}">
#{{ itm.id }} - {{ itm.name }}
{% if itm.memo %}
<div><small>{{ itm.memo | truncatechars:100}}</small></div>
{% endif %}
</a>
{% endfor %}
</div>

{% endblock %}
9 changes: 9 additions & 0 deletions todo/templates/todo/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends 'todo/base.html' %}
{% block content %}


<h1>Home - all items</h1>
<a class="btn btn-primary mb-5" href="{% url 'create_todo' %}">+ Create</a>


{% endblock %}
22 changes: 22 additions & 0 deletions todo/templates/todo/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends 'todo/base.html' %}
{% block content %}
<style>
form input, form textarea {
display: block
}
</style>

<h1>Log In</h1>

<h3>{{ error }}</h3>

<form method="POST">

{{ form.as_p }}
{% csrf_token %}

<button type="submit" class="btn btn-primary">Log In</button>

</form>

{% endblock %}
22 changes: 22 additions & 0 deletions todo/templates/todo/signupuser.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends 'todo/base.html' %}
{% block content %}
<style>
form input, form textarea {
display: block
}
</style>

<h1>Sign Up</h1>

<h3>{{ error }}</h3>

<form method="POST">

{{ form.as_p }}
{% csrf_token %}

<button type="submit" class="btn btn-primary">Sign Up</button>

</form>

{% endblock %}
50 changes: 50 additions & 0 deletions todo/templates/todo/view_todo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{% extends 'todo/base.html' %}
{% block content %}
<style>
form input, form textarea {
display: block
}
</style>

<h1>View</h1>

<!--
{% if itm.is_important %}
<h2>! IMPORTANT !</h2>
{% endif %}
<h5>ID: #{{ itm.id }}</h5>
<h5>NAME: {{ itm.name }}</h5>
{% if itm.memo %}
<p><small>{{ itm.memo}}</small></p>
{% endif %}
-->
<form method="POST">

{{ form.as_p }}
{% csrf_token %}

<button type="submit" class="btn btn-primary">Update</button>


</form>
<br/>

<form method="POST" action={% url 'complete_item' itm.id %}>
{% csrf_token %}
<button type="submit" class="btn btn-success">Complete item</button>
</form>

<br/>



<form method="POST" action={% url 'delete_item' itm.id %}>
{% csrf_token %}
<button type="submit" class="btn btn-danger">DELETE</button>
</form>



{% endblock %}
3 changes: 3 additions & 0 deletions todo/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
Loading

0 comments on commit 361ef20

Please sign in to comment.