Merge pull request #399 from mrkiwi-nz/master

Changed render_to_response() to render()
This commit is contained in:
Ross Poulton 2016-06-22 11:05:21 +10:00 committed by GitHub
commit e4dc3e51eb
4 changed files with 85 additions and 87 deletions

View File

@ -19,7 +19,7 @@ try:
except ImportError: except ImportError:
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import render_to_response from django.shortcuts import render
from django.template import loader, Context from django.template import loader, Context
import simplejson import simplejson
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
@ -64,7 +64,7 @@ def api(request, method):
warnings.warn("django-helpdesk API will be removed in January 2016. See https://github.com/rossp/django-helpdesk/issues/198 for details.", category=DeprecationWarning) warnings.warn("django-helpdesk API will be removed in January 2016. See https://github.com/rossp/django-helpdesk/issues/198 for details.", category=DeprecationWarning)
if method == 'help': if method == 'help':
return render_to_response('helpdesk/help_api.html') return render(request, template_name='helpdesk/help_api.html')
if request.method != 'POST': if request.method != 'POST':
return api_return(STATUS_ERROR_BADMETHOD) return api_return(STATUS_ERROR_BADMETHOD)

View File

@ -11,7 +11,7 @@ views/kb.py - Public-facing knowledgebase views. The knowledgebase is a
from datetime import datetime from datetime import datetime
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.template import RequestContext from django.template import RequestContext
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
@ -22,31 +22,31 @@ from helpdesk.models import KBCategory, KBItem
def index(request): def index(request):
category_list = KBCategory.objects.all() category_list = KBCategory.objects.all()
# TODO: It'd be great to have a list of most popular items here. # TODO: It'd be great to have a list of most popular items here.
return render_to_response('helpdesk/kb_index.html', return render(request, template_name='helpdesk/kb_index.html',
RequestContext(request, { context = {
'kb_categories': category_list, 'kb_categories': category_list,
'helpdesk_settings': helpdesk_settings, 'helpdesk_settings': helpdesk_settings,
})) })
def category(request, slug): def category(request, slug):
category = get_object_or_404(KBCategory, slug__iexact=slug) category = get_object_or_404(KBCategory, slug__iexact=slug)
items = category.kbitem_set.all() items = category.kbitem_set.all()
return render_to_response('helpdesk/kb_category.html', return render(request, template_name='helpdesk/kb_category.html',
RequestContext(request, { context = {
'category': category, 'category': category,
'items': items, 'items': items,
'helpdesk_settings': helpdesk_settings, 'helpdesk_settings': helpdesk_settings,
})) })
def item(request, item): def item(request, item):
item = get_object_or_404(KBItem, pk=item) item = get_object_or_404(KBItem, pk=item)
return render_to_response('helpdesk/kb_item.html', return render(request, template_name='helpdesk/kb_item.html',
RequestContext(request, { context = {
'item': item, 'item': item,
'helpdesk_settings': helpdesk_settings, 'helpdesk_settings': helpdesk_settings,
})) })
def vote(request, item): def vote(request, item):

View File

@ -9,7 +9,7 @@ views/public.py - All public facing views, eg non-staff (no authentication
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, Http404, HttpResponse from django.http import HttpResponseRedirect, Http404, HttpResponse
from django.shortcuts import render_to_response, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.template import loader, Context, RequestContext from django.template import loader, Context, RequestContext
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
@ -38,7 +38,7 @@ def homepage(request):
if form.is_valid(): if form.is_valid():
if text_is_spam(form.cleaned_data['body'], request): if text_is_spam(form.cleaned_data['body'], request):
# This submission is spam. Let's not save it. # This submission is spam. Let's not save it.
return render_to_response('helpdesk/public_spam.html', RequestContext(request, {})) return render(request, template_name='helpdesk/public_spam.html')
else: else:
ticket = form.save() ticket = form.save()
return HttpResponseRedirect('%s?ticket=%s&email=%s'% ( return HttpResponseRedirect('%s?ticket=%s&email=%s'% (
@ -63,12 +63,12 @@ def homepage(request):
knowledgebase_categories = KBCategory.objects.all() knowledgebase_categories = KBCategory.objects.all()
return render_to_response('helpdesk/public_homepage.html', return render(request, 'helpdesk/public_homepage.html',
RequestContext(request, { {
'form': form, 'form': form,
'helpdesk_settings': helpdesk_settings, 'helpdesk_settings': helpdesk_settings,
'kb_categories': knowledgebase_categories 'kb_categories': knowledgebase_categories
})) })
def view_ticket(request): def view_ticket(request):
@ -117,25 +117,25 @@ def view_ticket(request):
if helpdesk_settings.HELPDESK_NAVIGATION_ENABLED: if helpdesk_settings.HELPDESK_NAVIGATION_ENABLED:
redirect_url = reverse('helpdesk_view', args=[ticket_id]) redirect_url = reverse('helpdesk_view', args=[ticket_id])
return render_to_response('helpdesk/public_view_ticket.html', return render(request, 'helpdesk/public_view_ticket.html',
RequestContext(request, { {
'ticket': ticket, 'ticket': ticket,
'helpdesk_settings': helpdesk_settings, 'helpdesk_settings': helpdesk_settings,
'next': redirect_url, 'next': redirect_url,
})) })
return render_to_response('helpdesk/public_view_form.html', return render(request, template_name='helpdesk/public_view_form.html',
RequestContext(request, { context = {
'ticket': ticket, 'ticket': ticket,
'email': email, 'email': email,
'error_message': error_message, 'error_message': error_message,
'helpdesk_settings': helpdesk_settings, 'helpdesk_settings': helpdesk_settings,
})) })
def change_language(request): def change_language(request):
return_to = '' return_to = ''
if 'return_to' in request.GET: if 'return_to' in request.GET:
return_to = request.GET['return_to'] return_to = request.GET['return_to']
return render_to_response('helpdesk/public_change_language.html', return render(request, template_name='helpdesk/public_change_language.html',
RequestContext(request, {'next': return_to})) context = {'next': return_to})

View File

@ -26,7 +26,7 @@ from django.core import paginator
from django.db import connection from django.db import connection
from django.db.models import Q from django.db.models import Q
from django.http import HttpResponseRedirect, Http404, HttpResponse from django.http import HttpResponseRedirect, Http404, HttpResponse
from django.shortcuts import render_to_response, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.template import loader, Context, RequestContext from django.template import loader, Context, RequestContext
from django.utils.dates import MONTHS_3 from django.utils.dates import MONTHS_3
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
@ -153,15 +153,15 @@ def dashboard(request):
dash_tickets = query_to_dict(cursor.fetchall(), cursor.description) dash_tickets = query_to_dict(cursor.fetchall(), cursor.description)
return render_to_response('helpdesk/dashboard.html', return render(request, 'helpdesk/dashboard.html',
RequestContext(request, { {
'user_tickets': tickets, 'user_tickets': tickets,
'user_tickets_closed_resolved': tickets_closed_resolved, 'user_tickets_closed_resolved': tickets_closed_resolved,
'unassigned_tickets': unassigned_tickets, 'unassigned_tickets': unassigned_tickets,
'all_tickets_reported_by_current_user': all_tickets_reported_by_current_user, 'all_tickets_reported_by_current_user': all_tickets_reported_by_current_user,
'dash_tickets': dash_tickets, 'dash_tickets': dash_tickets,
'basic_ticket_stats': basic_ticket_stats, 'basic_ticket_stats': basic_ticket_stats,
})) })
dashboard = staff_member_required(dashboard) dashboard = staff_member_required(dashboard)
@ -171,10 +171,10 @@ def delete_ticket(request, ticket_id):
raise PermissionDenied() raise PermissionDenied()
if request.method == 'GET': if request.method == 'GET':
return render_to_response('helpdesk/delete_ticket.html', return render(request, template_name='helpdesk/delete_ticket.html',
RequestContext(request, { context = {
'ticket': ticket, 'ticket': ticket,
})) })
else: else:
ticket.delete() ticket.delete()
return HttpResponseRedirect(reverse('helpdesk_home')) return HttpResponseRedirect(reverse('helpdesk_home'))
@ -197,13 +197,13 @@ def followup_edit(request, ticket_id, followup_id):
ticketcc_string, SHOW_SUBSCRIBE = return_ticketccstring_and_show_subscribe(request.user, ticket) ticketcc_string, SHOW_SUBSCRIBE = return_ticketccstring_and_show_subscribe(request.user, ticket)
return render_to_response('helpdesk/followup_edit.html', return render(request, template_name='helpdesk/followup_edit.html',
RequestContext(request, { context = {
'followup': followup, 'followup': followup,
'ticket': ticket, 'ticket': ticket,
'form': form, 'form': form,
'ticketcc_string': ticketcc_string, 'ticketcc_string': ticketcc_string,
})) })
elif request.method == 'POST': elif request.method == 'POST':
form = EditFollowUpForm(request.POST) form = EditFollowUpForm(request.POST)
if form.is_valid(): if form.is_valid():
@ -296,8 +296,8 @@ def view_ticket(request, ticket_id):
ticketcc_string, SHOW_SUBSCRIBE = return_ticketccstring_and_show_subscribe(request.user, ticket) ticketcc_string, SHOW_SUBSCRIBE = return_ticketccstring_and_show_subscribe(request.user, ticket)
return render_to_response('helpdesk/ticket.html', return render(request, template_name='helpdesk/ticket.html',
RequestContext(request, { context = {
'ticket': ticket, 'ticket': ticket,
'form': form, 'form': form,
'active_users': users, 'active_users': users,
@ -305,7 +305,7 @@ def view_ticket(request, ticket_id):
'preset_replies': PreSetReply.objects.filter(Q(queues=ticket.queue) | Q(queues__isnull=True)), 'preset_replies': PreSetReply.objects.filter(Q(queues=ticket.queue) | Q(queues__isnull=True)),
'ticketcc_string': ticketcc_string, 'ticketcc_string': ticketcc_string,
'SHOW_SUBSCRIBE': SHOW_SUBSCRIBE, 'SHOW_SUBSCRIBE': SHOW_SUBSCRIBE,
})) })
view_ticket = staff_member_required(view_ticket) view_ticket = staff_member_required(view_ticket)
def return_ticketccstring_and_show_subscribe(user, ticket): def return_ticketccstring_and_show_subscribe(user, ticket):
@ -892,8 +892,8 @@ def ticket_list(request):
querydict.pop('page', 1) querydict.pop('page', 1)
return render_to_response('helpdesk/ticket_list.html', return render(request, 'helpdesk/ticket_list.html',
RequestContext(request, dict( dict(
context, context,
query_string=querydict.urlencode(), query_string=querydict.urlencode(),
tickets=tickets, tickets=tickets,
@ -906,7 +906,7 @@ def ticket_list(request):
from_saved_query=from_saved_query, from_saved_query=from_saved_query,
saved_query=saved_query, saved_query=saved_query,
search_message=search_message, search_message=search_message,
))) ))
ticket_list = staff_member_required(ticket_list) ticket_list = staff_member_required(ticket_list)
@ -923,10 +923,10 @@ def edit_ticket(request, ticket_id):
else: else:
form = EditTicketForm(instance=ticket) form = EditTicketForm(instance=ticket)
return render_to_response('helpdesk/edit_ticket.html', return render(request, template_name='helpdesk/edit_ticket.html',
RequestContext(request, { context = {
'form': form, 'form': form,
})) })
edit_ticket = staff_member_required(edit_ticket) edit_ticket = staff_member_required(edit_ticket)
def create_ticket(request): def create_ticket(request):
@ -958,10 +958,8 @@ def create_ticket(request):
if helpdesk_settings.HELPDESK_CREATE_TICKET_HIDE_ASSIGNED_TO: if helpdesk_settings.HELPDESK_CREATE_TICKET_HIDE_ASSIGNED_TO:
form.fields['assigned_to'].widget = forms.HiddenInput() form.fields['assigned_to'].widget = forms.HiddenInput()
return render_to_response('helpdesk/create_ticket.html', return render(request, template_name='helpdesk/create_ticket.html',
RequestContext(request, { context = {'form': form})
'form': form,
}))
create_ticket = staff_member_required(create_ticket) create_ticket = staff_member_required(create_ticket)
@ -1017,21 +1015,21 @@ unhold_ticket = staff_member_required(unhold_ticket)
def rss_list(request): def rss_list(request):
return render_to_response('helpdesk/rss_list.html', return render(request, template_name='helpdesk/rss_list.html',
RequestContext(request, { context = {
'queues': Queue.objects.all(), 'queues': Queue.objects.all(),
})) })
rss_list = staff_member_required(rss_list) rss_list = staff_member_required(rss_list)
def report_index(request): def report_index(request):
number_tickets = Ticket.objects.all().count() number_tickets = Ticket.objects.all().count()
saved_query = request.GET.get('saved_query', None) saved_query = request.GET.get('saved_query', None)
return render_to_response('helpdesk/report_index.html', return render(request, template_name='helpdesk/report_index.html',
RequestContext(request, { context = {
'number_tickets': number_tickets, 'number_tickets': number_tickets,
'saved_query': saved_query, 'saved_query': saved_query,
})) })
report_index = staff_member_required(report_index) report_index = staff_member_required(report_index)
@ -1200,15 +1198,15 @@ def run_report(request, report):
data.append(summarytable[item, hdr]) data.append(summarytable[item, hdr])
table.append([item] + data) table.append([item] + data)
return render_to_response('helpdesk/report_output.html', return render(request, 'helpdesk/report_output.html',
RequestContext(request, { {
'title': title, 'title': title,
'charttype': charttype, 'charttype': charttype,
'data': table, 'data': table,
'headings': column_headings, 'headings': column_headings,
'from_saved_query': from_saved_query, 'from_saved_query': from_saved_query,
'saved_query': saved_query, 'saved_query': saved_query,
})) })
run_report = staff_member_required(run_report) run_report = staff_member_required(run_report)
@ -1234,10 +1232,10 @@ def delete_saved_query(request, id):
query.delete() query.delete()
return HttpResponseRedirect(reverse('helpdesk_list')) return HttpResponseRedirect(reverse('helpdesk_list'))
else: else:
return render_to_response('helpdesk/confirm_delete_saved_query.html', return render(request, template_name='helpdesk/confirm_delete_saved_query.html',
RequestContext(request, { context = {
'query': query, 'query': query,
})) })
delete_saved_query = staff_member_required(delete_saved_query) delete_saved_query = staff_member_required(delete_saved_query)
@ -1251,18 +1249,18 @@ def user_settings(request):
else: else:
form = UserSettingsForm(s.settings) form = UserSettingsForm(s.settings)
return render_to_response('helpdesk/user_settings.html', return render(request, template_name='helpdesk/user_settings.html',
RequestContext(request, { context = {
'form': form, 'form': form,
})) })
user_settings = staff_member_required(user_settings) user_settings = staff_member_required(user_settings)
def email_ignore(request): def email_ignore(request):
return render_to_response('helpdesk/email_ignore_list.html', return render(request, template_name='helpdesk/email_ignore_list.html',
RequestContext(request, { context = {
'ignore_list': IgnoreEmail.objects.all(), 'ignore_list': IgnoreEmail.objects.all(),
})) })
email_ignore = superuser_required(email_ignore) email_ignore = superuser_required(email_ignore)
@ -1275,10 +1273,10 @@ def email_ignore_add(request):
else: else:
form = EmailIgnoreForm(request.GET) form = EmailIgnoreForm(request.GET)
return render_to_response('helpdesk/email_ignore_add.html', return render(request, template_name='helpdesk/email_ignore_add.html',
RequestContext(request, { context = {
'form': form, 'form': form,
})) })
email_ignore_add = superuser_required(email_ignore_add) email_ignore_add = superuser_required(email_ignore_add)
@ -1288,10 +1286,10 @@ def email_ignore_del(request, id):
ignore.delete() ignore.delete()
return HttpResponseRedirect(reverse('helpdesk_email_ignore')) return HttpResponseRedirect(reverse('helpdesk_email_ignore'))
else: else:
return render_to_response('helpdesk/email_ignore_del.html', return render(request, template_name='helpdesk/email_ignore_del.html',
RequestContext(request, { context = {
'ignore': ignore, 'ignore': ignore,
})) })
email_ignore_del = superuser_required(email_ignore_del) email_ignore_del = superuser_required(email_ignore_del)
def ticket_cc(request, ticket_id): def ticket_cc(request, ticket_id):
@ -1300,11 +1298,11 @@ def ticket_cc(request, ticket_id):
raise PermissionDenied() raise PermissionDenied()
copies_to = ticket.ticketcc_set.all() copies_to = ticket.ticketcc_set.all()
return render_to_response('helpdesk/ticket_cc_list.html', return render(request, template_name='helpdesk/ticket_cc_list.html',
RequestContext(request, { context = {
'copies_to': copies_to, 'copies_to': copies_to,
'ticket': ticket, 'ticket': ticket,
})) })
ticket_cc = staff_member_required(ticket_cc) ticket_cc = staff_member_required(ticket_cc)
def ticket_cc_add(request, ticket_id): def ticket_cc_add(request, ticket_id):
@ -1321,11 +1319,11 @@ def ticket_cc_add(request, ticket_id):
return HttpResponseRedirect(reverse('helpdesk_ticket_cc', kwargs={'ticket_id': ticket.id})) return HttpResponseRedirect(reverse('helpdesk_ticket_cc', kwargs={'ticket_id': ticket.id}))
else: else:
form = TicketCCForm() form = TicketCCForm()
return render_to_response('helpdesk/ticket_cc_add.html', return render(request, template_name='helpdesk/ticket_cc_add.html',
RequestContext(request, { context = {
'ticket': ticket, 'ticket': ticket,
'form': form, 'form': form,
})) })
ticket_cc_add = staff_member_required(ticket_cc_add) ticket_cc_add = staff_member_required(ticket_cc_add)
def ticket_cc_del(request, ticket_id, cc_id): def ticket_cc_del(request, ticket_id, cc_id):
@ -1334,10 +1332,10 @@ def ticket_cc_del(request, ticket_id, cc_id):
if request.method == 'POST': if request.method == 'POST':
cc.delete() cc.delete()
return HttpResponseRedirect(reverse('helpdesk_ticket_cc', kwargs={'ticket_id': cc.ticket.id})) return HttpResponseRedirect(reverse('helpdesk_ticket_cc', kwargs={'ticket_id': cc.ticket.id}))
return render_to_response('helpdesk/ticket_cc_del.html', return render(request, template_name='helpdesk/ticket_cc_del.html',
RequestContext(request, { context = {
'cc': cc, 'cc': cc,
})) })
ticket_cc_del = staff_member_required(ticket_cc_del) ticket_cc_del = staff_member_required(ticket_cc_del)
def ticket_dependency_add(request, ticket_id): def ticket_dependency_add(request, ticket_id):
@ -1354,11 +1352,11 @@ def ticket_dependency_add(request, ticket_id):
return HttpResponseRedirect(reverse('helpdesk_view', args=[ticket.id])) return HttpResponseRedirect(reverse('helpdesk_view', args=[ticket.id]))
else: else:
form = TicketDependencyForm() form = TicketDependencyForm()
return render_to_response('helpdesk/ticket_dependency_add.html', return render(request, template_name='helpdesk/ticket_dependency_add.html',
RequestContext(request, { context = {
'ticket': ticket, 'ticket': ticket,
'form': form, 'form': form,
})) })
ticket_dependency_add = staff_member_required(ticket_dependency_add) ticket_dependency_add = staff_member_required(ticket_dependency_add)
def ticket_dependency_del(request, ticket_id, dependency_id): def ticket_dependency_del(request, ticket_id, dependency_id):
@ -1366,10 +1364,10 @@ def ticket_dependency_del(request, ticket_id, dependency_id):
if request.method == 'POST': if request.method == 'POST':
dependency.delete() dependency.delete()
return HttpResponseRedirect(reverse('helpdesk_view', args=[ticket_id])) return HttpResponseRedirect(reverse('helpdesk_view', args=[ticket_id]))
return render_to_response('helpdesk/ticket_dependency_del.html', return render(request, template_name='helpdesk/ticket_dependency_del.html',
RequestContext(request, { context = {
'dependency': dependency, 'dependency': dependency,
})) })
ticket_dependency_del = staff_member_required(ticket_dependency_del) ticket_dependency_del = staff_member_required(ticket_dependency_del)
def attachment_del(request, ticket_id, attachment_id): def attachment_del(request, ticket_id, attachment_id):