def _adapter_layer_arguments(self): try: layer_arguments = adapter_layer_arguments(self.adapter_layer_json) except (ValueError, AttributeError): raise WorkspaceItemError("Undecodable json: %s", self.adapter_layer_json) return layer_arguments
def get_context_data(self, **kwargs): context = super(ThresholdsView, self).get_context_data(**kwargs) identifier = self.identifier() location_id = identifier["location"] workspace_item_id = self.request.GET.get("workspace_item_id") workspace_item = WorkspaceEditItem.objects.get(pk=workspace_item_id) layer_arguments = adapter_layer_arguments(workspace_item.adapter_layer_json) jdbc_source_slug = layer_arguments["slug"] try: jdbc_source = JdbcSource.objects.get(slug=jdbc_source_slug) except JdbcSource.DoesNotExist: raise WorkspaceItemError("Jdbc source %s doesn't exist." % jdbc_source_slug) parameter_id = layer_arguments["parameter"] filter_id = layer_arguments["filter"] named_locations = jdbc_source.get_locations(filter_id, parameter_id) location_name = [location["location"] for location in named_locations if location["locationid"] == location_id][ 0 ] context["location_name"] = location_name # get the threshold belonging to the location, filter and parameter ids thresholds = Threshold.objects.filter(location_id=location_id, filter_id=filter_id, parameter_id=parameter_id) context["location"] = location_id context["thresholds"] = thresholds adapter = workspace_item.adapter context["adapter"] = adapter image_graph_url = workspace_item.url("lizard_map_adapter_image", [identifier]) context["image_graph_url"] = image_graph_url flot_graph_data_url = workspace_item.url("lizard_map_adapter_flot_graph_data", [identifier]) context["flot_graph_data_url"] = flot_graph_data_url context["form"] = ThresholdCreateForm( initial={"workspace_item_id": workspace_item_id, "location_id": location_id} ) return context
def save(self, commit=True): workspace_item = WorkspaceEditItem.objects.get( pk=self.cleaned_data['workspace_item_id']) layer_arguments = adapter_layer_arguments( workspace_item.adapter_layer_json) parameter_id = layer_arguments['parameter'] filter_id = layer_arguments['filter'] instance = super(ThresholdCreateForm, self).save(commit=False) instance.filter_id = filter_id instance.parameter_id = parameter_id if commit: instance.save() return instance