本文整理汇总了Python中util.rest.parse_string_list函数的典型用法代码示例。如果您正苦于以下问题:Python parse_string_list函数的具体用法?Python parse_string_list怎么用?Python parse_string_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_string_list函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list
def list(self, request):
"""Retrieves jobs and returns it in JSON form
:param request: the HTTP GET request
:type request: :class:`rest_framework.request.Request`
:rtype: :class:`rest_framework.response.Response`
:returns: the HTTP response to send back to the user
"""
started = rest_util.parse_timestamp(request, 'started', required=False)
ended = rest_util.parse_timestamp(request, 'ended', required=False)
rest_util.check_time_range(started, ended)
statuses = rest_util.parse_string_list(request, 'status', required=False)
job_ids = rest_util.parse_int_list(request, 'job_id', required=False)
job_type_ids = rest_util.parse_int_list(request, 'job_type_id', required=False)
job_type_names = rest_util.parse_string_list(request, 'job_type_name', required=False)
job_type_categories = rest_util.parse_string_list(request, 'job_type_category', required=False)
error_categories = rest_util.parse_string_list(request, 'error_category', required=False)
include_superseded = rest_util.parse_bool(request, 'include_superseded', required=False)
order = rest_util.parse_string_list(request, 'order', required=False)
jobs = Job.objects.get_jobs(started=started, ended=ended, statuses=statuses, job_ids=job_ids,
job_type_ids=job_type_ids, job_type_names=job_type_names,
job_type_categories=job_type_categories, error_categories=error_categories,
include_superseded=include_superseded, order=order)
page = self.paginate_queryset(jobs)
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
示例2: get
def get(self, request):
'''Gets job executions and their associated job_type id, name, and version
:param request: the HTTP GET request
:type request: :class:`rest_framework.request.Request`
:rtype: :class:`rest_framework.response.Response`
:returns: the HTTP response to send back to the user
'''
started = rest_util.parse_timestamp(request, u'started', required=False)
ended = rest_util.parse_timestamp(request, u'ended', required=False)
rest_util.check_time_range(started, ended)
job_status = rest_util.parse_string(request, u'status', required=False)
job_type_ids = rest_util.parse_int_list(request, u'job_type_id', required=False)
job_type_names = rest_util.parse_string_list(request, u'job_type_name', required=False)
job_type_categories = rest_util.parse_string_list(request, u'job_type_category', required=False)
node_ids = rest_util.parse_int_list(request, u'node_id', required=False)
order = rest_util.parse_string_list(request, u'order', required=False)
job_exes = JobExecution.objects.get_exes(started, ended, job_status, job_type_ids, job_type_names,
job_type_categories, node_ids, order)
page = rest_util.perform_paging(request, job_exes)
serializer = JobExecutionListSerializer(page, context={u'request': request})
return Response(serializer.data, status=status.HTTP_200_OK)
示例3: list
def list(self, request):
"""Gets jobs and their associated latest execution
:param request: the HTTP GET request
:type request: :class:`rest_framework.request.Request`
:rtype: :class:`rest_framework.response.Response`
:returns: the HTTP response to send back to the user
"""
started = rest_util.parse_timestamp(request, 'started', required=False)
ended = rest_util.parse_timestamp(request, 'ended', required=False)
rest_util.check_time_range(started, ended)
job_status = rest_util.parse_string(request, 'status', required=False)
job_ids = rest_util.parse_int_list(request, 'job_id', required=False)
job_type_ids = rest_util.parse_int_list(request, 'job_type_id', required=False)
job_type_names = rest_util.parse_string_list(request, 'job_type_name', required=False)
job_type_categories = rest_util.parse_string_list(request, 'job_type_category', required=False)
order = rest_util.parse_string_list(request, 'order', required=False)
jobs = Job.objects.get_jobs(started, ended, job_status, job_ids, job_type_ids, job_type_names,
job_type_categories, order)
# Add the latest execution for each matching job
page = self.paginate_queryset(jobs)
job_exes_dict = JobExecution.objects.get_latest(page)
for job in page:
job.latest_job_exe = job_exes_dict[job.id] if job.id in job_exes_dict else None
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
示例4: get
def get(self, request, name):
'''Retrieves the plot values for metrics and return them in JSON form
:param request: the HTTP GET request
:type request: :class:`rest_framework.request.Request`
:rtype: :class:`rest_framework.response.Response`
:returns: the HTTP response to send back to the user
'''
started = rest_util.parse_timestamp(request, 'started', required=False)
ended = rest_util.parse_timestamp(request, 'ended', required=False)
rest_util.check_time_range(started, ended)
choice_ids = rest_util.parse_string_list(request, 'choice_id', required=False)
column_names = rest_util.parse_string_list(request, 'column', required=False)
group_names = rest_util.parse_string_list(request, 'group', required=False)
try:
provider = registry.get_provider(name)
metrics_type = provider.get_metrics_type(include_choices=False)
except MetricsTypeError:
raise Http404
# Build a unique set of column names from groups
columns = metrics_type.get_column_set(column_names, group_names)
# Get the actual plot values
metrics_values = provider.get_plot_data(started, ended, choice_ids, columns)
page = rest_util.perform_paging(request, metrics_values)
if len(choice_ids) > 1:
serializer = MetricsPlotMultiListSerializer(page, context={'request': request})
else:
serializer = MetricsPlotListSerializer(page, context={'request': request})
return Response(serializer.data, status=status.HTTP_200_OK)
示例5: list
def list(self, request):
"""Retrieves the batches and returns it in JSON form
:param request: the HTTP GET request
:type request: :class:`rest_framework.request.Request`
:rtype: :class:`rest_framework.response.Response`
:returns: the HTTP response to send back to the user
"""
started = rest_util.parse_timestamp(request, 'started', required=False)
ended = rest_util.parse_timestamp(request, 'ended', required=False)
rest_util.check_time_range(started, ended)
statuses = rest_util.parse_string_list(request, 'status', required=False)
recipe_type_ids = rest_util.parse_int_list(request, 'recipe_type_id', required=False)
recipe_type_names = rest_util.parse_string_list(request, 'recipe_type_name', required=False)
order = rest_util.parse_string_list(request, 'order', required=False)
batches = Batch.objects.get_batches(started=started, ended=ended, statuses=statuses,
recipe_type_ids=recipe_type_ids, recipe_type_names=recipe_type_names,
order=order)
page = self.paginate_queryset(batches)
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
示例6: get
def get(self, request):
"""Retrieves the job updates for a given time range and returns it in JSON form
:param request: the HTTP GET request
:type request: :class:`rest_framework.request.Request`
:rtype: :class:`rest_framework.response.Response`
:returns: the HTTP response to send back to the user
"""
started = rest_util.parse_timestamp(request, 'started', required=False)
ended = rest_util.parse_timestamp(request, 'ended', required=False)
rest_util.check_time_range(started, ended)
job_status = rest_util.parse_string(request, 'status', required=False)
job_type_ids = rest_util.parse_int_list(request, 'job_type_id', required=False)
job_type_names = rest_util.parse_string_list(request, 'job_type_name', required=False)
job_type_categories = rest_util.parse_string_list(request, 'job_type_category', required=False)
order = rest_util.parse_string_list(request, 'order', required=False)
jobs = Job.objects.get_job_updates(started, ended, job_status, job_type_ids, job_type_names,
job_type_categories, order)
page = self.paginate_queryset(jobs)
Job.objects.populate_input_files(page)
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
示例7: test_parse_string_list_default
def test_parse_string_list_default(self):
'''Tests parsing a required list of string parameters that are provided via default value.'''
request = MagicMock(Request)
request.QUERY_PARAMS = QueryDict('', mutable=True)
request.QUERY_PARAMS.setlist('test', ['value1'])
self.assertEqual(rest_util.parse_string_list(request, 'test2', ['value2', 'value3']), ['value2', 'value3'])
示例8: test_parse_string_list
def test_parse_string_list(self):
"""Tests parsing a required list of string parameters that is provided via GET."""
request = MagicMock(Request)
request.query_params = QueryDict('', mutable=True)
request.query_params.setlist('test', ['value1', 'value2'])
self.assertListEqual(rest_util.parse_string_list(request, 'test'), ['value1', 'value2'])
示例9: test_parse_string_list_post
def test_parse_string_list_post(self):
'''Tests parsing a required list of string parameters that are provided via POST.'''
request = MagicMock(Request)
request.DATA = QueryDict('', mutable=True)
request.DATA.setlist('test', ['value1', 'value2'])
self.assertEqual(rest_util.parse_string_list(request, 'test'), ['value1', 'value2'])
示例10: test_parse_string_list_optional
def test_parse_string_list_optional(self):
'''Tests parsing an optional list of string parameters that are missing.'''
request = MagicMock(Request)
request.QUERY_PARAMS = QueryDict('', mutable=True)
request.QUERY_PARAMS.setlist('test', ['value1'])
self.assertListEqual(rest_util.parse_string_list(request, 'test2', required=False), [])
示例11: post
def post(self, request, recipe_id):
"""Schedules a recipe for reprocessing and returns it in JSON form
:param request: the HTTP GET request
:type request: :class:`rest_framework.request.Request`
:param recipe_id: The id of the recipe
:type recipe_id: int encoded as a str
:rtype: :class:`rest_framework.response.Response`
:returns: the HTTP response to send back to the user
"""
job_names = rest_util.parse_string_list(request, 'job_names', required=False)
all_jobs = rest_util.parse_bool(request, 'all_jobs', required=False)
try:
handler = Recipe.objects.reprocess_recipe(recipe_id, job_names, all_jobs)
except Recipe.DoesNotExist:
raise Http404
except ReprocessError as err:
raise BadParameter(unicode(err))
try:
new_recipe = Recipe.objects.get_details(handler.recipe.id)
except Recipe.DoesNotExist:
raise Http404
url = urlresolvers.reverse('recipe_details_view', args=[new_recipe.id])
serializer = self.get_serializer(new_recipe)
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=dict(location=url))
示例12: test_parse_string_list_accepted_all
def test_parse_string_list_accepted_all(self):
'''Tests parsing a list of string parameters where all values are acceptable.'''
request = MagicMock(Request)
request.QUERY_PARAMS = QueryDict('', mutable=True)
request.QUERY_PARAMS.setlist('test', ['value1', 'value2'])
self.assertListEqual(rest_util.parse_string_list(request, 'test', accepted_values=['value1', 'value2']),
['value1', 'value2'])
示例13: test_parse_string_list_post
def test_parse_string_list_post(self):
"""Tests parsing a required list of string parameters that are provided via POST."""
request = MagicMock(Request)
request.data = QueryDict('', mutable=True)
request.data.update({
'test': ['value1', 'value2']
})
self.assertEqual(rest_util.parse_string_list(request, 'test'), ['value1', 'value2'])
示例14: list
def list(self, request, name):
"""Retrieves the plot values for metrics and return them in JSON form
:param request: the HTTP GET request
:type request: :class:`rest_framework.request.Request`
:param name: the name of the metrics detail to retrieve.
:type name: string
:rtype: :class:`rest_framework.response.Response`
:returns: the HTTP response to send back to the user
"""
started = rest_util.parse_timestamp(request, 'started', required=False)
ended = rest_util.parse_timestamp(request, 'ended', required=False)
rest_util.check_time_range(started, ended)
choice_ids = rest_util.parse_string_list(request, 'choice_id', required=False)
column_names = rest_util.parse_string_list(request, 'column', required=False)
group_names = rest_util.parse_string_list(request, 'group', required=False)
try:
provider = registry.get_provider(name)
metrics_type = provider.get_metrics_type(include_choices=False)
except MetricsTypeError:
raise Http404
# Build a unique set of column names from groups
columns = metrics_type.get_column_set(column_names, group_names)
# Get the actual plot values
metrics_values = provider.get_plot_data(started, ended, choice_ids, columns)
page = self.paginate_queryset(metrics_values)
if len(choice_ids) > 1:
serializer = MetricsPlotMultiSerializer(page, many=True)
else:
serializer = MetricsPlotSerializer(page, many=True)
return self.get_paginated_response(serializer.data)
示例15: get
def get(self, request):
"""Retrieves the job load for a given time range and returns it in JSON form
:param request: the HTTP GET request
:type request: :class:`rest_framework.request.Request`
:rtype: :class:`rest_framework.response.Response`
:returns: the HTTP response to send back to the user
"""
started = rest_util.parse_timestamp(request, 'started', default_value=rest_util.get_relative_days(7))
ended = rest_util.parse_timestamp(request, 'ended', required=False)
rest_util.check_time_range(started, ended, max_duration=datetime.timedelta(days=31))
job_type_ids = rest_util.parse_int_list(request, 'job_type_id', required=False)
job_type_names = rest_util.parse_string_list(request, 'job_type_name', required=False)
job_type_categories = rest_util.parse_string_list(request, 'job_type_category', required=False)
job_type_priorities = rest_util.parse_string_list(request, 'job_type_priority', required=False)
job_loads = JobLoad.objects.get_job_loads(started, ended, job_type_ids, job_type_names, job_type_categories,
job_type_priorities)
job_loads_grouped = JobLoad.objects.group_by_time(job_loads)
page = rest_util.perform_paging(request, job_loads_grouped)
serializer = JobLoadGroupListSerializer(page, context={'request': request})
return Response(serializer.data, status=status.HTTP_200_OK)