Note
A newer version of this tutorial using Django 1.9 is available from Leanpub: https://leanpub.com/tangowithdjango19
So far we have been adding in different pieces of functionality to Rango. We’ve been building up the application in this manner to get you familiar with the Django Framework, and to learn about how to construct the various parts of a website that you are likely to make in your own projects. Rango however at the present moment is not very cohesive. In this chapter, we challenge you to improve the application and its user experience by bringing together functionality that we’ve already implemented alongside some awesome new additions.
To make Rango more coherent and integrated it would be nice to add the following functionality.
Note
We won’t be working through all of these tasks right now. Some will be taken care of in Chapter ajax-label, while some will be left to you to complete as additional exercises.
Before we start to add this additional functionality we will make a todo list to plan our workflow for each task. Breaking tasks down into sub-tasks will greatly simplify the implementation so that we are attacking each one with a clear plan. In this chapter, we will provide you with the workflow for a number of the above tasks. From what you have learnt so far, you should be able to fill in the gaps and implement most of it on your own (except those requiring AJAX). In the next chapter, we have included code snipets and elaborated on how to implement these features.
Currently, Rango provides a direct link to external pages. This is not very good if you want to track the number of times each page is clicked and viewed. To count the number of times a page is viewed via Rango you will need to perform the following steps.
Create a new view called track_url(), and map it to URL /rango/goto/ and name it 'name=goto'.
Update the category.html so that it uses /rango/goto/?page_id=XXX instead of using the direct URL, remember to use the url templatetag (i.e. <a href=”{% url ‘goto’ %}?pageid={{page.id}}”>)
If you’re unsure of how to retrieve the page_id querystring from the HTTP GET request, the following code sample should help you.
if request.method == 'GET':
if 'page_id' in request.GET:
page_id = request.GET['page_id']
Always check the request method is of type GET first, then you can access the dictionary request.GET which contains values passed as part of the request. If page_id exists within the dictionary, you can pull the required value out with request.GET['page_id'].
Note
You could also do this without using a querystring, but through the URL instead, i.e. /rango/goto/<page_id>/. In which case you would need to create a urlpattern that pulls out the page_id.
Rango aims to provide users with a helpful directory of page links. At the moment, the search functionality is essentially independent of the categories. It would be nicer to have search integrated into category browsing. Let’s assume that a user will first browse their category of interest first. If they can’t find the page that they want, they can then search for it. If they find a page that is suitable, then they can add it to the category that they are in. Let’s focus on the first problem, of putting search on the category page. To do this, perform the following steps:
If you have swapped over to the django-registration-redux package, then you’ll have to collect the UserProfile data. To do this, instead of re-directed the user to the rango index page, you will need re-direct them to a new form, to collect the website and url details. To add the UserProfile registration functionality:
Another useful feature to let users inspect and edit their own profile. Undertake the following steps to add this functionality.
To let users browse through user profiles, you can create a users page, that lists all the users. If you click on a user page, then you can see their profile (but the user can only edit their own page).