Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed All Tasks #3

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions authentication/templates/authentication/failedLogin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Login Failed 😥</h1>
<h2>Please try again with the correct Credentials that is the username and the password field both are filled and neither of them is empty !</h2>
<a href="{% url 'loginView' %}">Back to the Login Page</a>
</body>
</html>
24 changes: 24 additions & 0 deletions authentication/templates/authentication/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends 'store/base.html' %}

{% block content %}
<h2>Log in</h2>

<form method="POST" >
{% csrf_token %}

{% for field in form %}
<p>
{{ field.label_tag }}<br>
{{ field }}
{% if field.help_text %}
<small style="color: rgb(67, 67, 238)">{{ field.help_text }}</small>
{% endif %}
{% for error in field.errors %}
<p style="color: rgb(151, 5, 5)">{{ error }}</p>
{% endfor %}
</p>
{% endfor %}
<h6 style="color:rgb(151, 5, 5);">{{error}}</h6>
<button type="submit" class="btn btn-primary">Log in</button>
</form>
{% endblock %}
21 changes: 21 additions & 0 deletions authentication/templates/authentication/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends 'store/base.html' %}

{% block content %}
<h2>Sign up</h2>
<form method="post">
{% csrf_token %}
{% for field in form %}
<p>
{{ field.label_tag }}<br>
{{ field }}
{% if field.help_text %}
<small style="color: black">{{ field.help_text }}</small>
{% endif %}
{% for error in field.errors %}
<p style="color:rgb(151, 5, 5);">{{ error }}</p>
{% endfor %}
</p>
{% endfor %}
<button type="submit" class="btn btn-primary">Sign up</button>
</form>
{% endblock %}
14 changes: 14 additions & 0 deletions authentication/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.urls import path
from authentication.views import *

urlpatterns = [
# setting the paths for the Library App

path('login/',loginView, name='loginView'),
path('logout/',logoutView, name='logoutView'),
path('register/',registerView, name='registerView'),
# path(r'^404',"website.views.page_404",name='page_404'),
# path('check/',home,name='home'),
# checking the path here

]
71 changes: 66 additions & 5 deletions authentication/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,74 @@
from django.shortcuts import render
# from django.shortcuts import render,render_to_response,redirect
from django.shortcuts import render,redirect
from django.contrib.auth import login,logout,authenticate
# Create your views here.
from django.contrib import messages
from django.contrib.auth.models import User,auth
from django.http.response import HttpResponse, HttpResponseBase, HttpResponseRedirectBase
from django.core.checks import messages
from django.template import RequestContext
from library.forms import SignUpForm
from django.contrib.auth.forms import UserCreationForm,AuthenticationForm


# Create your views here.

# loginView function
def loginView(request):
pass
if request.method == 'GET':
return render(request,'authentication/login.html',{'form':AuthenticationForm()})
else:
username=request.POST['username']
password=request.POST['password']

if username != '' and password != '':
user = authenticate(request,username,password)
if user is None:
return render(request,'authentication/failedLogin.html',
{'form':AuthenticationForm(),
'error':'Credentials did not match, Please try Again !'})
# return HttpResponse ('Not matched !')

else:
login(request,user)
return redirect('index')
# return HttpResponse ('index')
else:
return render ('authentication/failedLogin.html')

# logoutView function
def logoutView(request):
pass
return redirect('index')
# return HttpResponse ('index')

# registerView function
def registerView(request):
pass
if request.method == 'POST':
form = SignUpForm(request.POST)


if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
raw_password = form.cleaned_data.get('password1')

# authentication starts here
user = authenticate(username=username, password=raw_password)
login(request, user)
return redirect('index')
# return HttpResponse ('index')


else:
form = SignUpForm()
return render(request, 'authentication/register.html', {'form': form})
# return HttpResponse ('<h1>Form</h1>')


# function for the 404 error page but later implemented in other way

# def home(request):
# return HttpResponse ("home check")
# checking the working of the function and the path

# def page_404(request):
# return render_to_response('404.html', RequestContext(request))
21 changes: 21 additions & 0 deletions library/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User

# SignUpForm class
class SignUpForm(UserCreationForm):
first_name = forms.CharField(max_length=20, required=False)
last_name = forms.CharField(max_length=20, required=False)
email = forms.EmailField(max_length=256)

# meta class
class Meta:
model = User
fields = (
'username',
'first_name',
'last_name',
'email',
'password1',
'password2',
)
20 changes: 6 additions & 14 deletions library/settings.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
"""
Django settings for library project.

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

For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""

import django_heroku
import os
Expand All @@ -24,9 +13,12 @@
SECRET_KEY = '==e^87*tib$+f)9$46#-jc&toydks5v^g5ym7wq^shf5(hno3&'

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

DEBUG = False
# <--- for checking the 404 page

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['*']


# Application definition
Expand Down Expand Up @@ -57,7 +49,7 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR,'store/templates/store')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down
19 changes: 4 additions & 15 deletions library/urls.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
"""library URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.1/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
from django.conf.urls.static import static
from django.conf import settings


# including the urlpatterns
urlpatterns = [
path('',include('store.urls')),
path('admin/', admin.site.urls),
path('accounts/',include('django.contrib.auth.urls')),
path('authentication/',include('django.contrib.auth.urls')),
path('',include('authentication.urls')),
]+static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
9 changes: 0 additions & 9 deletions library/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
"""
WSGI config for library 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/2.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application
Expand Down
3 changes: 3 additions & 0 deletions store/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django.contrib import admin
from store.models import *


# Register your models here.

admin.site.register(Book)
admin.site.register(BookCopy)
admin.site.register(UserRating)
35 changes: 35 additions & 0 deletions store/migrations/0003_auto_20210717_1151.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 3.2.5 on 2021-07-17 06:21

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


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('store', '0002_auto_20190607_1302'),
]

operations = [
migrations.AlterField(
model_name='bookcopy',
name='borrow_date',
field=models.DateField(blank=True, null=True),
),
migrations.AlterField(
model_name='bookcopy',
name='borrower',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='borrower', to=settings.AUTH_USER_MODEL),
),
migrations.CreateModel(
name='UserRating',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('rating', models.IntegerField(default=0)),
('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='store.book')),
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='user', to=settings.AUTH_USER_MODEL)),
],
),
]
58 changes: 51 additions & 7 deletions store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
from django.contrib.auth.models import User
# Create your models here.






# Book class
class Book(models.Model):
title = models.CharField(max_length=50)
author = models.CharField(max_length=50)
genre = models.CharField(max_length=50)
title = models.CharField(max_length=200)
author = models.CharField(max_length=200)
genre = models.CharField(max_length=200)
description = models.TextField(null=True)
mrp = models.PositiveIntegerField()
rating = models.FloatField(default=0.0)
Expand All @@ -15,18 +21,56 @@ class Meta:

def __str__(self):
return f'{self.title} by {self.author}'
# use of f strings here



# BookCopy class
class BookCopy(models.Model):
book = models.ForeignKey(Book, on_delete=models.CASCADE)
borrow_date = models.DateField(null=True, blank=True)
book = models.ForeignKey(Book,
on_delete=models.CASCADE)

borrow_date = models.DateField(null=True,
blank=True)

# True status means that the copy is available for issue, False means unavailable
status = models.BooleanField(default=False)
borrower = models.ForeignKey(User, related_name='borrower', null=True, blank=True, on_delete=models.SET_NULL)

borrower = models.ForeignKey(User,
related_name='borrower',
null=True,
blank=True,
on_delete=models.SET_NULL)

def __str__(self):



# use of f strings here

if self.borrow_date:
return f'{self.book.title}, {str(self.borrow_date)}'
else:
return f'{self.book.title} - Available'
return f'{self.book.title} - Available for borrowing'






# UserRating class
class UserRating(models.Model):

user=models.ForeignKey(User,
related_name='user',
null=True,
blank=True,
on_delete=models.SET_NULL)

book = models.ForeignKey(Book,
on_delete=models.CASCADE)

rating = models.IntegerField(default=0)

def __str__(self):
return f'{self.book.title}'
Loading