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
joyrideto yourINSTALLED_APPSsetting. - Run
syncdbcommand to initialise thejoyridedatabase tables - Run
collectstaticcommand 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_URLis relative toSTATIC_URL.
- e.g.
- Set this to
Noneif you have already included jQuery in your template so thatjoyride_mediaandjoyride_jstemplate 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-joyrideoptioncookieMonster
- 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-joyrideshowJoyRideElementandshowJoyRideElementOnfields- 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
clickon some element whose id or class isabcthen you need to setshowJoyRideElement=#abcandshowJoyRideElementOn=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
destroyfield- 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_mediatag also includesjQuery,jQuery ModernizerandjQuery Cookiebased on the value of yourJOYRIDE_JQUERY_URL,JOYRIDE_JQUERY_MODERNIZR_URLandJOYRIDE_JQUERY_COOKIE_URLsettings. 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_mediatag can be replaced with two separate tags,joyride_cssandjoyride_js.joyride_jsaccepts 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_joyridesandget_joyride,include_joyrideto include multiple joyride tours or single joyride tour respectively in template. -
get_joyridesandget_joyrideboth tags accept parameters to filter the joyrides. Following filters are common in both:url_pathfilter joyrides by url path.- e.g.
{% get_joyrides url_path=request.path as joyrides %} - If you have left
url_pathempty while configuring joyride in admin then in order to get those joyride whoseurl_pathis empty you would do{% get_joyrides url_path="" as joyrides %}
- e.g.
for_userfilter joyrides by user if you are usingJoyRideHistorymodel 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.
slugonly used withget_joyrideto 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_joyridesome 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.