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

CSOC TASK 2#3

Open
atpug22 wants to merge 8 commits into
COPS-IITBHU:masterfrom
atpug22:master
Open

CSOC TASK 2#3
atpug22 wants to merge 8 commits into
COPS-IITBHU:masterfrom
atpug22:master

Conversation

@atpug22

@atpug22 atpug22 commented May 3, 2020

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 @atpug22 ! Will update the points later!

Comment thread store/admin.py
Comment on lines +7 to +17
@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
list_display = ('title', 'author', 'genre')

# Register the Admin classes for BookInstance using the decorator
@admin.register(BookCopy)
class BookInstanceAdmin(admin.ModelAdmin):
list_filter = ('status', 'borrow_date')
list_display = ('book','status', 'borrow_date')

admin.site.register(BookRating)

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.

Looks good!

Comment thread store/models.py
Comment on lines +34 to +37
class BookRating(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)
ratinguser = models.FloatField(default=0)

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 rating shall be given as an integer - please read proper instructions.
The user 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

def bookDetailView(request, bid):
template_name = 'store/book_detail.html'
book1=Book.objects.get(pk=bid)

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

Comment thread store/views.py
Comment on lines +36 to +39
def bookRatingView(request):
template_name= template_name = 'store/book_detail.html'
book_id = request.POST.get("bid")
rating_value = request.POST.get("rating")

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 simply edit the JS code you've written in the template and easily put invalid values of rating.

Comment thread store/views.py
Comment on lines 135 to +148
def returnBookView(request):
pass
book_id = request.POST.get("bid")
book=BookCopy.objects.get(id=book_id)
if(book):
message="success"
book.status=True
book.borrower=None
book.borrow_date=None
book.save()
else:
message="failure"
response_data = {
'message': message,
}

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 not to commit the virtual environment created by you to git.

@krashish8

Copy link
Copy Markdown
Member

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

2 participants