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

All stages done - CSOC-task-2#8

Open
PaRaDoX50 wants to merge 2 commits into
COPS-IITBHU:masterfrom
PaRaDoX50:master
Open

All stages done - CSOC-task-2#8
PaRaDoX50 wants to merge 2 commits into
COPS-IITBHU:masterfrom
PaRaDoX50:master

Conversation

@PaRaDoX50

Copy link
Copy Markdown

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! @PaRaDoX50 I loved how you've utilized the related_name field.

Will update the points later!

Comment thread authentication/forms.py

class LoginForm(forms.Form):
username = forms.CharField(max_length=254)
password = forms.CharField(label=("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 must add widget=forms.PasswordInput, so that the input would be a password, not plain text.

Who likes to show his password on the screen to the fellow users? 😅

Comment thread store/models.py
Comment on lines +34 to +36
book = models.ForeignKey(Book, on_delete=models.CASCADE)
rating_by = models.ForeignKey(User, related_name='rating_by', null=False, blank=False, on_delete=models.CASCADE)
rating = models.FloatField()

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.

Also, you could have also used unique_together META option here.

Comment thread store/views.py
Comment on lines +28 to +37
desired_book = get_object_or_404(Book,id=bid)

count = BookCopy.objects.filter(Q(book=desired_book) & Q(status=True)).count()
issued = False
if request.user.is_authenticated:
user_book_copies = request.user.borrower.all()
for bc in user_book_copies:
if bc.book == desired_book:
issued = True
break

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.

Good!

Comment thread store/views.py
# (i.e. the book search feature will also be implemented in this view)
}
get_data = request.GET
print(get_data,"hello")

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.

Hello!! 😃

Comment thread store/views.py
@login_required
def loanBookView(request):
book_id = request.POST.get('bid')
count = BookCopy.objects.filter(Q(book=Book.objects.get(id=book_id)) & Q(status=True)).count()

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 database, one to get the book and another to filter it.
Better, you should've used: book=book_id

Comment thread store/views.py
Comment on lines +149 to +162
bookcopy_id = request.POST.get('bid')
bookcopy = get_object_or_404(BookCopy,id=bookcopy_id)
bookcopy.borrower = None
bookcopy.borrow_date = None
bookcopy.status = True
bookcopy.save()
print(request.POST)
msg = 'success'

response_data={
'message': msg
}

return JsonResponse(response_data)

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.

Comment thread store/views.py
Comment on lines +166 to +174
form = forms.RatingForm(request.POST)
if form.is_valid():
rating = form.cleaned_data.get('rating')
ratings_by_user =request.user.rating_by.all()
print(ratings_by_user,'hellllsaldlasldlasldl')
if ratings_by_user.count() > 0:
rating_object = ratings_by_user[0]
rating_object.rating = rating
rating_object.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'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.

@krashish8

Copy link
Copy Markdown
Member

Points Updated! 🎉

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

Copy link
Copy Markdown
Author

Thank you for reviewing!

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