summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-08-22 00:31:56 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-08-22 00:31:56 +0200
commitd8e86c6d50d5d50cd11a3aabef5ccc0b6d71cfed (patch)
tree50ed3dbd56724470f898bb58a14264051377277b
parent9314f621ef3989ebe6aa01c44fd501299fef8d53 (diff)
downloadIshtar-d8e86c6d50d5d50cd11a3aabef5ccc0b6d71cfed.tar.bz2
Ishtar-d8e86c6d50d5d50cd11a3aabef5ccc0b6d71cfed.zip
Django 1.11: use render() instead render_to_response - pass dict to templates
-rw-r--r--archaeological_files/views.py5
-rw-r--r--archaeological_files/wizards.py7
-rw-r--r--archaeological_operations/views.py8
-rw-r--r--archaeological_operations/widgets.py4
-rw-r--r--archaeological_operations/wizards.py11
-rw-r--r--archaeological_warehouse/wizards.py10
-rw-r--r--ishtar_common/admin.py7
-rw-r--r--ishtar_common/templatetags/window_tables.py8
-rw-r--r--ishtar_common/views.py52
-rw-r--r--ishtar_common/widgets.py17
-rw-r--r--ishtar_common/wizards.py26
11 files changed, 61 insertions, 94 deletions
diff --git a/archaeological_files/views.py b/archaeological_files/views.py
index d21e5801c..0c0dac3f3 100644
--- a/archaeological_files/views.py
+++ b/archaeological_files/views.py
@@ -23,7 +23,7 @@ import re
from django.core.urlresolvers import reverse
from django.db.models import Q
from django.http import HttpResponse
-from django.shortcuts import render_to_response, redirect
+from django.shortcuts import redirect, render
from django.utils.translation import ugettext_lazy as _
from ishtar_common.views import get_item, show_item, revert_item
@@ -99,8 +99,7 @@ def dashboard_file(request, *args, **kwargs):
Main dashboard
"""
dct = {'dashboard': models.FileDashboard()}
- return render_to_response('ishtar/dashboards/dashboard_file.html', dct,
- context_instance=RequestContext(request))
+ return render(request, 'ishtar/dashboards/dashboard_file.html', dct)
file_search_wizard = SearchWizard.as_view(
[('general-file_search', FileFormSelection)],
diff --git a/archaeological_files/wizards.py b/archaeological_files/wizards.py
index 1558cd46e..e8d6ca9ae 100644
--- a/archaeological_files/wizards.py
+++ b/archaeological_files/wizards.py
@@ -20,8 +20,7 @@
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Max
-from django.shortcuts import render_to_response
-from django.template import RequestContext
+from django.shortcuts import render
from django.utils.translation import ugettext_lazy as _
from ishtar_common.forms import reverse_lazy
@@ -134,9 +133,7 @@ class FileDeletionWizard(FileClosingWizard):
for operation in Operation.objects.filter(associated_file=obj).all():
operation.delete()
obj.delete()
- return render_to_response(
- 'ishtar/wizard/wizard_delete_done.html', {},
- context_instance=RequestContext(self.request))
+ return render(self.request, 'ishtar/wizard/wizard_delete_done.html', {})
class FileAdministrativeActWizard(OperationAdministrativeActWizard):
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py
index 13b9a4767..1fecce9cd 100644
--- a/archaeological_operations/views.py
+++ b/archaeological_operations/views.py
@@ -22,7 +22,7 @@ import json
from django.core.urlresolvers import reverse
from django.db.models import Q
from django.http import HttpResponse
-from django.shortcuts import render_to_response, redirect
+from django.shortcuts import render, redirect
from django.utils.translation import ugettext_lazy as _, pgettext_lazy
from ishtar_common.views import get_item, show_item, revert_item, new_item
@@ -160,8 +160,7 @@ def dashboard_operation(request, *args, **kwargs):
Operation dashboard
"""
dct = {'dashboard': models.OperationDashboard()}
- return render_to_response('ishtar/dashboards/dashboard_operation.html',
- dct, context_instance=RequestContext(request))
+ return render(request, 'ishtar/dashboards/dashboard_operation.html', dct)
operation_search_wizard = SearchWizard.as_view(
[('general-operation_search', OperationFormSelection)],
@@ -482,8 +481,7 @@ def administrativeactfile_document(
dct['search_form'] = search_form()
dct['template_form'] = DocumentGenerationAdminActForm(
document_type=document_type)
- return render_to_response('ishtar/administrativeact_document.html', dct,
- context_instance=RequestContext(request))
+ return render(request, 'ishtar/administrativeact_document.html', dct)
def reset_wizards(request):
diff --git a/archaeological_operations/widgets.py b/archaeological_operations/widgets.py
index bb219ab76..c34752499 100644
--- a/archaeological_operations/widgets.py
+++ b/archaeological_operations/widgets.py
@@ -19,7 +19,7 @@
from django import forms
from django.forms import widgets
-from django.template import Context, loader
+from django.template import loader
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
@@ -66,5 +66,5 @@ class OAWidget(forms.TextInput):
'id': attrs['id'],
"safe_id": attrs['id'].replace('-', '_')}
t = loader.get_template('ishtar/blocks/OAWidget.html')
- rendered = t.render(Context(dct))
+ rendered = t.render(dct)
return mark_safe(rendered)
diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py
index 02d462f66..fffe34ca7 100644
--- a/archaeological_operations/wizards.py
+++ b/archaeological_operations/wizards.py
@@ -23,8 +23,7 @@ from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.db.models import Max
-from django.shortcuts import render_to_response
-from django.template import RequestContext
+from django.shortcuts import render
from django.utils.translation import ugettext_lazy as _
from ishtar_common.forms import reverse_lazy
@@ -430,8 +429,7 @@ class OperationAdministrativeActWizard(OperationWizard):
self.request.session[self.current_obj_slug] = unicode(admact.pk)
self.request.session[self.get_object_name(admact)] = unicode(admact.pk)
- res = render_to_response('ishtar/wizard/wizard_done.html', dct,
- context_instance=RequestContext(self.request))
+ res = render(self.request, 'ishtar/wizard/wizard_done.html', dct)
return res
@@ -458,9 +456,8 @@ class AdministrativeActDeletionWizard(ClosingWizard):
def done(self, form_list, **kwargs):
obj = self.get_current_object()
obj.delete()
- return render_to_response(
- 'ishtar/wizard/wizard_delete_done.html', {},
- context_instance=RequestContext(self.request))
+ return render(
+ self.request, 'ishtar/wizard/wizard_delete_done.html', {})
def is_preventive(form_name, model, type_key='operation_type', key=''):
diff --git a/archaeological_warehouse/wizards.py b/archaeological_warehouse/wizards.py
index 571e56b1b..6678e6c36 100644
--- a/archaeological_warehouse/wizards.py
+++ b/archaeological_warehouse/wizards.py
@@ -17,8 +17,7 @@
# See the file COPYING for details.
-from django.shortcuts import render_to_response
-from django.template import RequestContext
+from django.shortcuts import render
from ishtar_common.forms import reverse_lazy
from ishtar_common.wizards import Wizard, DeletionWizard
@@ -50,8 +49,7 @@ class PackagingWizard(TreatmentWizard):
extra_args_for_new=extra_args_for_new)
packaging = TreatmentType.objects.get(txt_idx='packaging')
treatment.treatment_types.add(packaging)
- res = render_to_response('ishtar/wizard/wizard_done.html', {},
- context_instance=RequestContext(self.request))
+ res = render(self.request, 'ishtar/wizard/wizard_done.html', {})
return return_object and (obj, res) or res
@@ -141,9 +139,7 @@ class ContainerWizard(Wizard):
self.current_object = container
# force evaluation of lazy urls
dct['wizard_done_window'] = unicode(self.wizard_done_window)
- return render_to_response(
- self.wizard_done_template, dct,
- context_instance=RequestContext(self.request))
+ return render(self.request, self.wizard_done_template, dct)
class ContainerModificationWizard(ContainerWizard):
diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py
index c5166b3f2..4af60fa90 100644
--- a/ishtar_common/admin.py
+++ b/ishtar_common/admin.py
@@ -27,8 +27,7 @@ from django.contrib.auth.admin import GroupAdmin, UserAdmin
from django.contrib.auth.models import Group, User
from django.contrib.gis.forms import PointField, OSMWidget
from django.http import HttpResponseRedirect, HttpResponse
-from django.shortcuts import render_to_response
-from django.template import RequestContext
+from django.shortcuts import render
from django.template.defaultfilters import slugify
from django.utils.translation import ugettext_lazy as _
@@ -70,9 +69,7 @@ def gen_import_generic(self, request, queryset):
form = ImportGenericForm(
initial={'_selected_action':
request.POST.getlist(admin.ACTION_CHECKBOX_NAME)})
- return render_to_response(
- 'admin/import_from_csv.html', {'csv_form': form},
- context_instance=RequestContext(request))
+ return render(request, 'admin/import_from_csv.html', {'csv_form': form})
gen_import_generic.short_description = "Import from a CSV file"
diff --git a/ishtar_common/templatetags/window_tables.py b/ishtar_common/templatetags/window_tables.py
index bf4dd2b1a..00274c25f 100644
--- a/ishtar_common/templatetags/window_tables.py
+++ b/ishtar_common/templatetags/window_tables.py
@@ -84,7 +84,7 @@ def dynamic_table_document(
if output == 'html':
col_names, extra_cols = grid.get_cols()
t = get_template('ishtar/blocks/window_tables/dynamic_documents.html')
- context = template.Context({
+ context = {
'caption': caption,
'name': '{}{}{}'.format(slugify(caption), key, int(time.time())),
'source': source + source_attrs,
@@ -97,7 +97,7 @@ def dynamic_table_document(
'loading': unicode(_("Loading...")),
'encoding': settings.ENCODING or 'utf-8',
'large': large
- })
+ }
return t.render(context)
else:
col_names, extra_cols = grid.get_cols(python=True)
@@ -126,11 +126,11 @@ def dynamic_table_document(
d.append('')
data.append(d)
t = get_template('ishtar/blocks/window_tables/static_documents.html')
- context = template.Context({
+ context = {
'caption': caption,
'col_names': col_names,
'data': data
- })
+ }
return t.render(context)
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 8ab07fc00..9a6fdbdcd 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -19,7 +19,7 @@
from tidylib import tidy_document as tidy
-from copy import copy
+from copy import copy, deepcopy
import csv
import cStringIO as StringIO
import datetime
@@ -48,8 +48,8 @@ from django.db.models.fields import FieldDoesNotExist
from django.forms.models import modelformset_factory
from django.http import HttpResponse, Http404, HttpResponseRedirect, \
HttpResponseBadRequest
-from django.shortcuts import render_to_response, redirect
-from django.template import RequestContext, loader
+from django.shortcuts import redirect, render
+from django.template import loader
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext, ugettext_lazy as _
from django.views.generic import ListView, UpdateView, TemplateView
@@ -114,13 +114,11 @@ def index(request):
else:
dct['random_image'] = image
try:
- return render_to_response('index.html', dct,
- context_instance=RequestContext(request))
+ return render(request, 'index.html', dct)
except NoReverseMatch:
# probably rights exception (rights revoked)
logout(request)
- return render_to_response('index.html', dct,
- context_instance=RequestContext(request))
+ return render(request, 'index.html', dct)
person_search_wizard = wizards.SearchWizard.as_view(
[('general-person_search', forms.PersonFormSelection)],
@@ -296,9 +294,9 @@ def shortcut_menu(request):
model).render(
model.SLUG + '-shortcut', value=current,
attrs={'id': 'current_' + model.SLUG})))
- return render_to_response(
- 'ishtar/blocks/advanced_shortcut_menu.html',
- dct, context_instance=RequestContext(request))
+ return render(
+ request, 'ishtar/blocks/advanced_shortcut_menu.html', dct
+ )
dct = {
'current_menu': [],
'SHORTCUT_SHOW': request.session['SHORTCUT_SHOW']
@@ -341,8 +339,7 @@ def shortcut_menu(request):
dct['current_menu'].append((lbl, model_name, cls, items))
if new_selected_item:
current_selected_item[model_name] = new_selected_item
- return render_to_response('ishtar/blocks/shortcut_menu.html', dct,
- context_instance=RequestContext(request))
+ return render(request, 'ishtar/blocks/shortcut_menu.html', dct)
CURRENT_ITEM_KEYS = (('file', File),
('operation', Operation),
@@ -1211,8 +1208,7 @@ def display_item(model, extra_dct=None, show_url=None):
dct['show_url'] = "/{}{}/".format(show_url, pk)
else:
dct['show_url'] = "/show-{}/{}/".format(model.SLUG, pk)
- return render_to_response('ishtar/display_item.html', dct,
- context_instance=RequestContext(request))
+ return render(request, 'ishtar/display_item.html', dct)
return func
@@ -1262,8 +1258,7 @@ def show_item(model, name, extra_dct=None):
# add context
if extra_dct:
dct.update(extra_dct(request, item))
- context_instance = RequestContext(request)
- context_instance.update(dct)
+ context_instance = deepcopy(dct)
context_instance['output'] = 'html'
if hasattr(item, 'history_object'):
filename = item.history_object.associated_filename
@@ -1414,13 +1409,10 @@ def new_item(model, frm, many=False):
if dct['parent_pk'] and '_select_' in dct['parent_pk']:
parents = dct['parent_pk'].split('_')
dct['parent_pk'] = "_".join([parents[0]] + parents[2:])
- return render_to_response(
- 'window.html', dct,
- context_instance=RequestContext(request))
+ return render(request, 'window.html', dct)
else:
dct['form'] = frm(limits=limits)
- return render_to_response('window.html', dct,
- context_instance=RequestContext(request))
+ return render(request, 'window.html', dct)
return func
new_person = new_item(models.Person, forms.PersonForm)
@@ -1449,8 +1441,7 @@ def action(request, action_slug, obj_id=None, *args, **kwargs):
globals_dct = globals()
if action_slug in globals_dct:
return globals_dct[action_slug](request, dct, obj_id, *args, **kwargs)
- return render_to_response('index.html', dct,
- context_instance=RequestContext(request))
+ return render(request, 'index.html', dct)
def dashboard_main(request, dct, obj_id=None, *args, **kwargs):
@@ -1470,8 +1461,7 @@ def dashboard_main(request, dct, obj_id=None, *args, **kwargs):
app_list.append((_(u"Treatment requests"), 'treatmentfiles'))
app_list.append((_(u"Treatments"), 'treatments'))
dct = {'app_list': app_list}
- return render_to_response('ishtar/dashboards/dashboard_main.html', dct,
- context_instance=RequestContext(request))
+ return render(request, 'ishtar/dashboards/dashboard_main.html', dct)
DASHBOARD_FORMS = {
'files': DashboardFormFile, 'operations': DashboardFormOpe,
@@ -1486,9 +1476,8 @@ def dashboard_main_detail(request, item_name):
"""
if item_name == 'users':
dct = {'ishtar_users': models.UserDashboard()}
- return render_to_response(
- 'ishtar/dashboards/dashboard_main_detail_users.html',
- dct, context_instance=RequestContext(request))
+ return render(
+ request, 'ishtar/dashboards/dashboard_main_detail_users.html', dct)
form = None
slicing, date_source, fltr, show_detail = 'year', None, {}, False
profile = models.get_current_profile()
@@ -1552,8 +1541,7 @@ def dashboard_main_detail(request, item_name):
n = datetime.datetime.now()
dct['unique_id'] = dct['item_name'] + "_" + \
'%d_%d_%d' % (n.minute, n.second, n.microsecond)
- return render_to_response('ishtar/dashboards/dashboard_main_detail.html',
- dct, context_instance=RequestContext(request))
+ return render(request, 'ishtar/dashboards/dashboard_main_detail.html', dct)
def reset_wizards(request):
@@ -1605,9 +1593,7 @@ def merge_action(model, form, key):
return redirect(reverse(current_url, kwargs={'page': page}))
else:
context['formset'] = FormSet(queryset=queryset)
- return render_to_response(
- 'ishtar/merge_' + key + '.html', context,
- context_instance=RequestContext(request))
+ return render(request, 'ishtar/merge_' + key + '.html', context)
return merge
diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py
index bb090346b..37a243c7d 100644
--- a/ishtar_common/widgets.py
+++ b/ishtar_common/widgets.py
@@ -29,7 +29,7 @@ from django.forms import ClearableFileInput
from django.forms.utils import flatatt
from django.forms.widgets import CheckboxSelectMultiple as \
CheckboxSelectMultipleBase
-from django.template import Context, loader
+from django.template import loader
from django.template.defaultfilters import slugify
from django.utils.encoding import smart_unicode
from django.utils.functional import lazy
@@ -216,7 +216,7 @@ class SquareMeterWidget(forms.TextInput):
'id': attrs['id'],
"safe_id": attrs['id'].replace('-', '_')}
t = loader.get_template('blocks/SquareMeterWidget.html')
- rendered = t.render(Context(dct))
+ rendered = t.render(dct)
return mark_safe(rendered)
AreaWidget = forms.TextInput
@@ -319,7 +319,7 @@ class JQueryAutoComplete(forms.TextInput):
if self.multiple:
tpl = 'blocks/JQueryAutocompleteMultiple.js'
t = loader.get_template(tpl)
- js = t.render(Context(dct))
+ js = t.render(dct)
return js
def render(self, name, value=None, attrs=None):
@@ -488,7 +488,7 @@ class JQueryTown(forms.TextInput):
'selected_state': selected_state}
)
html = loader.get_template('blocks/JQueryAdvancedTown.html')\
- .render(Context(dct))
+ .render(dct)
return html
@@ -541,7 +541,7 @@ class JQueryPersonOrganization(forms.TextInput):
'field_id': field_id}
if self.options:
dct['options'] = mark_safe('%s' % self.options)
- js = loader.get_template(self.js_template).render(Context(dct))
+ js = loader.get_template(self.js_template).render(dct)
return js
def render(self, name, value=None, attrs=None):
@@ -587,7 +587,7 @@ class JQueryPersonOrganization(forms.TextInput):
'name': name,
'js': self.render_js(name, selected),
'new': mark_safe(new)}
- html = loader.get_template(self.html_template).render(Context(dct))
+ html = loader.get_template(self.html_template).render(dct)
return html
@@ -696,8 +696,7 @@ class JQueryJqGrid(forms.RadioSelect):
def render(self, name, value=None, attrs=None):
t = loader.get_template('blocks/form_flex_snippet.html')
form = self.form()
- rendered = t.render(Context({'form': form,
- 'flex': True}))
+ rendered = t.render({'form': form, 'flex': True})
dct = {}
if self.new:
model_name = self.associated_model._meta.object_name.lower()
@@ -745,5 +744,5 @@ class JQueryJqGrid(forms.RadioSelect):
'multi_cols': ",".join((u'"%d"' % col
for col in self.multiple_cols))})
t = loader.get_template('blocks/JQueryJqGrid.html')
- rendered += t.render(Context(dct))
+ rendered += t.render(dct)
return mark_safe(rendered)
diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py
index 5217eafae..4a7181e9f 100644
--- a/ishtar_common/wizards.py
+++ b/ishtar_common/wizards.py
@@ -36,8 +36,8 @@ from django.db.models.fields import NOT_PROVIDED
from django.http import HttpResponseRedirect
from django.forms import ValidationError
-from django.shortcuts import render_to_response, redirect
-from django.template import Context, RequestContext, loader
+from django.shortcuts import redirect, render
+from django.template import loader
from django.utils.datastructures import MultiValueDict as BaseMultiValueDict
from django.utils.translation import ugettext_lazy as _
@@ -778,8 +778,7 @@ class Wizard(NamedUrlWizardView):
wizard_done_window = unicode(self.wizard_done_window)
if wizard_done_window:
dct['wizard_done_window'] = wizard_done_window
- res = render_to_response(self.wizard_done_template, dct,
- context_instance=RequestContext(self.request))
+ res = render(self.request, self.wizard_done_template, dct)
return return_object and (obj, res) or res
def get_deleted(self, keys):
@@ -1253,9 +1252,8 @@ class DeletionWizard(Wizard):
obj.delete()
except ObjectDoesNotExist:
pass
- return render_to_response(
- 'ishtar/wizard/wizard_delete_done.html', {},
- context_instance=RequestContext(self.request))
+ return render(
+ self.request, 'ishtar/wizard/wizard_delete_done.html', {})
class ClosingWizard(Wizard):
@@ -1306,9 +1304,8 @@ class ClosingWizard(Wizard):
and hasattr(obj, 'end_date'):
obj.end_date = form.cleaned_data['end_date']
obj.save()
- return render_to_response(
- 'ishtar/wizard/wizard_closing_done.html', {},
- context_instance=RequestContext(self.request))
+ return render(
+ self.request, 'ishtar/wizard/wizard_closing_done.html', {})
class PersonWizard(Wizard):
@@ -1417,20 +1414,21 @@ class AccountWizard(Wizard):
app_name = site and ("Ishtar - " + site.name) \
or "Ishtar"
- context = Context({
+ context = {
'login': dct['username'],
'password': dct['password'],
'app_name': app_name,
'site': site and site.domain or ""
- })
+ }
t = loader.get_template('account_activation_email.txt')
msg = t.render(context)
subject = _(u"[%(app_name)s] Account creation/modification") % {
"app_name": app_name}
send_mail(subject, msg, settings.ADMINS[0][1],
[dct['email']], fail_silently=True)
- res = render_to_response('ishtar/wizard/wizard_done.html', {},
- context_instance=RequestContext(self.request))
+ res = render(
+ self.request, 'ishtar/wizard/wizard_done.html', {},
+ )
return res
def get_form_kwargs(self, step=None):