This commit is contained in:
Anna Sudnitsina 2017-12-06 11:56:54 +03:00
parent e62391cb92
commit feae4cebe9
20 changed files with 450 additions and 0 deletions

BIN
db.sqlite3 Normal file

Binary file not shown.

22
manage.py Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "organizer.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
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?"
)
raise
execute_from_command_line(sys.argv)

0
organizer/__init__.py Normal file
View File

123
organizer/settings.py Normal file
View File

@ -0,0 +1,123 @@
"""
Django settings for organizer project.
Generated by 'django-admin startproject' using Django 1.11b1.
For more information on this file, see
https://docs.djangoproject.com/en/dev/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/dev/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'zqu26qd&p8t=06wrjr1&q1v35^k9%uv&dyj-akq49wfi)ceq@y'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'todolist'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'organizer.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'organizer.wsgi.application'
# Database
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/dev/topics/i18n/
LANGUAGE_CODE = 'ru-RU'
TIME_ZONE = 'Europe/Moscow'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/dev/howto/static-files/
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')

26
organizer/urls.py Normal file
View File

@ -0,0 +1,26 @@
"""organizer URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/dev/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 import settings
from django.conf.urls import url, include
from django.contrib import admin
from django.conf.urls.static import static
from todolist.views import TaskView
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^tasks/$', TaskView.as_view(), name='tasks'),
url(r'^tasks/', include('todolist.urls'))
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

16
organizer/wsgi.py Normal file
View File

@ -0,0 +1,16 @@
"""
WSGI config for organizer project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "organizer.settings")
application = get_wsgi_application()

0
todolist/__init__.py Normal file
View File

7
todolist/admin.py Normal file
View File

@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
from .models import Task
admin.site.register(Task)

8
todolist/apps.py Normal file
View File

@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
class TodolistConfig(AppConfig):
name = 'todolist'

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11b1 on 2017-12-02 12:45
from __future__ import unicode_literals
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Task',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateTimeField(default=django.utils.timezone.now)),
('title', models.CharField(max_length=50)),
],
),
]

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11b1 on 2017-12-02 13:01
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('todolist', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='task',
name='if_done',
field=models.BooleanField(default=False),
),
]

View File

17
todolist/models.py Normal file
View File

@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.utils import timezone
class Task(models.Model):
date = models.DateTimeField(default=timezone.now)
title = models.CharField(max_length=50)
if_done = models.BooleanField(default=False)
def __unicode__(self):
return self.title
class Meta:
ordering = ["-date"]

View File

@ -0,0 +1,43 @@
body {
font-family: 'Open Sans', sans-serif;
}
.hover {
display: none;
}
hr{
border:0;
border-top:1px solid #eee;
}
form:hover a{
text-decoration-line: none;
color: red;
display: inline;
}
input[type="checkbox"] {
font-size: 10px
}
a.plus_btn {
border: none;
text-align: center;
/*vertical-align: middle;*/
text-decoration: none;
color: black;
display: inline-block;
background-color: #e0e0e0;
border-radius: 50%;
font-size: 20px;
height: 30px;
margin: 10px;
width: 30px;
}
.task_item {
padding: 20px;
}
.time {
color: #999999;
font-size: 12px;
letter-spacing: 1px;
padding: 5px 10px;
display: inline-block;
}

View File

@ -0,0 +1,25 @@
$(function() {
$('input[type="checkbox"]').click(function() {
$.ajax({
data: $(this).parent().serialize() ,
type: 'POST'
});
if ($(this).parent().css("text-decoration-line") == "none") {
$(this).parent().css("text-decoration-line", "line-through")}
else {
$(this).parent().css("text-decoration-line", "none");
}
});
$('a.delete').click(function() {
$.ajax({
data: $(this).parent().serialize(),
type: 'POST',
url: 'delete/'
});
//todo: если success
$(this).parent().remove();
})
});

View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form class="" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" name="" value="Добавить">
</form>
{% if form.instance.pk %}
<a href="{% url 'task_delete' pk=form.instance.pk %}">Удалить</a>
{% endif %}
</body>
</html>

View File

@ -0,0 +1,34 @@
{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" href="{% static 'css/style.css' %}">
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="{% static 'js/script.js' %}"></script>
<title>Tasks</title>
</head>
<body>
<p>To Do List:
<a class="plus_btn" href="{% url 'create_task' %}">+</a></p>
{% regroup tasks by date|date:"d-m-y" as task_list %}
{% for date in task_list %}
<p>{{ date.grouper }}</p>
{% for t in date.list %}
{% if t.if_done %}
<form class ="task-item" style="text-decoration: line-through">
<input type="checkbox" name="done" checked>
{% else %}
<form class ="task-item" style="text-decoration: none;">
<input type="checkbox" name="done">
{% endif %}
{% csrf_token %}
<input type="hidden" name='id' value="{{ t.id }}">
{{ t.title }} <span class="time">{{ t.date|date:"H:i" }}</span><a href="javascript:void(0)" class="hover delete"><i class="fa fa-trash"></i></a>
</form>
{% endfor %}
<hr>
{% endfor %}
</html>

6
todolist/tests.py Normal file
View File

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
# Create your tests here.

10
todolist/urls.py Normal file
View File

@ -0,0 +1,10 @@
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^create/$', views.TaskCreateView.as_view(), name="create_task"),
url(r'^update/(?P<pk>\d+)/$', views.TaskUpdateView.as_view()),
# url(r'^delete/(?P<pk>\d+)/$', views.TaskDeleteView.as_view(), name='task_delete')
#url(r'^delete/(?P<pk>\d+)/$', views.task_delete, name='task_delete')
url(r'^delete/$', views.TaskDeleteView.as_view(), name='task_delete')
]

49
todolist/views.py Normal file
View File

@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from django.views.generic import (
View, TemplateView, ListView, CreateView, UpdateView, DeleteView
)
from django.views.generic.detail import SingleObjectMixin
from django.core.urlresolvers import reverse_lazy
from .models import Task
class TaskView(ListView):
model = Task
context_object_name = 'tasks'
template_name = "todolist/todo.html"
def post(self, request):
if request.is_ajax():
obj = Task.objects.get(id=request.POST["id"])
if "done" in request.POST:
obj.if_done = True
else:
obj.if_done = False
obj.save()
return HttpResponse('OK')
class TaskCreateView(CreateView):
model = Task
fields = ('title',)
success_url = reverse_lazy('tasks')
class TaskUpdateView(UpdateView):
model = Task
fields = ('title',)
class TaskDeleteView(View, SingleObjectMixin):
model = Task
pk_url_kwarg = 'id'
def post(self, request):
self.kwargs = request.POST
self.object = self.get_object()
self.object.delete()
return HttpResponse('')