def safe_next_link(full_path): q = QueryDict('', mutable=True) next_url = urlparse(full_path).path next_query = iri_to_uri(urlparse(full_path).query) next_query_dict = None if next_query: next_query_dict = QueryDict(next_query).copy() for k,v in next_query_dict.iteritems(): if not v: del(next_query_dict[k]) params = '?%s' % next_query_dict.urlencode() if next_query_dict else '' q['next'] = '%s%s' % (next_url, params) return q.urlencode()
def search_pool_page(request, host_name, page): logging.info('Start of search_pool_page()') if request.method == 'GET': host = get_object_or_404(Host, name=host_name) host_settings = get_list_or_404(Setting, hostname=host) node_list = parse_node_list(host, host_settings) template_dict = {} try: pg_num = request.GET['pg'] except: pg_num = 1 # This is quirky, but we don't want to pass the pg=3 parameter back to the search results. # It causes, the pager links to append (i.e. ?pg=2&pg=2&pg=2) # So we loop through the QueryDict and get rid of the pg=2 parameters. fresh = QueryDict('') fresh = fresh.copy() q = QueryDict(request.META['QUERY_STRING']) for key, value in q.iteritems(): if key != 'pg': fresh.update({key: value}) template_dict['query_string'] = fresh.urlencode() # Start the search process cat = request.GET['type'] str = request.GET['search'] results = Song.objects.filter(title__icontains=str) results = results | Song.objects.filter(artist__name__icontains=str) results = results | Song.objects.filter(album__name__icontains=str) results = results | Song.objects.filter(genre__name__icontains=str) #populate the paginator using the search queryset. p = get_song_search_pager(results) try: single_page = p.page(page) except EmptyPage, InvalidPage: single_page = p.page(p.num_pages) #place all the information we gathered into the template dictionary template_dict['node_list'] = node_list template_dict['active_host'] = host template_dict['search'] = True template_dict['all_pages'] = p template_dict['single_page'] = single_page template_dict['pool_page'] = page logging.info('End of search_pool_page() with GET') return render_to_response('controller/pool_search.html', template_dict, context_instance=RequestContext(request))
def search_pool_page(request, host_name, page): logging.info('Start of search_pool_page()') if request.method == 'GET': host = get_object_or_404(Host, name=host_name) host_settings = get_list_or_404(Setting, hostname=host) node_list = parse_node_list(host, host_settings) template_dict = {} try: pg_num = request.GET['pg'] except: pg_num=1 # This is quirky, but we don't want to pass the pg=3 parameter back to the search results. # It causes, the pager links to append (i.e. ?pg=2&pg=2&pg=2) # So we loop through the QueryDict and get rid of the pg=2 parameters. fresh = QueryDict('') fresh = fresh.copy() q = QueryDict(request.META['QUERY_STRING']) for key,value in q.iteritems(): if key != 'pg': fresh.update({key : value}) template_dict['query_string'] = fresh.urlencode() # Start the search process cat = request.GET['type'] str = request.GET['search'] results = Song.objects.filter(title__icontains=str) results = results | Song.objects.filter(artist__name__icontains=str) results = results | Song.objects.filter(album__name__icontains=str) results = results | Song.objects.filter(genre__name__icontains=str) #populate the paginator using the search queryset. p = get_song_search_pager(results) try: single_page = p.page(page) except EmptyPage, InvalidPage: single_page = p.page(p.num_pages) #place all the information we gathered into the template dictionary template_dict['node_list'] = node_list template_dict['active_host'] = host template_dict['search'] = True template_dict['all_pages'] = p template_dict['single_page'] = single_page template_dict['pool_page'] = page logging.info('End of search_pool_page() with GET') return render_to_response('controller/pool_search.html', template_dict, context_instance=RequestContext(request))
def safe_next_link(full_path, keys_to_delete=[]): q = QueryDict('', mutable=True) next_url = urlparse(full_path).path next_query = iri_to_uri(urlparse(full_path).query) next_query_dict = None if next_query: deleted_keys = [] next_query_dict = QueryDict(next_query).copy() if keys_to_delete: deleted_keys.extend(keys_to_delete) for k,v in next_query_dict.iteritems(): if not v: deleted_keys.append(k) for key in deleted_keys: if key in next_query_dict: del[next_query_dict[key]] params = '?%s' % next_query_dict.urlencode() if next_query_dict else '' q['next'] = '%s%s' % (next_url, params) return q.urlencode()
def task_start(request, part_id=None, task_id=None): part_id = pk_to_int_or_404(part_id) task_id = pk_to_int_or_404(task_id) part = get_object_or_404(models.Participant, pk=part_id) task = get_object_or_404(models.Task, pk=task_id) session = request.session app = task.app cond = part.condition site = part.site exp = site.experiment exptr = exp.experimenter # a task's app may not require a scenario, initialize these to null (scen_id, scen_name) = (None, None) if task.scenario is not None: scen_id = task.scenario.id tmp = task.scenario.scenario_file.name scen_name = os.path.splitext(os.path.basename(tmp))[0] # although the tutalk is "localhost" this get's different values in # different environments, such as when running manage.py runserver # (no reverse proxy) # thus the value of tutalk host needs to be computed server_name = request.META["HTTP_HOST"] if "HTTP_X_FORWARDED_SERVER" in request.META: server_name = request.META["HTTP_X_FORWARDED_SERVER"] server_port = request.META["SERVER_PORT"] server_name = server_name.replace(server_port, '').rstrip(':') if server_name.startswith("127.0"): server_name = "localhost" tutalk_host = server_name if "localhost" == tutalk_host: tutalk_host = socket.getfqdn() # remove any session information related to any previous # taks the user may have run for key in request.session.keys(): if not key.startswith("_auth_user"): del request.session[key] std_app_params = build_std_app_params_dict( cond, exp, exptr, part, site, task, scen_id, scen_name, tutalk_host) url = "%s" % app.url if not url.startswith("http"): url = "http://%s/%s" % (server_name, url) # map the App's names for app parameters to the actual values qd = QueryDict(mutable=True) for param in app.params: try: qd[param.name] = std_app_params[param.value] except KeyError as ke: utils.LOGGER.error(ke) # add any custom app param name/values if len(app.cust_params) > 0: for cust_param in app.cust_params: qd[cust_param.name] = cust_param.value if "session" == app.parameter_method: for (key, value) in qd.iteritems(): session[key] = value session.save() elif "querystring" == app.parameter_method: qs = "%s" % qd.urlencode() url = "%s?%s" % (url, qs) # always save the following information in the session object # regardless of the apps parameter passing scheme session["task_info"] = (task_id, part_id) session.save() task_status = models.TaskStatus.objects\ .get_or_create(participant_id=part_id, task_id=task_id)[0] task_status.set_started() task_status.save() return HttpResponseRedirect(url, 302)
def parse_form(self, request): data = QueryDict(request.body.decode('utf-8')) data = {key: json.loads(val) for key, val in data.iteritems()} return data