def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse: """ The handler for 'get' requests. This will render the 'edit.html' template with all models, all possible model outputs, the parameters that are configurable on each model, distribution types that may be used on each, and any sort of necessary messages :param HttpRequest request: The request asking to render this page :param args: An ordered list of arguments :param kwargs: A dictionary of named arguments :return: A rendered page """ errors, warnings, info = extract_log_data(kwargs) # Define a function that will make words friendlier towards humans. Text like 'hydro_whatsit' will # become 'Hydro Whatsit' def humanize(words: str) -> str: split = words.split("_") return " ".join(split).title() models = list(communication.get_available_models().keys()) domains = ['example-domain-A', 'example-domain-B'] #FIXME map this from supported domains outputs = list() distribution_types = list() # Create a mapping between each output type and a friendly representation of it for output in communication.get_available_outputs(): output_definition = dict() output_definition['name'] = humanize(output) output_definition['value'] = output outputs.append(output_definition) # Create a mapping between each distribution type and a friendly representation of it for distribution_type in communication.ModelExecRequest.get_distribution_types( ): type_definition = dict() type_definition['name'] = humanize(distribution_type) type_definition['value'] = distribution_type distribution_types.append(type_definition) # Package everything up to be rendered for the client payload = { 'models': models, 'domains': domains, 'outputs': outputs, 'parameters': communication.ModelExecRequest.get_parameters(), 'distribution_types': distribution_types, 'errors': errors, 'info': info, 'warnings': warnings } # Return the rendered page return render(request, 'maas/edit.html', payload)
def form_editor_payload(request_arguments: dict) -> dict: """ Accumulate and return all parameters needed to render the configuration screen Args: request_arguments: Parameters passed via an HttpRequest Returns: A dictionary, keyed by strings, representing some configurable setting(s) that need their value(s) changed. """ catchments = request_arguments.get('feature-ids', None) if catchments is not None: catchments = catchments.split("|") output_types = list() distribution_types = list() # Create a mapping between each output type and a friendly representation of it for output in communication.get_available_outputs(): output_definition = dict() output_definition['name'] = utilities.humanize(output) output_definition['value'] = output output_types.append(output_definition) # Create a mapping between each distribution type and a friendly representation of it for distribution_type in communication.MaaSRequest.get_distribution_types(): type_definition = dict() type_definition['name'] = utilities.humanize(distribution_type) type_definition['value'] = distribution_type distribution_types.append(type_definition) payload = { 'catchments': catchments, 'output_types': output_types, 'distribution_types': distribution_types, 'parameters': [ {"value": parameter, "name": utilities.humanize(parameter)} for parameter in MaaSRequest.get_parameters() ] } return payload
def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse: """ The handler for 'get' requests. This will render the 'edit.html' template with all models, all possible model outputs, the parameters that are configurable on each model, distribution types that may be used on each, and any sort of necessary messages :param HttpRequest request: The request asking to render this page :param args: An ordered list of arguments :param kwargs: A dictionary of named arguments :return: A rendered page """ # If a list of error messages wasn't passed, create one if 'errors' not in kwargs: errors = list() else: # Otherwise continue to use the passed in list errors = kwargs['errors'] # type: list # If a list of warning messages wasn't passed create one if 'warnings' not in kwargs: warnings = list() else: # Otherwise continue to use the passed in list warnings = kwargs['warnings'] # type: list # If a list of basic messages wasn't passed, create one if 'info' not in kwargs: info = list() else: # Otherwise continue to us the passed in list info = kwargs['info'] # type: list # Define a function that will make words friendlier towards humans. Text like 'hydro_whatsit' will # become 'Hydro Whatsit' def humanize(words: str) -> str: split = words.split("_") return " ".join(split).title() models = list(get_available_models().keys()) outputs = list() distribution_types = list() # Create a mapping between each output type and a friendly representation of it for output in get_available_outputs(): output_definition = dict() output_definition['name'] = humanize(output) output_definition['value'] = output outputs.append(output_definition) # Create a mapping between each distribution type and a friendly representation of it for distribution_type in MaaSRequest.get_distribution_types(): type_definition = dict() type_definition['name'] = humanize(distribution_type) type_definition['value'] = distribution_type distribution_types.append(type_definition) # Package everything up to be rendered for the client payload = { 'models': models, 'outputs': outputs, 'parameters': MaaSRequest.get_parameters(), 'distribution_types': distribution_types, 'errors': errors, 'info': info, 'warnings': warnings } # Return the rendered page return render(request, 'maas/edit.html', payload)