mirror of
https://github.com/c0de-archive/django-gallery.git
synced 2024-12-22 10:12:41 +00:00
51a117ca5f
CircleCI's free service only allows running 1 container at a time. This causes problems if I want to use a database. A workaround that I found seems to work by running the database server directly within the test container. This does increase test time however
30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
from django.http import HttpResponse
|
|
from django.template import loader
|
|
from django.contrib import auth
|
|
|
|
# Usage:
|
|
# template - relative path to the template you wish to render
|
|
# request - The request object for the user
|
|
# message - An optional message to me shown to the user, set to None or ''
|
|
# context - A dictionary of arbitrary key-value combos for use in the App
|
|
def _ResponseTemplate(template, request, message='', context=None):
|
|
if isinstance(context, dict) and \
|
|
not (context.get('message', False)):
|
|
context['message'] = str(message)
|
|
elif isinstance(context, dict) and \
|
|
(context.get('message', False)):
|
|
context['message'] += ' -- ' + str(message)
|
|
else:
|
|
context = {
|
|
'message': str(message)
|
|
}
|
|
|
|
template = loader.get_template(str(template))
|
|
return HttpResponse(template.render(context, request))
|
|
|
|
# Logs out a user, sending them to the login screen with an optional message and context
|
|
# Same arguments as _ResponseTemplate, except for the template
|
|
def _ForceLogout(request, message='', context=None):
|
|
auth.logout(request)
|
|
return _ResponseTemplate('account/login.html', request, message, context)
|