Skip to content

A more technical version of breadcrumbs, that allows you to create "checkpoints / breadcrumbs" using a decorator on django views, and jump back to them conditionally, if a breadcrumb is set, using breadcrumb_stasher.redirect.

Notifications You must be signed in to change notification settings

bmoyles0117/Django-Breadcrumb-Stasher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Django Breadcrumb Stasher

The purpose of this django plugin, is to easily create "save" points in django views, to return to once the user has completed a certain process. Let's say the user attempts to do a certain action, but must do a DIFFERENT action, before starting the desired action. When the user is done doing the required action, it would certainly be nice if you automatically returned the user to the DESIRED action.

In your views.py file, you could see something like the following. Please note that this will most likely not work by simply dropping it into your current code, although I'd definitely smile if it did!

The real power in this plugin, is that the breadcrumbs could originate from multiple sources, and still all lead back to the original stasher.

import breadcrumb_stasher
from django.shortcuts import render, redirect

# No breadcrumbs existed, the views use this view as the fallback url
def default_action(request):
	return render(request, 'default_action.html')

@breadcrumb_stasher.stash
def desired_action(request):
	# First requirement must be met
	if request.session.get('completed_requirement_1', '0') != '1':
		return redirect('views.required_action_1')

	# Then perhaps another
	if request.session.get('completed_requirement_2', '0') != '1':
		return redirect('views.required_action_2')

	return render(request, 'desired_action.html')

def required_action_1(request):
	if request.method == 'POST':
		request.session['completed_requirement_1'] = '1'

		# Redirect to the most recent breadcrumb, fallback to views.default_action if none are found!
		return breadcrumb_stasher.redirect(request, 'views.default_action')

	return render(request, 'required_action_1.html')

def required_action_2(request):
	if request.method == 'POST':
		request.session['completed_requirement_2'] = '1'

		# Redirect to the most recent breadcrumb, fallback to views.default_action if none are found!
		return breadcrumb_stasher.redirect(request, 'views.default_action')

	return render(request, 'required_action_2.html')

About

A more technical version of breadcrumbs, that allows you to create "checkpoints / breadcrumbs" using a decorator on django views, and jump back to them conditionally, if a breadcrumb is set, using breadcrumb_stasher.redirect.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages