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

task 2 #14

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

task 2 #14

wants to merge 9 commits into from

Conversation

Captain-Kirk83
Copy link

@Captain-Kirk83 Captain-Kirk83 commented May 7, 2020

CSoC Task 2 Submission

I have completed the following tasks

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

Copy link
Member

@krashish8 krashish8 left a comment

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! @Captain-Kirk83 👍
There are many errors, but it's good that you've at least tried. Now, try to fix these errors, or look at the submissions of others to understand how you could have done better!

Comment on lines +12 to +13
username=request.POST['username']
password=request.POST['password']
Copy link
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).

@@ -17,6 +21,13 @@ def bookDetailView(request, bid):
'num_available': None, # set this to the number of copies of the book available, or 0 if the book isn't available
}
# START YOUR CODE HERE
obj=Book.objects.get(id=bid)
Copy link
Member

Choose a reason for hiding this comment

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

This may fail with invalid book ID given in POST request, and would lead to server error. Expected behavior is to inform user with Not found (404) error.



try:
context['books']=Book.objects.filter(title=get_data['title']).filter(author=get_data['author']).filter(genre=get_data['genre'])
Copy link
Member

Choose a reason for hiding this comment

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

During filtering, you could have used icontains instead of an exact match.

Comment on lines 30 to 49
var l=Document.getElementById('loan-button');

l.addEventListener("click",function(){
$.ajax({
url: "/books/loan/",
method: "POST",
data: {
bid: {{ book.id }}
},
success: function(data, status, xhr){
if(data['message'] == "success"){
alert("Book successfully issued");
window.location.replace("/books/loaned/");
}
else{
alert("Unable to issue this book");
}
},
error: function(xhr, status, err){
alert("Some error occured");
Copy link
Member

Choose a reason for hiding this comment

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

There are errors in your Book loan and Book rate function. They aren't working.

There are syntax errors. (Document shall be document, punctutation errors etc)

context = {
'message' : 'success',
}
return render(request, template_name, context=context)


Copy link
Member

Choose a reason for hiding this comment

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

You should add @csrf_exempt here.

Comment on lines +133 to +134
obj=RateModel.booktoRate.objects.get(pk=book_id)
obj.bookRate=request.POST['rate']
Copy link
Member

Choose a reason for hiding this comment

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

This isn't correct.

store/views.py Outdated
Comment on lines 111 to 115
get_data = request.POST
obj=BookCopy.objects.get(book__id=get_data['bid'])
obj.borrower=None
obj.borrow_date=None
obj.status=True
Copy link
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.

Comment on lines +86 to +87
book_id = request.POST['bid']
obj=Book.objects.get(id=book_id)
Copy link
Member

@krashish8 krashish8 May 9, 2020

Choose a reason for hiding this comment

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

This may fail with invalid book ID given in POST request, and would lead to server error. Expected behavior is to inform user with Not found (404) error.

@krashish8
Copy link
Member

Points have been updated! 🎉

@krashish8 krashish8 added the Judged The Pull Requests which are judged label May 9, 2020
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.

None yet

3 participants