From feae4cebe9c2c801178f1b184c468bfb6a2bcf7a Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 6 Dec 2017 11:56:54 +0300 Subject: [PATCH] initial --- db.sqlite3 | Bin 0 -> 41984 bytes manage.py | 22 ++++ organizer/__init__.py | 0 organizer/settings.py | 123 +++++++++++++++++++++ organizer/urls.py | 26 +++++ organizer/wsgi.py | 16 +++ todolist/__init__.py | 0 todolist/admin.py | 7 ++ todolist/apps.py | 8 ++ todolist/migrations/0001_initial.py | 25 +++++ todolist/migrations/0002_task_if_done.py | 20 ++++ todolist/migrations/__init__.py | 0 todolist/models.py | 17 +++ todolist/static/css/style.css | 43 +++++++ todolist/static/js/script.js | 25 +++++ todolist/templates/todolist/task_form.html | 19 ++++ todolist/templates/todolist/todo.html | 34 ++++++ todolist/tests.py | 6 + todolist/urls.py | 10 ++ todolist/views.py | 49 ++++++++ 20 files changed, 450 insertions(+) create mode 100644 db.sqlite3 create mode 100644 manage.py create mode 100644 organizer/__init__.py create mode 100644 organizer/settings.py create mode 100644 organizer/urls.py create mode 100644 organizer/wsgi.py create mode 100644 todolist/__init__.py create mode 100644 todolist/admin.py create mode 100644 todolist/apps.py create mode 100644 todolist/migrations/0001_initial.py create mode 100644 todolist/migrations/0002_task_if_done.py create mode 100644 todolist/migrations/__init__.py create mode 100644 todolist/models.py create mode 100644 todolist/static/css/style.css create mode 100644 todolist/static/js/script.js create mode 100644 todolist/templates/todolist/task_form.html create mode 100644 todolist/templates/todolist/todo.html create mode 100644 todolist/tests.py create mode 100644 todolist/urls.py create mode 100644 todolist/views.py diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000000000000000000000000000000000000..f46ec78523467ad894d4554ab7bb9acc119d6ab2 GIT binary patch literal 41984 zcmeHQe{37qeZO~))S0$qNw!qBaa5maD>kQyx}PMEZhp|VB+Is_SeAdtMZliOlSGL> zWRkKiXW2qI$c8OLv2|PfSGx=YR;*aybn}udbuwfKHf+NxV;zbOYdds6mJMl!4q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D}TCjjla3Pa_wdXenJKhWpDB;e+)UxE7#Xl0}H#shL37Y&_WSW zkW@L<0%{JTN$^ozc?tNhue?EI+$xA$dt+~NHar7>ULl{V`S4MK;ZL%%ycqc z$QyyD>#zVNYE02$suYr=k*E+!dGCr6B_@b5Q4Fbq0xKz{Jaxzat`HNXkfO*!L`boB#atOQ#Kdq&5i~_pk0YXln!DE3UC&}FOn?VX zQX{I=hHfyJ`3b}RJo`HQ`N@a)xZks)Dnl~o-@hL%AE%XdbrJR?dH1h7IZ$6!*OlE? zv%E$v43&5}Q_eyKU7efcY?eraY(0|oO#6e*LnCuLXtOEUgts6HLB~ER$e3d5TsNfn0O9yf%fJLKuruH z35jLQ;N@E?bX3a2wXLTGg)UYLQAz}&9tdfix*Q7Ne&gVu2ECT@SR=O*Q=`qTbx8Oe zblAlmip}6sA>mOptV)_j{UHI?jho;R4U3M<>G_!gfB4Xu-O!aM@3IvGH;nucXl&~fV(zETL_=2VQb2>j;G^QU5keay!Rr7|H+?IMFrba@V7FOiw z{B}@3hE5T`l?^MQb+pkSaFwqjt>Cqg1cw@)X#-`$rZRQi`tmjv$?!%hhr{as16YTq AnE(I) literal 0 HcmV?d00001 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('')