Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
22 changes: 22 additions & 0 deletions nitkarshchourasia/django_projects/ToDo_webapp/manage.py
Original file line number Diff line number Diff line change
@@ -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_site.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()
Empty file.
6 changes: 6 additions & 0 deletions nitkarshchourasia/django_projects/ToDo_webapp/todo/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.contrib import admin
from .models import Todo

# Register your models here.

admin.site.register(Todo)
6 changes: 6 additions & 0 deletions nitkarshchourasia/django_projects/ToDo_webapp/todo/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class TodoConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "todo"
8 changes: 8 additions & 0 deletions nitkarshchourasia/django_projects/ToDo_webapp/todo/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django import forms
from .models import Todo


class TodoForm(forms.ModelForm):
class Meta:
model = Todo
fields = "__all__"
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 4.2.5 on 2023-09-30 16:11

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):
initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="Todo",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("title", models.CharField(max_length=100)),
("details", models.TextField()),
("date", models.DateTimeField(default=django.utils.timezone.now)),
],
),
]
14 changes: 14 additions & 0 deletions nitkarshchourasia/django_projects/ToDo_webapp/todo/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Any
from django.db import models
from django.utils import timezone

# Create your models here.


class Todo(models.Model):
title = models.CharField(max_length=100)
details = models.TextField()
date = models.DateTimeField(default=timezone.now)

def __str__(self) -> str:
return self.title
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>

<meta charset="utf-8">
<title>{{title}}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!--style-->
<style>
.card {

box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.5),
0 6px 20px 0 rgba(0, 0, 0, 0.39);
background: lightpink;
margin-bottom: 5%;
border-radius: 25px;
padding: 2%;
overflow: auto;
resize: both;
text-overflow: ellipsis;
}

.card:hover {
background: lightblue;
}

.submit_form {

text-align: center;
padding: 3%;
background: pink;
border-radius: 25px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.4),
0 6px 20px 0 rgba(0, 0, 0, 0.36);
}
</style>

</head>

<body class="container-fluid">

{% if messages %}
{% for message in messages %}
<div class="alert alert-info">
<strong>{{message}}</strong>
</div>
{% endfor %}
{% endif %}

<center class="row">
<h1><i>__TODO LIST__</i></h1>
<hr />
</center>

<div class="row">

<div class="col-md-8">

{% for i in list %}
<div class="card">
<center><b>{{i.title}}</b></center>
<hr />
{{i.date}}
<hr />
{{i.details}}
<br />
<br />
<form action="/del/{{i.id}}" method="POST" style=" padding-right: 4%; padding-bottom: 3%;">
{% csrf_token %}
<button value="remove" type="submit" class="btn btn-primary" style="float: right;"><span
class="glyphicon glyphicon-trash"></span> remove</button>
</form>
</div>
{% endfor%}
</div>
<div class="col-md-1"> </div>
<div class="col-md-3">
<div class="submit_form">
<form method="POST">
{% csrf_token %}
{{forms}}
<center>
<input type="submit" class="btn btn-default" value="submit" />
</center>
</form>
</div>
</div>
</div>
</body>

</html>
3 changes: 3 additions & 0 deletions nitkarshchourasia/django_projects/ToDo_webapp/todo/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
35 changes: 35 additions & 0 deletions nitkarshchourasia/django_projects/ToDo_webapp/todo/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from django.shortcuts import render, redirect
from django.contrib import messages

# Create your views here.

# Import todo form and models

from .forms import TodoForm
from .models import Todo


def index(request):
item_list = Todo.objects.order_by("-date")
if request.method == "POST":
form = TodoForm(request.POST)
if form.is_valid():
form.save()
return redirect("todo")
form = TodoForm()

page = {
"forms": form,
"list": item_list,
"title": "TODO LIST",
}

return render(request, "todo/index.html", page)

### Function to remove item, it receives todo item_id as primary key from url ##

def remove(request, item_id):
item = Todo.objects.get(id=item_id)
item.delete()
messages.info(request, "item removed !!!")
return redirect("todo")
Empty file.
16 changes: 16 additions & 0 deletions nitkarshchourasia/django_projects/ToDo_webapp/todo_site/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for todo_site 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_site.settings")

application = get_asgi_application()
124 changes: 124 additions & 0 deletions nitkarshchourasia/django_projects/ToDo_webapp/todo_site/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
"""
Django settings for todo_site project.

Generated by 'django-admin startproject' using Django 4.2.5.

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-5xdo&zrjq^i)0^g9v@_2e_r6+-!02807i$1pjhcm=19m7yufbz"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
"todo",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]

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_site.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_site.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


# 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"
25 changes: 25 additions & 0 deletions nitkarshchourasia/django_projects/ToDo_webapp/todo_site/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
URL configuration for todo_site 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
from todo import views

urlpatterns = [
path("", views.index, name="todo"),
path("del/<str:item_id>", views.remove, name="del"),
path("admin/", admin.site.urls),
]
Loading