def querytool_update(context, data_dict): ''' Create new query tool :param title :param description :param dataset :param filters :param created :param map_resource :param chart_resource :param y_axis_columns ''' # we need the querytool name in the context for name validation context['querytool'] = data_dict['querytool'] session = context['session'] data, errors = df.validate(data_dict, schema.querytool_schema(), context) if errors: raise toolkit.ValidationError(errors) querytool = CkanextQueryTool.get(name=data_dict['querytool']) visualizations = \ CkanextQueryToolVisualizations.get(name=data_dict['querytool']) # if name is not changed don't insert in visualizations table is_changed = False if visualizations: is_changed = (querytool.name == visualizations.name) if visualizations and is_changed: visualizations.name = data.get('name') visualizations.save() session.add(querytool) session.commit() if not querytool: querytool = CkanextQueryTool() items = [ 'title', 'description', 'name', 'private', 'type', 'group', 'dataset_name', 'owner_org', 'filters', 'sql_string', 'related_querytools', 'chart_resource', 'y_axis_columns' ] for item in items: setattr(querytool, item, data.get(item)) querytool.modified = datetime.datetime.utcnow() querytool.save() session.add(querytool) session.commit()
def querytool_update(context, data_dict): ''' Create new query tool :param title :param description :param dataset :param filters :param created :param map_resource :param chart_resource :param y_axis_columns ''' check_access('querytool_update', context) # we need the querytool name in the context for name validation context['querytool'] = data_dict['querytool'] session = context['session'] data, errors = df.validate(data_dict, schema.querytool_schema(), context) if errors: raise toolkit.ValidationError(errors) querytool = CkanextQueryTool.get(name=data_dict['querytool']) if not querytool: querytool = CkanextQueryTool() items = [ 'title', 'description', 'name', 'dataset_name', 'filters', 'sql_string', 'map_resource', 'chart_resource', 'y_axis_columns' ] for item in items: setattr(querytool, item, data.get(item)) querytool.modified = datetime.datetime.utcnow() querytool.save() session.add(querytool) session.commit()
def querytool_update(context, data_dict): ''' Create new query tool :param title :param description :param dataset :param filters :param created :param map_resource :param chart_resource :param y_axis_columns :param selection_label :param report_caption ''' # we need the querytool name in the context for name validation context['querytool'] = data_dict['querytool'] session = context['session'] data, errors = df.validate(data_dict, schema.querytool_schema(), context) if errors: raise toolkit.ValidationError(errors) querytool = CkanextQueryTool.get(name=data_dict['querytool']) visualizations = \ CkanextQueryToolVisualizations.get(name=data_dict['querytool']) # if name is not changed don't insert in visualizations table is_changed = False if visualizations: is_changed = (querytool.name == visualizations.name) if visualizations and is_changed: visualizations.name = data.get('name') visualizations.save() session.add(querytool) session.commit() if not querytool: querytool = CkanextQueryTool() items = [ 'title', 'description', 'name', 'private', 'type', 'group', 'dataset_name', 'owner_org', 'icon', 'image_url', 'image_display_url', 'filters', 'sql_string', 'related_querytools', 'chart_resource', 'y_axis_columns', 'additional_description', 'selection_label', 'report_caption' ] dataset_name = data.get('dataset_name') dataset = _get_action('package_show')(context, {'id': dataset_name}) dataset['groups'] = [{'name': str(data.get('group'))}] _get_action('package_patch')(context, dataset) image_url = data_dict['image_url'] if h.uploads_enabled(): image_upload = data_dict['image_upload'] if isinstance(image_upload, cgi.FieldStorage): upload = uploader.get_uploader('querytool', image_url) upload.update_data_dict(data_dict, 'image_url', 'image_upload', 'clear_upload') upload.upload(uploader) data_dict['image_display_url'] = upload.filename data['image_display_url'] = upload.filename else: data['image_display_url'] = querytool.image_display_url for item in items: setattr(querytool, item, data.get(item)) querytool.modified = datetime.datetime.utcnow() querytool.save() session.add(querytool) session.commit()