lostplaces-backend/django_lostplaces/lostplaces/common.py

25 lines
741 B
Python
Raw Permalink Normal View History

2020-12-25 12:57:05 +01:00
from django.shortcuts import redirect
2020-11-29 19:22:38 +01:00
def get_all_subclasses(cls):
'''
Gets all subclasses recursively, does not contain
abstract classes
'''
subclass_list = []
for subclass in cls.__subclasses__():
if not subclass._meta.abstract:
subclass_list.append(subclass)
subclass_list += get_all_subclasses(subclass)
2020-12-25 12:57:05 +01:00
return subclass_list
def redirect_referer_or(request, url='/'):
'''
Returns a django redirect to the requests referer,
if there is no referer the redirect will poin to the given url
Default url is /
'''
referer = request.META.get('HTTP_REFERER')
if referer is not None:
return redirect(referer)
else:
return redirect(url)