-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from HARSH-PRANJAL/harsh_patch1
Adding new To Do app
- Loading branch information
Showing
35 changed files
with
1,028 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
To-Do_app/ToDo_app/Items/migrations/0002_alter_items_date.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
To-Do_app/ToDo_app/Items/migrations/0003_alter_items_date.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
] |
Oops, something went wrong.