Skip to content
This repository was archived by the owner on Jun 16, 2021. It is now read-only.

CSoC Task 2 Submission#7

Open
shubhanshu02 wants to merge 11 commits into
COPS-IITBHU:masterfrom
shubhanshu02:master
Open

CSoC Task 2 Submission#7
shubhanshu02 wants to merge 11 commits into
COPS-IITBHU:masterfrom
shubhanshu02:master

Conversation

@shubhanshu02

Copy link
Copy Markdown
Member

CSoC Task 2 Submission

I have completed the following tasks.

  • Stage 1
  • Stage 2
  • Stage 3
  • Stage 4

@krashish8 krashish8 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on the assignment @shubhanshu02! I loved the originality of your submission. Will update the points later!

</div>
<div class="col-sm-6">
<label class="control-label" for="first_name">First Name*:</label>
<input type="first_name" name="first_name" id="first_name" placeholder="Password">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

placeholder shall not be "Password"

Comment on lines +19 to +23
<div class="col-sm-9">
<label class="control-label" for="password">Password*:</label>
<input type="password" name="password" id="password" placeholder="Password">
Password should be atleast 8 characters long
</div>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is preferable to let the user enter the password twice, for obvious reasons. However, this is fine for this assignment.

Comment thread authentication/views.py
Comment on lines +20 to +21
username = request.POST['username']
password = request.POST['password']

Copy link
Copy Markdown
Member

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

Comment thread authentication/views.py
Comment on lines +90 to +98
# Create a new user
new = User(username= query[0])
# Set password
new.set_password(query[1])
# Set the name of the user
new.first_name = query[2]
new.last_name = query[3]
# Save the User model object
new.save()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have directly used create_user(), however, this is fine!

Comment thread store/models.py
Comment on lines +34 to +35
book = models.ForeignKey(Book, null=True, on_delete=models.SET_NULL)
user = models.ForeignKey(User, null=True, on_delete=models.SET_NULL)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user and book should not be null here, and a better option would be to use on_delete=models.CASCADE

You could have also used unique_together META option here.

Comment thread store/views.py
Comment on lines +33 to +49
totalRatings = UserRating.objects.filter(book = book)
# check if user is logged in
# and rating objects are present for the book
if request.user.is_authenticated and totalRatings.count() > 0:
myRating = totalRatings.filter(user_id = request.user.id).first()
# If user rating is found
if myRating != None:
givenRating = myRating.rating
# Else the rating for the book by the user is None
else:
givenRating = None


context = {
'book': book,
'num_available': available_copies,
'usrating': givenRating,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider the case when another user has rated the book, and the current user hasn't done so. Then the local variable givenRating won't be assigned any value, which will raise an error.

Comment thread store/views.py
Comment on lines +19 to +24
for i in Book.objects.all():
avail.append(i.id)

# If the id in the request is in the list,
if bid in avail:
book = Book.objects.filter(id = bid).first()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good way to call ORM queries. This will run two queries on the database, one to append and the other to filter.

Comment thread store/views.py
Comment on lines +166 to +167
book_id = request.POST['bid']
value = request.POST['value']

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've not put a backend validation on the rating, so the user can easily put invalid values of rating.

Comment thread store/views.py
Comment on lines +138 to +147
if book != None:
# Set status to available
book.status = True
# Set borrower to none
book.borrower = None
# Set borrow date to none
book.borrow_date = None
# Save the object
book.save()
msg = 'success'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be a validation in the backend when a user is returning the book, to make sure that he has only borrowed the book. Otherwise, a simple POST request will make the BookCopy to be returned, and would set its status as True.

@krashish8

Copy link
Copy Markdown
Member

Also, make sure to run python manage.py makemigrations whenever you make any changes to the model.

@krashish8

Copy link
Copy Markdown
Member

Points updated! 🎉

@krashish8 krashish8 added the Judged The Pull Requests which are judged label May 9, 2020
@shubhanshu02

Copy link
Copy Markdown
Member Author

Thanks, @krashish8 for having a look at my PR. I have noted your suggestions and update them in my fork of the submission.

dependabot Bot and others added 4 commits July 21, 2020 09:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Judged The Pull Requests which are judged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants