Python Project Week: Yelp Clone in Python/Django. It’s finished!
Last week, two cohort mates and myself began cloning Yelp.com for our Python project week. We used Python, together with the Django back end framework and the built-in SQLite ORM database. We used Twitter Bootstrap 4 for styling and threw in a little jQuery to make it just a teeny bit more dynamic.
Due to the Thanksgiving holiday beginning on Thursday, we only had three days, versus the usual five days of a normal project week. Thus, we pared down our feature wish list a bit and focused on creating a bug free web app, ensuring that the features that we did build in would actually work correctly. We decided to do that instead of over-reaching, attempting to add awesome features, and ending up with a buggy mess. So, some of our cooler ideas, such as Google Places API integration, had to be put on the back burner.
One of the more interesting elements of this project was the management aspect. Since I was acting as project manager for our team, I had to make important decisions multiple times a day. I had to take the initiative to interrupt development to call team meetings to ensure team cohesion, and made overarching decisions regarding the long term view of what the end-product would look like and what features it would have, or lack. Since I was the youngest member of my team I felt a little uncomfortable directing my cohort mates, however, my assigning specific assignments and duties to each member of our small team went a long way in ensuring that each person worked on the area that they had the strongest skills in and that they were interested in working on.
I found that I really enjoyed that managerial aspect of development. I always enjoy leading people, since, as a leader, I must present confidently and with knowledge and experience. This drives me to become the best version of myself that I can be.
On a technical level, I found it rather interesting to debug routing. While it was easy, as the developer, to navigate the website without incurring any errors, I realized that there were many cases where users would receive error messages. For example, attempting to access the user’s profile page without being logged in caused an error and was a bit tricky to fix, due to the URL having a named capture group expecting to see a user ID.
urlpatterns = [url(r’^user/(?P<user_id>\d+)$’, views.show), #This caused an error if a non-logged in user attempted to navigate through this route.url(r’^user/$’, views.show_error, ), #Since a non-logged in user would be missing a user id to input to the named capture group, this route would handle it and route him to the login page with an appropriate flash message.]
If a non logged in user attempted to login he would be presented with a 404 error message, since that URL doesn’t exist. The solution for that was to create an entirely new url that would redirect to the previous page with a “You aren’t logged in. Please log in to access your Profile Page” flash message.
Another issue we had to deal with was during creation of new businesses and their insertion into the database. We calculated the average rating of each business based on the cumulative ratings of all users who reviewed that business and displayed that average rating on the businesses page. However, a newly created business doesn’t have any ratings, which caused an error. The solution for that was a simple try/except ZeroDivisionError statement at the average ratings calculation.
# This view returns the business that the user clicked on.def bus_results(request, bus_id): context = {"bus_id" : Business.objects.get(id=bus_id), "rating_key" : Review.objects.filter(business=Business.objects.get(id=bus_id))}#Try/Except so no error is returned since there are no reviews for newly created businesses.try: count = 0 sum = 0 for x in: context[rating_key"]: sum += x.rating count += 1 avg = sum/count return render(request, "business_app/bus_results.html", {"context": context, "avg": avg}) #created dict to pass in 2 variablesexcept ZeroDivisionError: return render(request, "business_app/bus_results.html", {"context": context, "avg": "No Rating Yet"})
Although many of the problems we faced were not extremely difficult or requiring deep technical knowledge, the accumulation of all the various bugs could have had a major impact on the user experience of our web app and chasing down the various bugs took a fair amount of time.
It was time well worth it, though! Our web app, Kelp, runs smoothly and bug free!