diff --git a/base/__init__.py b/base/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/base/__pycache__/__init__.cpython-310.pyc b/base/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..cce678a Binary files /dev/null and b/base/__pycache__/__init__.cpython-310.pyc differ diff --git a/base/__pycache__/admin.cpython-310.pyc b/base/__pycache__/admin.cpython-310.pyc new file mode 100644 index 0000000..5de67a4 Binary files /dev/null and b/base/__pycache__/admin.cpython-310.pyc differ diff --git a/base/__pycache__/apps.cpython-310.pyc b/base/__pycache__/apps.cpython-310.pyc new file mode 100644 index 0000000..01ff3c1 Binary files /dev/null and b/base/__pycache__/apps.cpython-310.pyc differ diff --git a/base/__pycache__/models.cpython-310.pyc b/base/__pycache__/models.cpython-310.pyc new file mode 100644 index 0000000..88c3ce7 Binary files /dev/null and b/base/__pycache__/models.cpython-310.pyc differ diff --git a/base/__pycache__/urls.cpython-310.pyc b/base/__pycache__/urls.cpython-310.pyc new file mode 100644 index 0000000..37c7819 Binary files /dev/null and b/base/__pycache__/urls.cpython-310.pyc differ diff --git a/base/__pycache__/views.cpython-310.pyc b/base/__pycache__/views.cpython-310.pyc new file mode 100644 index 0000000..484df2b Binary files /dev/null and b/base/__pycache__/views.cpython-310.pyc differ diff --git a/base/admin.py b/base/admin.py new file mode 100644 index 0000000..ac186dd --- /dev/null +++ b/base/admin.py @@ -0,0 +1,4 @@ +from django.contrib import admin +from .models import Task + +admin.site.register(Task) diff --git a/base/apps.py b/base/apps.py new file mode 100644 index 0000000..05011e8 --- /dev/null +++ b/base/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class BaseConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'base' diff --git a/base/migrations/0001_initial.py b/base/migrations/0001_initial.py new file mode 100644 index 0000000..b1dd456 --- /dev/null +++ b/base/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# Generated by Django 4.2.2 on 2023-06-22 09:47 + +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='Task', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(blank=True, max_length=200, null=True)), + ('description', models.TextField(blank=True, null=True)), + ('complete', models.BooleanField(default=False)), + ('create', models.DateTimeField(auto_now_add=True)), + ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + options={ + 'ordering': ['complete'], + }, + ), + ] diff --git a/base/migrations/__init__.py b/base/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/base/migrations/__pycache__/0001_initial.cpython-310.pyc b/base/migrations/__pycache__/0001_initial.cpython-310.pyc new file mode 100644 index 0000000..67daace Binary files /dev/null and b/base/migrations/__pycache__/0001_initial.cpython-310.pyc differ diff --git a/base/migrations/__pycache__/__init__.cpython-310.pyc b/base/migrations/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..ba3b4ed Binary files /dev/null and b/base/migrations/__pycache__/__init__.cpython-310.pyc differ diff --git a/base/models.py b/base/models.py new file mode 100644 index 0000000..73601ed --- /dev/null +++ b/base/models.py @@ -0,0 +1,15 @@ +from django.db import models +from django.contrib.auth.models import User + +class Task(models.Model): + user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True) + title = models.CharField(max_length=200, null=True, blank=True) + description = models.TextField(null=True, blank=True) + complete = models.BooleanField(default=False) + create = models.DateTimeField(auto_now_add=True) + + def __str__(self): + return self.title + + class Meta: + ordering = ['complete'] diff --git a/base/templates/base/login.html b/base/templates/base/login.html new file mode 100644 index 0000000..8d927e0 --- /dev/null +++ b/base/templates/base/login.html @@ -0,0 +1,19 @@ +{% extends 'base/main.html' %} +{% block content %} + +
+

Login

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

Don't have an account? Register

+
+ + +{% endblock content %} \ No newline at end of file diff --git a/base/templates/base/main.html b/base/templates/base/main.html new file mode 100644 index 0000000..27b6cd3 --- /dev/null +++ b/base/templates/base/main.html @@ -0,0 +1,115 @@ + + + + + + Bucket List + + + +
+ {% block content %} + + {% endblock content %} +
+ + \ No newline at end of file diff --git a/base/templates/base/register.html b/base/templates/base/register.html new file mode 100644 index 0000000..4c746f2 --- /dev/null +++ b/base/templates/base/register.html @@ -0,0 +1,24 @@ +{% extends 'base/main.html' %} +{% block content %} +
+

Register

+
+ +
+
+ {% csrf_token %} + + {{form.username}} + + {{form.password1}} + + {{form.password2}} + +
+ +

Already have an account? Click Hear

+ +
+ + +{% endblock content %} \ No newline at end of file diff --git a/base/templates/base/task.html b/base/templates/base/task.html new file mode 100644 index 0000000..13f0691 --- /dev/null +++ b/base/templates/base/task.html @@ -0,0 +1 @@ +

Task: {{task}}

\ No newline at end of file diff --git a/base/templates/base/task_confirm_delete.html b/base/templates/base/task_confirm_delete.html new file mode 100644 index 0000000..9558c8d --- /dev/null +++ b/base/templates/base/task_confirm_delete.html @@ -0,0 +1,16 @@ +{% extends 'base/main.html' %} +{% block content %} + +
+ ←Go Back +
+ +
+
+ {% csrf_token %} +

Are you sure want to Delete List "{{task}}"

+ +
+
+ +{% endblock content %} \ No newline at end of file diff --git a/base/templates/base/task_form.html b/base/templates/base/task_form.html new file mode 100644 index 0000000..e7d0d27 --- /dev/null +++ b/base/templates/base/task_form.html @@ -0,0 +1,17 @@ +{% extends 'base/main.html' %} +{% block content %} +
+ ←Back +
+ +
+
+ {% csrf_token %} + {{form.as_p}} + +
+
+ + + +{% endblock content %} \ No newline at end of file diff --git a/base/templates/base/task_list.html b/base/templates/base/task_list.html new file mode 100644 index 0000000..350f176 --- /dev/null +++ b/base/templates/base/task_list.html @@ -0,0 +1,52 @@ +{% extends 'base/main.html' %} +{% block content %} + +
+
+

Hello {{request.user|title}}

+

You have {{count}} Incomplete Dream'{{ count|pluralize:"s" }}

+
+ {% if request.user.is_authenticated %} + Logout + {% else %} + Login + {% endif %} +
+ +
+
+ + +
+ + +
+ + + + + + +
+ {% for task in tasks %} +
+ {% if task.complete %} +
+
+ {{task}} +
+
+ {% else %} +
+
+ {{task}} +
+
+ × + {% endif %} +
+ {% empty %} +

No Items In List

+ {% endfor %} +
+ +{% endblock content %} diff --git a/base/tests.py b/base/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/base/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/base/urls.py b/base/urls.py new file mode 100644 index 0000000..bfc4821 --- /dev/null +++ b/base/urls.py @@ -0,0 +1,14 @@ +from django.urls import path +from .views import TaskList , TaskDetail, TaskCreate, TaskUpdate, TaskDelete, CustomLoginView, RegisterPage +from django.contrib.auth.views import LogoutView + +urlpatterns = [ + path('login/',CustomLoginView.as_view(),name='login'), + path('logout/',LogoutView.as_view(next_page='login'),name='logout'), + path('register/',RegisterPage.as_view(),name='register'), + path('',TaskList.as_view(),name='tasks'), + path('task//',TaskDetail.as_view(),name='task'), + path('task-create',TaskCreate.as_view(),name='task-create'), + path('task-update//',TaskUpdate.as_view(),name='task-update'), + path('task-delete//',TaskDelete.as_view(),name='task-delete'), +] \ No newline at end of file diff --git a/base/views.py b/base/views.py new file mode 100644 index 0000000..926ca3f --- /dev/null +++ b/base/views.py @@ -0,0 +1,83 @@ +from django.shortcuts import render +from django.views.generic import ListView +from django.views.generic.detail import DetailView +from django.views.generic.edit import CreateView, UpdateView, DeleteView, FormView +from django.urls import reverse_lazy + +from django.contrib.auth.views import LoginView + +from django.contrib.auth.mixins import LoginRequiredMixin + +from django.contrib.auth.forms import UserCreationForm + +from django.contrib.auth import login + +from .models import Task + +class CustomLoginView(LoginView): + template_name = 'base/login.html' + fields = '__all__' + redirect_authenticated_user = True + + def get_success_url(self): + return reverse_lazy('tasks') + +class RegisterPage(FormView): + template_name = 'base/register.html' + form_class = UserCreationForm + redirect_authenticated_user = True + success_url = reverse_lazy('tasks') + + def form_valid(self, form): + user = form.save() + if user is not None: + login(self.request,user) + return super(RegisterPage,self).form_valid(form) + + def get(self, *args, **kwargs): + if self.request.user.is_authenticated: + return redirect('tasks') + return super(RegisterPage,self).get(*args,**kwargs) + +class TaskList(LoginRequiredMixin, ListView): + model = Task + context_object_name = 'tasks' + + def get_context_data(self, **kwargs): + conext = super().get_context_data(**kwargs) + conext['tasks'] = conext['tasks'].filter(user=self.request.user) + conext['count'] = conext['tasks'].filter(complete=False).count() + + search_input = self.request.GET.get('search-area') or '' + if search_input: + conext['tasks'] = conext['tasks'].filter(title__startswith=search_input) + + + conext['search_input'] = search_input + return conext + + + +class TaskDetail(LoginRequiredMixin, DetailView): + model = Task + context_object_name = 'task' + template_name = 'base/task.html' + +class TaskCreate(LoginRequiredMixin, CreateView): + model = Task + fields = ['title', 'description', 'complete'] + success_url = reverse_lazy('tasks') + + def form_valid(self, form): + form.instance.user = self.request.user + return super(TaskCreate, self).form_valid(form) + +class TaskUpdate(LoginRequiredMixin, UpdateView): + model = Task + fields = ['title', 'description', 'complete'] + success_url = reverse_lazy('tasks') + +class TaskDelete(LoginRequiredMixin, DeleteView): + model = Task + context_object_name = 'task' + success_url = reverse_lazy('tasks') diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..5405743 Binary files /dev/null and b/db.sqlite3 differ diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..acb3679 --- /dev/null +++ b/manage.py @@ -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', 'todo_list.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() diff --git a/todo_list/__init__.py b/todo_list/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/todo_list/__pycache__/__init__.cpython-310.pyc b/todo_list/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..3c8d3fb Binary files /dev/null and b/todo_list/__pycache__/__init__.cpython-310.pyc differ diff --git a/todo_list/__pycache__/settings.cpython-310.pyc b/todo_list/__pycache__/settings.cpython-310.pyc new file mode 100644 index 0000000..d8003f1 Binary files /dev/null and b/todo_list/__pycache__/settings.cpython-310.pyc differ diff --git a/todo_list/__pycache__/urls.cpython-310.pyc b/todo_list/__pycache__/urls.cpython-310.pyc new file mode 100644 index 0000000..90c99f8 Binary files /dev/null and b/todo_list/__pycache__/urls.cpython-310.pyc differ diff --git a/todo_list/__pycache__/wsgi.cpython-310.pyc b/todo_list/__pycache__/wsgi.cpython-310.pyc new file mode 100644 index 0000000..383cce8 Binary files /dev/null and b/todo_list/__pycache__/wsgi.cpython-310.pyc differ diff --git a/todo_list/asgi.py b/todo_list/asgi.py new file mode 100644 index 0000000..76e8834 --- /dev/null +++ b/todo_list/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for todo_list project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'todo_list.settings') + +application = get_asgi_application() diff --git a/todo_list/settings.py b/todo_list/settings.py new file mode 100644 index 0000000..ab9bba2 --- /dev/null +++ b/todo_list/settings.py @@ -0,0 +1,125 @@ +""" +Django settings for todo_list project. + +Generated by 'django-admin startproject' using Django 4.2.2. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-%f+7xx$sqhpscwc3#vr_r7saz-#-v9od0&ic1y$^3u@hoi9^uf' + +# 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', + 'base.apps.BaseConfig', +] + +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 = 'todo_list.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 = 'todo_list.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.2/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/4.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + +LOGIN_URL = 'login' + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.2/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/todo_list/urls.py b/todo_list/urls.py new file mode 100644 index 0000000..e123a5a --- /dev/null +++ b/todo_list/urls.py @@ -0,0 +1,23 @@ +""" +URL configuration for todo_list project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path('admin/', admin.site.urls), + path('',include("base.urls")) +] diff --git a/todo_list/wsgi.py b/todo_list/wsgi.py new file mode 100644 index 0000000..e6286b7 --- /dev/null +++ b/todo_list/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for todo_list 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/4.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'todo_list.settings') + +application = get_wsgi_application()