diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..f46ec78 Binary files /dev/null and b/db.sqlite3 differ diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..538dbfb --- /dev/null +++ b/manage.py @@ -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) diff --git a/organizer/__init__.py b/organizer/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/organizer/settings.py b/organizer/settings.py new file mode 100644 index 0000000..719d00f --- /dev/null +++ b/organizer/settings.py @@ -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') diff --git a/organizer/urls.py b/organizer/urls.py new file mode 100644 index 0000000..a8a32c2 --- /dev/null +++ b/organizer/urls.py @@ -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) diff --git a/organizer/wsgi.py b/organizer/wsgi.py new file mode 100644 index 0000000..9ed4b25 --- /dev/null +++ b/organizer/wsgi.py @@ -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() diff --git a/todolist/__init__.py b/todolist/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/todolist/admin.py b/todolist/admin.py new file mode 100644 index 0000000..cf2201c --- /dev/null +++ b/todolist/admin.py @@ -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) diff --git a/todolist/apps.py b/todolist/apps.py new file mode 100644 index 0000000..f9a1763 --- /dev/null +++ b/todolist/apps.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class TodolistConfig(AppConfig): + name = 'todolist' diff --git a/todolist/migrations/0001_initial.py b/todolist/migrations/0001_initial.py new file mode 100644 index 0000000..c8cf3e5 --- /dev/null +++ b/todolist/migrations/0001_initial.py @@ -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)), + ], + ), + ] diff --git a/todolist/migrations/0002_task_if_done.py b/todolist/migrations/0002_task_if_done.py new file mode 100644 index 0000000..7c055b4 --- /dev/null +++ b/todolist/migrations/0002_task_if_done.py @@ -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), + ), + ] diff --git a/todolist/migrations/__init__.py b/todolist/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/todolist/models.py b/todolist/models.py new file mode 100644 index 0000000..0c8022f --- /dev/null +++ b/todolist/models.py @@ -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"] diff --git a/todolist/static/css/style.css b/todolist/static/css/style.css new file mode 100644 index 0000000..f6c1336 --- /dev/null +++ b/todolist/static/css/style.css @@ -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; +} diff --git a/todolist/static/js/script.js b/todolist/static/js/script.js new file mode 100644 index 0000000..1d4fb32 --- /dev/null +++ b/todolist/static/js/script.js @@ -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(); + }) + }); diff --git a/todolist/templates/todolist/task_form.html b/todolist/templates/todolist/task_form.html new file mode 100644 index 0000000..6218aee --- /dev/null +++ b/todolist/templates/todolist/task_form.html @@ -0,0 +1,19 @@ + + + + + + + +
+ {% csrf_token %} + {{ form }} + + + +
+ {% if form.instance.pk %} + Удалить + {% endif %} + + diff --git a/todolist/templates/todolist/todo.html b/todolist/templates/todolist/todo.html new file mode 100644 index 0000000..46573be --- /dev/null +++ b/todolist/templates/todolist/todo.html @@ -0,0 +1,34 @@ +{% load staticfiles %} + + + + + + + + + + Tasks + + +

To Do List: + +

+ {% regroup tasks by date|date:"d-m-y" as task_list %} + {% for date in task_list %} +

{{ date.grouper }}

+ {% for t in date.list %} + {% if t.if_done %} +
+ + {% else %} + + + {% endif %} + {% csrf_token %} + + {{ t.title }} {{ t.date|date:"H:i" }} +
+ {% endfor %} +
+ {% endfor %} + diff --git a/todolist/tests.py b/todolist/tests.py new file mode 100644 index 0000000..5982e6b --- /dev/null +++ b/todolist/tests.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import TestCase + +# Create your tests here. diff --git a/todolist/urls.py b/todolist/urls.py new file mode 100644 index 0000000..6c53603 --- /dev/null +++ b/todolist/urls.py @@ -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\d+)/$', views.TaskUpdateView.as_view()), + # url(r'^delete/(?P\d+)/$', views.TaskDeleteView.as_view(), name='task_delete') + #url(r'^delete/(?P\d+)/$', views.task_delete, name='task_delete') + url(r'^delete/$', views.TaskDeleteView.as_view(), name='task_delete') +] diff --git a/todolist/views.py b/todolist/views.py new file mode 100644 index 0000000..9a1c4d2 --- /dev/null +++ b/todolist/views.py @@ -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('')