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

All Task Completed with added features #11

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

Conversation

king-11
Copy link
Member

@king-11 king-11 commented May 7, 2020

CSoC Task 2 Submission

I have completed the following tasks

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

Addded Features

Supports search on 'Enter' keypress.
It also deals with the user trying to log in and signup again even though already authenticated.
Deployed at: https://pacific-basin-13105.herokuapp.com/

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! @king-11

Comment on lines +7 to +21
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
first_name = models.CharField(max_length=100, blank=True)
last_name = models.CharField(max_length=100, blank=True)
email = models.EmailField(max_length=150)

def __str__(self):
return self.user.username


@receiver(post_save, sender=User)
def update_profile_signal(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)
instance.profile.save()
Copy link
Member

Choose a reason for hiding this comment

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

Good use of receiver decorator! 👍
However, one should create an extra model only if required. Here, the user model is sufficient to store these details.

Comment on lines +17 to +18
user = form.save()
user.refresh_from_db()
Copy link
Member

Choose a reason for hiding this comment

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

Looks good!

TIME_ZONE = 'UTC'
TIME_ZONE = 'Asia/Kolkata'
Copy link
Member

Choose a reason for hiding this comment

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

It's good that you've modified the TIME_ZONE to IST.

Comment on lines +38 to +42
class BookRating(models.Model):
book = models.ForeignKey(Book, on_delete=models.CASCADE)
username = models.ForeignKey(User, on_delete=models.CASCADE)
rating = models.IntegerField(
default=1, validators=[MaxValueValidator(10), MinValueValidator(0)])
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.

You could've used unique_together META option here. However, its fine for this assignment.

Comment on lines +65 to +72
document.querySelectorAll('input').forEach((i) => {
i.addEventListener('keyup', (event) => {
if (event.keyCode === 13) {
event.preventDefault();
document.querySelector("#search_button").click();
}
})
})
Copy link
Member

Choose a reason for hiding this comment

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

Good!

Comment on lines +20 to +22
book = get_object_or_404(Book, pk=bid)
book.rating = BookRating.objects.filter(
book=book).aggregate(rating=Avg('rating'))['rating']
Copy link
Member

Choose a reason for hiding this comment

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

Good to have used aggregation to calculate Avg.

store/views.py Outdated Show resolved Hide resolved
store/views.py Outdated
Comment on lines 125 to 129
bid = request.POST['bid']
book = get_object_or_404(BookCopy, pk=bid)

if book:
book.borrower = None
Copy link
Member

Choose a reason for hiding this comment

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

During the book return, you must validate that the borrower of the book is the current user.

store/views.py Outdated
book = get_object_or_404(Book, pk=bid)

user = request.user
rating = request.POST['rating']
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.

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

@krashish8
Copy link
Member

Points updated! 🎉

@krashish8 krashish8 added the Judged The Pull Requests which are judged label May 9, 2020
@king-11
Copy link
Member Author

king-11 commented May 9, 2020

@krashish8 thanks for your reviews I will make sure these issues don't occur in upcoming assignments.

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

2 participants