A django application which gives flexibility to configure Guided Tours on your site through admin panel.
- This application is built on top of jQuery plugin zurb-joyride.
Install from PyPI with easy_install
or pip
:
pip install django-joyride
To use django-joyride
in your Django project:
- Add
joyride
to yourINSTALLED_APPS
setting. - Run
syncdb
command to initialise thejoyride
database tables - Run
collectstatic
command to collect the static files of joyride intoSTATIC_ROOT
Available settings:
-
JOYRIDE_JQUERY_URL
- Set this to different version of jquery in your static folder, If you wish to use a different version of jQuery, or host it yourself
- e.g.
JOYRIDE_JQUERY_URL = 'joyride/js/jquery.min.js'
This will use the jQuery available atSTATIC_URL/joyride/js/jquery.min.js
. A relativeJOYRIDE_JQUERY_URL
is relative toSTATIC_URL
.
- e.g.
- Set this to
None
if you have already included jQuery in your template so thatjoyride_media
andjoyride_js
template tag should not include jQuery to avoid conflict.- e.g.
JOYRIDE_JQUERY_URL = None
- e.g.
- Set this to different version of jquery in your static folder, If you wish to use a different version of jQuery, or host it yourself
-
JOYRIDE_JQUERY_COOKIE_URL
- Same settings as
JOYRIDE_JQUERY_URL
, it decide whether to include or not to include thejquery.cookie.js
. This should be included if you are going to use thezurb-joyride
optioncookieMonster
- Same settings as
-
JOYRIDE_JQUERY_MODERNIZR_URL
- Same settings as
JOYRIDE_JQUERY_URL
, it decide whether to include or not to include the jquery modernizr.
- Same settings as
-
JOYRIDE_LIB_URL
- The model and model fields are self explanatory. All model fields have help text for better understanding. Still if you want more documentation on it then check the comprehensive documentation on
zurb-joyride
- Following model fields are extra and comes in handy:
-
url_path
- The url e.g.
/about/
or url regex/abc/\d+/
of the page for which you are creating the joyride tour. Later on you can use this as a parameter in template tags to filter joyrides based onrequest.path
- The url e.g.
-
The BOTTLENECK of
zurb-joyride
showJoyRideElement
andshowJoyRideElementOn
fields- Arrggh! it is not possible to use multiple joyrides on single page unless previous joyrides are destroyed. So in order to overcome that situation sometime you might want to activate the second joyride tour on some event. Lets say we want our second joyride to be activated when user
click
on some element whose id or class isabc
then you need to setshowJoyRideElement=#abc
andshowJoyRideElementOn=click
.
- Arrggh! it is not possible to use multiple joyrides on single page unless previous joyrides are destroyed. So in order to overcome that situation sometime you might want to activate the second joyride tour on some event. Lets say we want our second joyride to be activated when user
destroy
field- IDs(slug) of joyrides which should be destroyed before invoking this joyride e.g.
destroy=#abc, #cde
- IDs(slug) of joyrides which should be destroyed before invoking this joyride e.g.
-
- Include The Media
- Load the django-joyride template tags
{% load joyride_tags %}
- Include the media (css and js files)
{% joyride_media %}
-
By default the
joyride_media
tag also includesjQuery
,jQuery Modernizer
andjQuery Cookie
based on the value of yourJOYRIDE_JQUERY_URL
,JOYRIDE_JQUERY_MODERNIZR_URL
andJOYRIDE_JQUERY_COOKIE_URL
settings. To suppress the inclusion of these libraries (if you are already including it yourself), set these settings toNone
.If you prefer to link CSS and Javascript from different locations, the
joyride_media
tag can be replaced with two separate tags,joyride_css
andjoyride_js
.joyride_js
accepts parameters to suppress jQuery, jQuery Modernizr and jQuery Cookie inclusion at template level also, just likejoyride_media
- e.g.
{% joyride_js no_jquery="true" no_jquery_modernizr="true" %}
- e.g.
-
- Include the joyride tour(s)
-
You need to use
get_joyrides
,include_joyrides
andget_joyride
,include_joyride
to include multiple joyride tours or single joyride tour respectively in template. -
get_joyrides
andget_joyride
both tags accept parameters to filter the joyrides. Following filters are common in both:url_path
filter joyrides by url path.- e.g.
{% get_joyrides url_path=request.path as joyrides %}
- If you have left
url_path
empty while configuring joyride in admin then in order to get those joyride whoseurl_path
is empty you would do{% get_joyrides url_path="" as joyrides %}
- e.g.
for_user
filter joyrides by user if you are usingJoyRideHistory
model to keep track of joyrides with respect to user.- e.g.
{% get_joyrides for_user=request.user as joyrides %}
# this will get all joyrides for user which are not viewed or cancelled by user.
- e.g.
exclude_viewed
(default=True) if you want to include all joyrides for user irrespective of seen/cancelled or not- e.g.
{% get_joyrides for_user=request.user exclude_viewed=False %}
- e.g.
slug
only used withget_joyride
to get single joyride.- e.g.
{% get_joyride "my-tour-slug" %}
- e.g.
-
Include Multiple joyrides
{% get_joyrides as joyrides %} {% include_joyrides joyrides %}
-
Include Single joyride
{% get_joyride "my-tour-slug" as joyride %} {% include_joyride joyride %}
-
This model is only used if you have registered users on your site and you want to keep track of joyrides which are already viewed by user so that those joyrides should never be shown to user again. It is up to you how you are going to make use of this table. Below is an example:
Set
postRideCallback=mark_viewed_joyride
(A method to call once the tour closes (cancelled or complete)) in admin. Write the javascript callbackmark_viewed_joyride
some where in your template:function mark_joyride(index, tip, id){ $.ajax({ url: '{% url mark_joyride %}', data: {"slug": id}, dataType: 'text', success: function(){ $("#"+id).remove(); // remove the element also from dom } }); }
The view for
{% url mark_joyride %}
would be:@login_required def mark_joyride(request): from joyride.models import JoyRide, JoyRideHistory slug = request.GET.get('slug') joyride = get_object_or_404(JoyRide, slug=slug) user = request.user obj, created = JoyRideHistory.objects.get_or_create(user=user, joyride=joyride) if not created: obj.viewed = True obj.save() return HttpResponse(json.dumps({}), content_type='application/json')
- zurb-joyride This package is built on top of it.
- django-markitup for some help in template tags.