This repository has been archived by the owner on Jun 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
All task completed #6
Open
aishwary023
wants to merge
7
commits into
COPS-IITBHU:master
Choose a base branch
from
aishwary023:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dbfbf5d
All task completed
aishwary023 a5ecee8
styling change
aishwary023 da760e5
Update models.py
aishwary023 ff370de
Minor changes
aishwary023 bccb95c
Update views.py
aishwary023 d038a21
Set theme jekyll-theme-cayman
aishwary023 eb7edd8
final commit
aishwary023 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
theme: jekyll-theme-cayman |
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,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: grey">{{ field.help_text }}</small> | ||
{% endif %} | ||
{% for error in field.errors %} | ||
<p style="color: red">{{ error }}</p> | ||
{% endfor %} | ||
</p> | ||
{% endfor %} | ||
<h6 style="color: red;">{{error}}</h6> | ||
<button type="submit" class="btn btn-primary">Log in</button> | ||
</form> | ||
{% endblock %} |
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,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: grey">{{ field.help_text }}</small> | ||
{% endif %} | ||
{% for error in field.errors %} | ||
<p style="color: red">{{ error }}</p> | ||
{% endfor %} | ||
</p> | ||
{% endfor %} | ||
<button type="submit" class="btn btn-primary">Sign up</button> | ||
</form> | ||
{% endblock %} |
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,8 @@ | ||
from django.urls import path | ||
from authentication.views import * | ||
|
||
urlpatterns = [ | ||
path('login/',loginView, name='loginView'), | ||
path('logout/',logoutView, name='logoutView'), | ||
path('register/',registerView, name='registerView'), | ||
] |
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 |
---|---|---|
@@ -1,13 +1,35 @@ | ||
from django.shortcuts import render | ||
from django.shortcuts import render,redirect | ||
from django.contrib.auth import login,logout,authenticate | ||
# Create your views here. | ||
from django.contrib.auth.forms import UserCreationForm,AuthenticationForm | ||
from django.contrib.auth.models import User | ||
from django.db import IntegrityError | ||
from library.forms import SignUpForm | ||
|
||
|
||
def loginView(request): | ||
pass | ||
if request.method == 'GET': | ||
return render(request,'authentication/login.html',{'form':AuthenticationForm()}) | ||
else: | ||
user = authenticate(request,username=request.POST['username'],password=request.POST['password']) | ||
if user is None: | ||
return render(request,'authentication/login.html',{'form':AuthenticationForm(),'error':'Username and Password did not match.'}) | ||
else: | ||
login(request,user) | ||
return redirect('index') | ||
|
||
def logoutView(request): | ||
pass | ||
return redirect('index') | ||
|
||
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') | ||
user = authenticate(username=username, password=raw_password) | ||
login(request, user) | ||
return redirect('index') | ||
else: | ||
form = SignUpForm() | ||
return render(request, 'authentication/register.html', {'form': form}) |
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,15 @@ | ||
from django import forms | ||
from django.contrib.auth.forms import UserCreationForm | ||
from django.contrib.auth.models import User | ||
|
||
|
||
class SignUpForm(UserCreationForm): | ||
first_name = forms.CharField(max_length=30, required=False, help_text='Required.') | ||
last_name = forms.CharField(max_length=30, required=False, help_text='Optional.') | ||
email = forms.EmailField(max_length=254, help_text='Required. Input a valid email address.') | ||
|
||
class Meta: | ||
model = User | ||
fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2', ) | ||
|
||
|
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
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
|
||
admin.site.register(Book) | ||
admin.site.register(BookCopy) | ||
admin.site.register(UserRating) |
This file was deleted.
Oops, something went wrong.
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 2.2.1 on 2020-05-06 05: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', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='UserRating', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('rating', models.FloatField(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)), | ||
], | ||
), | ||
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.DeleteModel( | ||
name='Profile', | ||
), | ||
] |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from django.db import models | ||
from django.contrib.auth.models import User | ||
# Create your models here. | ||
|
||
|
||
class Book(models.Model): | ||
title = models.CharField(max_length=50) | ||
|
@@ -17,11 +17,19 @@ def __str__(self): | |
return f'{self.title} by {self.author}' | ||
|
||
|
||
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.FloatField(default=0) | ||
Comment on lines
+20
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rating shall be given as an integer - please read proper instructions. You could have also used |
||
|
||
def __str__(self): | ||
return f'{self.book.title}' | ||
|
||
class BookCopy(models.Model): | ||
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) | ||
status = models.BooleanField(default=True) | ||
borrower = models.ForeignKey(User, related_name='borrower', null=True, blank=True, on_delete=models.SET_NULL) | ||
|
||
def __str__(self): | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are directly accessing POST data without checking if it even exists. This may lead to server crash if a user access this endpoint with invalid request data. The good behavior would have been to throw a client error (400), rather than server error (500).