mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-10 00:42:06 +00:00

render_to_response does not work on newer django, so it needs to be replaced. And using a speicfic context actually overcomplicates things, it's easier to just use a wrapper function. For those cases where we don't need NavContext, just use render() (the new shortcut function from django), which also removes the need to use RequestContext.
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
from django.http import Http404
|
|
from pgweb.util.decorators import login_required
|
|
|
|
from pgweb.util.contexts import render_pgweb
|
|
from pgweb.util.helpers import simple_form
|
|
|
|
from models import ProfessionalService
|
|
from forms import ProfessionalServiceForm
|
|
|
|
regions = (
|
|
('africa','Africa'),
|
|
('asia','Asia'),
|
|
('europe','Europe'),
|
|
('northamerica','North America'),
|
|
('oceania','Oceania'),
|
|
('southamerica','South America'),
|
|
)
|
|
|
|
def root(request, servtype):
|
|
title = servtype=='support' and 'Professional Services' or 'Hosting Providers'
|
|
what = servtype=='support' and 'support' or 'hosting'
|
|
support = servtype=='support'
|
|
return render_pgweb(request, 'support', 'profserv/root.html', {
|
|
'title': title,
|
|
'support': support,
|
|
'regions': regions,
|
|
'what': what,
|
|
})
|
|
|
|
|
|
def region(request, servtype, regionname):
|
|
regname = [n for r,n in regions if r==regionname]
|
|
if not regname:
|
|
raise Http404
|
|
regname = regname[0]
|
|
|
|
what = servtype=='support' and 'support' or 'hosting'
|
|
whatname = servtype=='support' and 'Professional Services' or 'Hosting Providers'
|
|
title = "%s - %s" % (whatname, regname)
|
|
support = servtype=='support'
|
|
|
|
# DB model is a bit funky here, so use the extra-where functionality to filter properly.
|
|
# Field names are cleaned up earlier, so it's safe against injections.
|
|
services = ProfessionalService.objects.select_related('org').filter(approved=True).extra(where=["region_%s AND provides_%s" % (regionname, what),])
|
|
|
|
return render_pgweb(request, 'support', 'profserv/list.html', {
|
|
'title': title,
|
|
'support': support,
|
|
'what': what,
|
|
'whatname': whatname,
|
|
'regionname': regname,
|
|
'services': services,
|
|
})
|
|
|
|
|
|
# Forms to edit
|
|
@login_required
|
|
def profservform(request, itemid):
|
|
return simple_form(ProfessionalService, itemid, request, ProfessionalServiceForm,
|
|
redirect='/account/edit/services/')
|