blob: 365f84fd05d9d4e23a474ca1a7ad24b8e2ceab8f [file] [log] [blame]
mblighe8819cd2008-02-15 16:48:40 +00001import urllib2
2
showard7c785282008-05-29 19:45:12 +00003from frontend.afe import models, rpc_handler, rpc_interface, site_rpc_interface
4from frontend.afe import rpc_utils
mblighe8819cd2008-02-15 16:48:40 +00005from django.http import HttpResponse, HttpResponsePermanentRedirect
6
showard7c785282008-05-29 19:45:12 +00007# since site_rpc_interface is later in the list, its methods will override those
8# of rpc_interface
9rpc_handler_obj = rpc_handler.RpcHandler((rpc_interface, site_rpc_interface),
jadmanski0afbb632008-06-06 21:10:57 +000010 document_module=rpc_interface)
showard7c785282008-05-29 19:45:12 +000011
12
13def handle_rpc(request):
jadmanski0afbb632008-06-06 21:10:57 +000014 return rpc_handler_obj.handle_rpc_request(request)
showard7c785282008-05-29 19:45:12 +000015
16
mblighe8819cd2008-02-15 16:48:40 +000017def model_documentation(request):
jadmanski0afbb632008-06-06 21:10:57 +000018 doc = '<h2>Models</h2>\n'
19 for model_name in ('Label', 'Host', 'Test', 'User', 'AclGroup', 'Job'):
20 model_class = getattr(models, model_name)
21 doc += '<h3>%s</h3>\n' % model_name
22 doc += '<pre>\n%s</pre>\n' % model_class.__doc__
23 return HttpResponse(doc)
mblighe8819cd2008-02-15 16:48:40 +000024
25
26def redirect_with_extra_data(request, url, **kwargs):
jadmanski0afbb632008-06-06 21:10:57 +000027 kwargs['getdata'] = request.GET.urlencode()
28 kwargs['server_name'] = request.META['SERVER_NAME']
29 return HttpResponsePermanentRedirect(url % kwargs)
mblighe8819cd2008-02-15 16:48:40 +000030
31
32GWT_SERVER = 'http://localhost:8888/'
33def gwt_forward(request, forward_addr):
jadmanski0afbb632008-06-06 21:10:57 +000034 if len(request.POST) == 0:
35 data = None
36 else:
37 data = request.raw_post_data
38 url_response = urllib2.urlopen(GWT_SERVER + forward_addr, data=data)
39 http_response = HttpResponse(url_response.read())
40 for header, value in url_response.info().items():
41 if header not in ('connection',):
42 http_response[header] = value
43 return http_response