├── .gitignore ├── LICENSE ├── README.md ├── azure-pipelines.yml ├── requirements.txt ├── results └── django-to-do.gif └── todo ├── manage.py ├── static ├── css │ └── custom.css └── images │ ├── dexter.gif │ ├── dexter.png │ ├── tasker.png │ └── wa.png ├── tasks ├── __init__.py ├── admin.py ├── apps.py ├── migrations │ ├── 0001_initial.py │ ├── 0002_task_priority.py │ ├── 0003_task_complete.py │ ├── 0004_auto_20180506_0853.py │ ├── 0005_auto_20180506_0932.py │ ├── 0006_auto_20180506_0940.py │ ├── 0007_auto_20180506_0946.py │ ├── 0008_auto_20180507_0326.py │ ├── 0009_auto_20180507_0328.py │ └── __init__.py ├── models.py ├── templates │ ├── base.html │ └── tasks.html ├── templatetags │ └── tags.py ├── tests.py ├── urls.py └── views.py └── todo ├── __init__.py ├── settings.py ├── urls.py └── wsgi.py /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | *.pyc 3 | *.sqlite3 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Omkar Pathak 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Django-to-do 2 | A dead simple Django ToDo Web App 3 | 4 | This is a sample project that a novice django developer can use to get started. 5 | 6 | ## Working 7 | 8 | ![Django to do](results/django-to-do.gif) 9 | 10 | ## Features 11 | 12 | - Dead simple 13 | - Easily add, delete 14 | - Simple UI 15 | - Blazing fast 16 | 17 | ## Setup 18 | 19 | - Download the files from this repo 20 | - Change the directory to the folder where you downloaded files 21 | - For installing required packages, execute the following command in terminal: 22 | 23 | ```bash 24 | $pip install -r requirements.txt 25 | ``` 26 | 27 | - After successful installation execute the following commands: 28 | 29 | ```bash 30 | $python manage.py migrate 31 | $python manage.py runserver 32 | ``` 33 | 34 | - Visit `127.0.0.1:8000` in your browser to enjoy the awesome app! 35 | 36 | Built with ♥ by [`Omkar Pathak`](http://www.omkarpathak.in/) 37 | 38 | # Donation 39 | 40 | If you have found my softwares to be of any use to you, do consider helping me pay my internet bills. This would encourage me to create many such softwares :) 41 | 42 | | PayPal | Donate via PayPal! | 43 | |:-------------------------------------------:|:-------------------------------------------------------------:| 44 | | ₹ (INR) | Donate via Instamojo | 45 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | # Python Django 2 | # Test a Django project on multiple versions of Python. 3 | # Add steps that analyze code, save build artifacts, deploy, and more: 4 | # https://docs.microsoft.com/vsts/pipelines/languages/python 5 | 6 | pool: 7 | vmImage: 'Ubuntu 16.04' 8 | strategy: 9 | matrix: 10 | Python35: 11 | PYTHON_VERSION: '3.5' 12 | Python36: 13 | PYTHON_VERSION: '3.6' 14 | Python37: 15 | PYTHON_VERSION: '3.7' 16 | maxParallel: 3 17 | 18 | steps: 19 | - task: UsePythonVersion@0 20 | inputs: 21 | versionSpec: '$(PYTHON_VERSION)' 22 | architecture: 'x64' 23 | 24 | - task: PythonScript@0 25 | displayName: 'Export project path' 26 | inputs: 27 | scriptSource: 'inline' 28 | script: | 29 | """Search all subdirectories for `manage.py`.""" 30 | from glob import iglob 31 | from os import path 32 | # Python >= 3.5 33 | manage_py = next(iglob(path.join('**', 'manage.py'), recursive=True), None) 34 | if not manage_py: 35 | raise SystemExit('Could not find a Django project') 36 | project_location = path.dirname(path.abspath(manage_py)) 37 | print('Found Django project in', project_location) 38 | print('##vso[task.setvariable variable=projectRoot]{}'.format(project_location)) 39 | 40 | - script: | 41 | python -m pip install --upgrade pip setuptools wheel 42 | pip install -r requirements.txt 43 | pip install unittest-xml-reporting 44 | displayName: 'Install prerequisites' 45 | 46 | - script: | 47 | pushd '$(projectRoot)' 48 | python manage.py test --testrunner xmlrunner.extra.djangotestrunner.XMLTestRunner --no-input 49 | condition: succeededOrFailed() 50 | displayName: 'Run tests' 51 | 52 | - task: PublishTestResults@2 53 | inputs: 54 | testResultsFiles: "**/TEST-*.xml" 55 | testRunTitle: 'Python $(PYTHON_VERSION)' 56 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Django==2.0.8 2 | pytz==2018.4 3 | -------------------------------------------------------------------------------- /results/django-to-do.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OmkarPathak/Django-to-do/3acbb8d91e375fb18fbc0b53931d76a5ca5a7b06/results/django-to-do.gif -------------------------------------------------------------------------------- /todo/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "todo.settings") 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /todo/static/css/custom.css: -------------------------------------------------------------------------------- 1 | .adanger{ 2 | color: #dc3545; /* red */ 3 | } 4 | 5 | .bwarning{ 6 | color: #ffc107; /* orange */ 7 | } 8 | 9 | .csuccess{ 10 | color: #28a745; /* green */ 11 | } 12 | 13 | .dprimary{ 14 | color: #007bff; /* blue */ 15 | } 16 | 17 | .adanger:hover{ 18 | color: #dc3545; /* red */ 19 | } 20 | 21 | .bwarning:hover{ 22 | color: #ffc107; /* orange */ 23 | } 24 | 25 | .csuccess:hover{ 26 | color: #28a745; /* green */ 27 | } 28 | 29 | .dprimary:hover{ 30 | color: #007bff; /* blue */ 31 | } 32 | -------------------------------------------------------------------------------- /todo/static/images/dexter.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OmkarPathak/Django-to-do/3acbb8d91e375fb18fbc0b53931d76a5ca5a7b06/todo/static/images/dexter.gif -------------------------------------------------------------------------------- /todo/static/images/dexter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OmkarPathak/Django-to-do/3acbb8d91e375fb18fbc0b53931d76a5ca5a7b06/todo/static/images/dexter.png -------------------------------------------------------------------------------- /todo/static/images/tasker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OmkarPathak/Django-to-do/3acbb8d91e375fb18fbc0b53931d76a5ca5a7b06/todo/static/images/tasker.png -------------------------------------------------------------------------------- /todo/static/images/wa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OmkarPathak/Django-to-do/3acbb8d91e375fb18fbc0b53931d76a5ca5a7b06/todo/static/images/wa.png -------------------------------------------------------------------------------- /todo/tasks/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OmkarPathak/Django-to-do/3acbb8d91e375fb18fbc0b53931d76a5ca5a7b06/todo/tasks/__init__.py -------------------------------------------------------------------------------- /todo/tasks/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Task, Username 3 | 4 | # Register your models here. 5 | class MyModelAdmin(admin.ModelAdmin): 6 | class Meta: 7 | model = Task 8 | 9 | class UsernameAdmin(admin.ModelAdmin): 10 | class Meta: 11 | model = Username 12 | 13 | admin.site.register(Task, MyModelAdmin) 14 | admin.site.register(Username, UsernameAdmin) 15 | -------------------------------------------------------------------------------- /todo/tasks/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class TasksConfig(AppConfig): 5 | name = 'tasks' 6 | -------------------------------------------------------------------------------- /todo/tasks/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.0.5 on 2018-05-03 09:49 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | initial = True 9 | 10 | dependencies = [ 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Task', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('title', models.CharField(max_length=200)), 19 | ('description', models.CharField(blank=True, max_length=1000)), 20 | ('date_of_creation', models.DateTimeField(auto_now_add=True)), 21 | ], 22 | ), 23 | ] 24 | -------------------------------------------------------------------------------- /todo/tasks/migrations/0002_task_priority.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.0.5 on 2018-05-04 10:14 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('tasks', '0001_initial'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='task', 15 | name='priority', 16 | field=models.CharField(choices=[('danger', 'Priority 1'), ('warning', 'Priority 2'), ('success', 'Priority 3'), ('primary', 'Priority 4')], default='danger', max_length=30), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /todo/tasks/migrations/0003_task_complete.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.0.4 on 2018-05-05 04:06 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('tasks', '0002_task_priority'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='task', 15 | name='complete', 16 | field=models.IntegerField(default=0), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /todo/tasks/migrations/0004_auto_20180506_0853.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.0.5 on 2018-05-06 08:53 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('tasks', '0003_task_complete'), 10 | ] 11 | 12 | operations = [ 13 | migrations.CreateModel( 14 | name='Username', 15 | fields=[ 16 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 17 | ('username', models.CharField(max_length=50)), 18 | ], 19 | ), 20 | migrations.AlterField( 21 | model_name='task', 22 | name='priority', 23 | field=models.CharField(choices=[('adanger', 'Priority 1'), ('bwarning', 'Priority 2'), ('csuccess', 'Priority 3'), ('dprimary', 'Priority 4')], default='adanger', max_length=30), 24 | ), 25 | ] 26 | -------------------------------------------------------------------------------- /todo/tasks/migrations/0005_auto_20180506_0932.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.0.5 on 2018-05-06 09:32 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('tasks', '0004_auto_20180506_0853'), 10 | ] 11 | 12 | operations = [ 13 | migrations.DeleteModel( 14 | name='Username', 15 | ), 16 | migrations.AddField( 17 | model_name='task', 18 | name='username', 19 | field=models.CharField(default='omkar', max_length=50, unique=True), 20 | preserve_default=False, 21 | ), 22 | ] 23 | -------------------------------------------------------------------------------- /todo/tasks/migrations/0006_auto_20180506_0940.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.0.5 on 2018-05-06 09:40 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('tasks', '0005_auto_20180506_0932'), 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Username', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('username', models.CharField(max_length=50, unique=True)), 19 | ], 20 | ), 21 | migrations.AlterField( 22 | model_name='task', 23 | name='username', 24 | field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tasks.Username'), 25 | ), 26 | ] 27 | -------------------------------------------------------------------------------- /todo/tasks/migrations/0007_auto_20180506_0946.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.0.5 on 2018-05-06 09:46 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('tasks', '0006_auto_20180506_0940'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='task', 15 | name='id', 16 | field=models.AutoField(primary_key=True, serialize=False), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /todo/tasks/migrations/0008_auto_20180507_0326.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.0.5 on 2018-05-07 03:26 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('tasks', '0007_auto_20180506_0946'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='task', 15 | name='priority', 16 | field=models.CharField(choices=[('adanger', 'Priority 1'), ('bwarning', 'Priority 2'), ('csuccess', 'Priority 3'), ('dprimary', 'Priority 4')], default='Select Priority', max_length=30), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /todo/tasks/migrations/0009_auto_20180507_0328.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.0.5 on 2018-05-07 03:28 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('tasks', '0008_auto_20180507_0326'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='task', 15 | name='priority', 16 | field=models.CharField(choices=[('adanger', 'Priority High'), ('bwarning', 'Priority Medium'), ('csuccess', 'Priority Low')], default='adanger', max_length=30), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /todo/tasks/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OmkarPathak/Django-to-do/3acbb8d91e375fb18fbc0b53931d76a5ca5a7b06/todo/tasks/migrations/__init__.py -------------------------------------------------------------------------------- /todo/tasks/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.forms import ModelForm 3 | from django import forms 4 | 5 | PRIORITIES = ( 6 | ('adanger', 'Priority High'), 7 | ('bwarning', 'Priority Medium'), 8 | ('csuccess', 'Priority Low') 9 | ) 10 | 11 | # Create your models here. 12 | class Username(models.Model): 13 | username = models.CharField(max_length=50, unique=True) 14 | 15 | def __str__(self): 16 | return self.username 17 | 18 | class Task(models.Model): 19 | id = models.AutoField(primary_key=True) 20 | username = models.ForeignKey(Username, on_delete=models.CASCADE) 21 | title = models.CharField(max_length=200) 22 | description = models.CharField(max_length=1000, blank=True) 23 | date_of_creation = models.DateTimeField(auto_now_add=True) 24 | priority = models.CharField( 25 | max_length=30, 26 | choices=PRIORITIES, 27 | default=PRIORITIES[0][0] 28 | ) 29 | complete = models.IntegerField(default=0) 30 | 31 | class TaskForm(ModelForm): 32 | class Meta: 33 | model = Task 34 | fields = '__all__' 35 | exclude = ['complete', 'date_of_creation', 'username'] 36 | widgets = { 37 | 'title': forms.TextInput(attrs={'placeholder': "What's on your mind today?"}), 38 | 'description': forms.Textarea(attrs={'placeholder': "Describe your task ..", 'cols': 80, 'rows': 3}), 39 | } 40 | 41 | class UsernameForm(ModelForm): 42 | class Meta: 43 | model = Username 44 | fields = '__all__' 45 | 46 | widgets = { 47 | 'username': forms.TextInput(attrs={'placeholder': "Enter a username"}), 48 | } 49 | 50 | def clean_username(self): 51 | username = self.cleaned_data.get('username') 52 | queryset = Username.objects.filter(username=username).count() 53 | if queryset > 0: 54 | raise forms.ValidationError('This username is already taken! Try a different one :)') 55 | return username 56 | -------------------------------------------------------------------------------- /todo/tasks/templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | {% load static %} 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | {% block title %}{% endblock %} 33 | 34 | 35 | 36 |
37 | {% block content %} 38 | 39 | {% endblock %} 40 |
41 | 42 | 43 | 44 | 45 | 46 | 47 | {% block javascript %}{% endblock %} 48 | 49 | 50 | -------------------------------------------------------------------------------- /todo/tasks/templates/tasks.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} 2 | {% load tags %} 3 | {% load static %} 4 | 5 | {% block title %}Taskकर{% endblock %} 6 | 7 | {% block content %} 8 |
9 |
10 |
11 | dexter 12 |
13 |
14 |
15 |
16 |
17 | 18 | 21 |
22 |
23 |
24 |
25 | 26 | 27 | 77 | 78 |
79 |
80 |
81 | {% for task in tasks %} 82 |
83 |
84 |
85 | {{ task.title }} 86 | 87 | {% if task.description %} 88 |
89 |
90 |
91 |
92 | {{ task.description }} 93 |
94 |
95 |
96 |
97 | {% endif %} 98 |
99 |
100 |
101 | 102 | 103 |
104 |
105 |
106 |
107 | {% endfor %} 108 |
109 |
110 |
111 | 112 |
113 | Made with ☕ and ♥ by Omkar & Chinmay 114 | 115 |
116 | 117 | We use 🍪 for the best experience 118 | 119 |
120 | 121 | © 2018. All rights reserved. 122 |
123 | {% endblock %} 124 | 125 | 126 | {% block javascript %} 127 | 132 | {% endblock %} 133 | -------------------------------------------------------------------------------- /todo/tasks/templatetags/tags.py: -------------------------------------------------------------------------------- 1 | from django import template 2 | 3 | register = template.Library() 4 | 5 | @register.filter(name='add_css') 6 | def add_css(field, css): 7 | """Removes all values of arg from the given string""" 8 | return field.as_widget(attrs={"class": css}) 9 | -------------------------------------------------------------------------------- /todo/tasks/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /todo/tasks/urls.py: -------------------------------------------------------------------------------- 1 | """todo URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/2.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.urls import path, include 17 | from . import views 18 | 19 | urlpatterns = [ 20 | path('delete//', views.delete, name='delete_task'), 21 | path('complete//', views.complete, name='completed_task'), 22 | path('', views.tasks, name='tasks'), 23 | ] 24 | -------------------------------------------------------------------------------- /todo/tasks/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render, redirect, reverse, render_to_response 2 | from django.http import HttpResponseRedirect,HttpResponse 3 | from .models import TaskForm, Task, UsernameForm, Username 4 | from django.template import RequestContext 5 | 6 | # Create your views here. 7 | 8 | def tasks(request): 9 | if request.method == 'POST': 10 | # this is wehere POST request is accessed 11 | form = TaskForm(request.POST or None) 12 | if form.is_valid(): 13 | user = Username.objects.get(username=request.COOKIES.get('username')) 14 | temp = form.save(commit=False) 15 | temp.username = user 16 | temp.save() 17 | form = TaskForm() 18 | tasks = Task.objects.filter(username__username=request.COOKIES.get('username')).order_by('priority') 19 | return render(request, 'tasks.html', {'form': form, 'tasks': tasks, 'user': user}) 20 | else: 21 | if 'username' not in request.COOKIES: 22 | from django.utils.crypto import get_random_string 23 | unique_id = get_random_string(length=32) 24 | username = Username() 25 | username.username = unique_id 26 | username.save() 27 | response = redirect(reverse('tasks')) 28 | # 604800s = 1 week 29 | response.set_cookie('username', username, max_age=604800) 30 | return response 31 | # this is where GET request are accessed 32 | form = TaskForm() 33 | tasks = Task.objects.filter(username__username=request.COOKIES.get('username')).order_by('priority') 34 | user = Username.objects.filter(username=request.COOKIES.get('username')) 35 | return render(request, 'tasks.html', {'form': form, 'tasks': tasks, 'user': user}) 36 | 37 | def check_user_validity(request): 38 | ''' 39 | Check if user such user exists in Database 40 | ''' 41 | 42 | try: 43 | return Username.objects.get(username__exact=request.COOKIES["username"]) 44 | except Exception: 45 | return False 46 | 47 | def delete(request, id): 48 | if 'username' in request.COOKIES and check_user_validity(request): 49 | #now check if user trying to access this task actually created this task 50 | Task.objects.filter(id=id,username=Username.objects.get(username__exact=request.COOKIES["username"])).delete() 51 | return redirect(reverse('tasks')) 52 | else: 53 | return HttpResponse("You are not allowed to access this resource") 54 | 55 | def complete(request, id): 56 | if 'username' in request.COOKIES and check_user_validity(request): 57 | try: 58 | task=Task.objects.get(id=id,username=Username.objects.get(username__exact=request.COOKIES["username"])) 59 | if task.complete: 60 | task.complete = 0 61 | else: 62 | task.complete = 1 63 | task.save() 64 | return redirect('/') 65 | except Exception: 66 | return HttpResponse("Sorry You are not allowed to access This task ") 67 | else: 68 | return HttpResponse("You are not allowed to access this resource") 69 | 70 | 71 | 72 | def clear(request): 73 | Username.objects.filter(username=request.COOKIES['username']).delete() 74 | response = HttpResponseRedirect('/tasks/') 75 | response.delete_cookie('username') 76 | return response 77 | -------------------------------------------------------------------------------- /todo/todo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OmkarPathak/Django-to-do/3acbb8d91e375fb18fbc0b53931d76a5ca5a7b06/todo/todo/__init__.py -------------------------------------------------------------------------------- /todo/todo/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for todo project. 3 | 4 | Generated by 'django-admin startproject' using Django 2.0.4. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/2.0/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = '0*$jmq3(h$)w-us0g6uz*!(k%-x1j-+pmo%r)oky^h1491o60#' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = ['*'] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'tasks', 41 | ] 42 | 43 | MIDDLEWARE = [ 44 | 'django.middleware.security.SecurityMiddleware', 45 | 'django.contrib.sessions.middleware.SessionMiddleware', 46 | 'django.middleware.common.CommonMiddleware', 47 | 'django.middleware.csrf.CsrfViewMiddleware', 48 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | ] 52 | 53 | ROOT_URLCONF = 'todo.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [os.path.join(BASE_DIR, 'templates')], 59 | 'APP_DIRS': True, 60 | 'OPTIONS': { 61 | 'context_processors': [ 62 | 'django.template.context_processors.debug', 63 | 'django.template.context_processors.request', 64 | 'django.contrib.auth.context_processors.auth', 65 | 'django.contrib.messages.context_processors.messages', 66 | ], 67 | }, 68 | }, 69 | ] 70 | 71 | WSGI_APPLICATION = 'todo.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/2.0/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/2.0/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_L10N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/2.0/howto/static-files/ 120 | 121 | STATIC_URL = '/static/' 122 | 123 | STATICFILES_DIRS = [ 124 | os.path.join(BASE_DIR, 'static'), 125 | ] 126 | -------------------------------------------------------------------------------- /todo/todo/urls.py: -------------------------------------------------------------------------------- 1 | """todo URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/2.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path, include 18 | from tasks import views 19 | 20 | urlpatterns = [ 21 | path('clear/', views.clear, name='clear_username'), 22 | path('admin/', admin.site.urls), 23 | path('', include('tasks.urls')), 24 | ] 25 | -------------------------------------------------------------------------------- /todo/todo/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for todo project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "todo.settings") 15 | 16 | application = get_wsgi_application() 17 | --------------------------------------------------------------------------------