Skip to content

Commit

Permalink
Merge pull request #24 from HARSH-PRANJAL/harsh_patch1
Browse files Browse the repository at this point in the history
Adding new To Do app
  • Loading branch information
ianshulx committed May 10, 2024
2 parents 9b0f29a + 3ec547e commit de40305
Show file tree
Hide file tree
Showing 35 changed files with 1,028 additions and 0 deletions.
12 changes: 12 additions & 0 deletions To-Do_app/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
django = "*"

[dev-packages]

[requires]
python_version = "3.10"
62 changes: 62 additions & 0 deletions To-Do_app/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
3 changes: 3 additions & 0 deletions To-Do_app/ToDo_app/Authentication/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions To-Do_app/ToDo_app/Authentication/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AuthenticationConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'Authentication'
Empty file.
3 changes: 3 additions & 0 deletions To-Do_app/ToDo_app/Authentication/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions To-Do_app/ToDo_app/Authentication/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.
13 changes: 13 additions & 0 deletions To-Do_app/ToDo_app/Authentication/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.urls import path
from .views import (
RegistrationView,
UserLoginView,
UserLogoutView,
)

urlpatterns = [
# django always checks for cross site forgery so we add csrf_exempt to let other sites send reuest to this url
path("registration", RegistrationView.as_view(), name="registration"),
path("userlogin", UserLoginView.as_view(), name="login"),
path("userlogout", UserLogoutView.as_view(), name="logout"),
]
85 changes: 85 additions & 0 deletions To-Do_app/ToDo_app/Authentication/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import json
from django.shortcuts import render, redirect
from django.views import View
from django.http import JsonResponse
from django.contrib.auth.models import User
from django.db import transaction
from django.contrib import messages
from django.contrib.auth import login, logout, authenticate


# Create your views here.
class RegistrationView(View):
def get(self, request):
messages.get_messages(request)
return render(request, "authentication/register.html")

def post(self, request):

# get user data
data = request.POST
username = data.get("username")
email = data.get("email")
password = data.get("password")

context = {"fieldValues": request.POST}

# validate
if not User.objects.filter(username=username).exists():
if not User.objects.filter(email=email).exists():
if len(password) < 8:
messages.error(request, "Password should be 8 charecter long")
return render(request, "authentication/register.html", context)
else:
# new nuser creation process
try:
# adding user to data base
user = User.objects.create_user(username=username, email=email)
user.set_password(password)
user.save()
transaction.commit()
messages.success(request, "Account created")
except Exception as e:
messages.error(request, f"Server - Database warning {str(e)}")
transaction.rollback()
else:
messages.error(request, "Email already exists")
return render(request, "authentication/register.html", context)
else:
messages.error(request, "User name already exists")
return render(request, "authentication/register.html", context)

return redirect("login")


class UserLoginView(View):
def get(self, request):
return render(request, "authentication/login.html")

def post(self, request):
data = request.POST
username = data.get("username")
password = data.get("password")

if username and password:
user = authenticate(username=username, password=password)
if user:
if user.is_active:
login(request, user)
messages.success(request, "Logged in successfully.")
return redirect("index") # Redirect to the expenses page
else:
messages.error(request, "Your account is not active.")
else:
messages.error(request, "Invalid username or password.")
else:
messages.error(request, "Please provide both username and password.")

return redirect("login")


class UserLogoutView(View):
def get(self, request):
logout(request)
messages.success(request, "Logout successfully.")
return redirect("login")
Empty file.
3 changes: 3 additions & 0 deletions To-Do_app/ToDo_app/Items/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions To-Do_app/ToDo_app/Items/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ItemsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'Items'
38 changes: 38 additions & 0 deletions To-Do_app/ToDo_app/Items/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 5.0.5 on 2024-05-07 09:36

import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Category',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='Items',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateField(default=django.utils.timezone.now, null=True)),
('description', models.TextField(null=True)),
('category', models.CharField(max_length=100)),
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ['-date'],
},
),
]
19 changes: 19 additions & 0 deletions To-Do_app/ToDo_app/Items/migrations/0002_alter_items_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0.5 on 2024-05-07 17:08

import datetime
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('Items', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='items',
name='date',
field=models.DateField(default=datetime.date.today, null=True),
),
]
18 changes: 18 additions & 0 deletions To-Do_app/ToDo_app/Items/migrations/0003_alter_items_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.5 on 2024-05-07 17:14

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('Items', '0002_alter_items_date'),
]

operations = [
migrations.AlterField(
model_name='items',
name='date',
field=models.DateField(null=True),
),
]
18 changes: 18 additions & 0 deletions To-Do_app/ToDo_app/Items/migrations/0004_items_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.5 on 2024-05-07 20:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('Items', '0003_alter_items_date'),
]

operations = [
migrations.AddField(
model_name='items',
name='status',
field=models.BooleanField(default=False),
),
]
Empty file.
28 changes: 28 additions & 0 deletions To-Do_app/ToDo_app/Items/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.db import models
from django.contrib.auth.models import User

# Create your models here.


class Items(models.Model):
date = models.DateField(null=True)
description = models.TextField(null=True)
owner = models.ForeignKey(to=User, on_delete=models.CASCADE)
status = models.BooleanField(default=False)
category = models.CharField(max_length=100)

def get_formatted_date(self):
return self.date.strftime("%Y-%m-%d") if self.date else None

def __str__(self):
return (str(self.owner) +" " + str(self.source))

class Meta:
ordering = ["-date"]


class Category(models.Model):
name = models.CharField(max_length=255)

def __str__(self):
return self.name
3 changes: 3 additions & 0 deletions To-Do_app/ToDo_app/Items/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.
10 changes: 10 additions & 0 deletions To-Do_app/ToDo_app/Items/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.urls import path
from . import views

urlpatterns = [
path("", views.index, name="index"),
path("addItems", views.addItems, name="addItems"),
path("deleteItems", views.deleteItems, name="deleteItems"),
path("updateItems", views.updateItems, name="updateItems"),
path("statusItems", views.statusItems, name="statusItems"),
]
Loading

0 comments on commit de40305

Please sign in to comment.