def _get_config_form_items(): # Styles for use in the form.select() macro. styles = [ {"text": "Default", "value": "/base/css/main.css"}, {"text": "Red", "value": "/base/css/red.css"}, {"text": "Green", "value": "/base/css/green.css"}, {"text": "Maroon", "value": "/base/css/maroon.css"}, {"text": "Fuchsia", "value": "/base/css/fuchsia.css"}, ] homepages = [ {"value": "1", "text": "Introductory area, search, featured group and featured organization"}, {"value": "2", "text": "Search, stats, introductory area, featured organization and featured group"}, {"value": "3", "text": "Search, introductory area and stats"}, ] items = [ {"name": "ckan.site_title", "control": "input", "label": _("Site Title"), "placeholder": ""}, {"name": "ckan.main_css", "control": "select", "options": styles, "label": _("Style"), "placeholder": ""}, {"name": "ckan.site_description", "control": "input", "label": _("Site Tag Line"), "placeholder": ""}, { "name": "ckan.site_logo", "control": "image_upload", "label": _("Site Tag Logo"), "placeholder": "", "upload_enabled": helpers.uploads_enabled(), "field_url": "ckan.site_logo", "field_upload": "logo_upload", "field_clear": "clear_logo_upload", }, {"name": "ckan.site_about", "control": "markdown", "label": _("About"), "placeholder": _("About page text")}, { "name": "ckan.site_intro_text", "control": "markdown", "label": _("Intro Text"), "placeholder": _("Text on home page"), }, { "name": "ckan.site_custom_css", "control": "textarea", "label": _("Custom CSS"), "placeholder": _("Customisable css inserted into the page header"), }, { "name": "ckan.homepage_style", "control": "select", "options": homepages, "label": _("Homepage"), "placeholder": "", }, ] return items
def _get_config_form_items(self): # Styles for use in the form.select() macro. styles = [{ 'text': 'Default', 'value': '/base/css/main.css' }, { 'text': 'Red', 'value': '/base/css/red.css' }, { 'text': 'Green', 'value': '/base/css/green.css' }, { 'text': 'Maroon', 'value': '/base/css/maroon.css' }, { 'text': 'Fuchsia', 'value': '/base/css/fuchsia.css' }] homepages = [{ 'value': '1', 'text': 'Introductory area, search, featured group and featured organization' }, { 'value': '2', 'text': 'Search, stats, introductory area, featured organization and featured group' }, { 'value': '3', 'text': 'Search, introductory area and stats' }] items = [ { 'name': 'ckan.site_title', 'control': 'input', 'label': _('Site Title'), 'placeholder': '' }, { 'name': 'ckan.main_css', 'control': 'select', 'options': styles, 'label': _('Style'), 'placeholder': '' }, { 'name': 'ckan.site_description', 'control': 'input', 'label': _('Site Tag Line'), 'placeholder': '' }, { 'name': 'ckan.site_logo', 'control': 'image_upload', 'label': _('Site Tag Logo'), 'placeholder': '', 'upload_enabled': h.uploads_enabled(), 'field_url': 'ckan.site_logo', 'field_upload': 'logo_upload', 'field_clear': 'clear_logo_upload' }, { 'name': 'ckan.site_about', 'control': 'markdown', 'label': _('About'), 'placeholder': _('About page text') }, { 'name': 'ckan.site_intro_text', 'control': 'markdown', 'label': _('Intro Text'), 'placeholder': _('Text on home page') }, { 'name': 'ckan.site_custom_css', 'control': 'textarea', 'label': _('Custom CSS'), 'placeholder': _('Customisable css inserted into the page header') }, { 'name': 'ckan.homepage_style', 'control': 'select', 'options': homepages, 'label': _('Homepage'), 'placeholder': '' }, ] return items
def orgportals_subdashboards_edit(self, org_name, subdashboard=None, data=None, errors=None, error_summary=None): if subdashboard: subdashboard = subdashboard[1:] data_dict = { 'org_name': org_name, 'subdashboard_name': subdashboard } _subdashboard = get_action('orgportals_subdashboards_show')({}, data_dict) if _subdashboard is None and len(subdashboard) > 0: p.toolkit.abort(404, _('Subdashboard not found.')) if _subdashboard is None: _subdashboard = {} if p.toolkit.request.method == 'POST' and not data: data = dict(p.toolkit.request.POST) media_items = [] for k, v in data.items(): item = {} if k.startswith('media_type'): id = k.split('_')[-1] if data['media_type_{}'.format(id)] == 'chart': item['order'] = int(id) item['media_type'] = data['media_type_{}'.format(id)] item['media_size'] = data['media_size_{}'.format(id)] item['chart_resourceview'] = data['chart_resourceview_{}'.format(id)] item['chart_subheader'] = data['chart_subheader_{}'.format(id)] media_items.append(item) elif data['media_type_{}'.format(id)] == 'youtube_video': item['order'] = int(id) item['media_type'] = data['media_type_{}'.format(id)] item['video_source'] = data['video_source_{}'.format(id)] item['video_title'] = data['video_title_{}'.format(id)] item['video_size'] = data['video_size_{}'.format(id)] item['video_title_url'] = data.get('video_title_url_{}'.format(id), item['video_source']) media_items.append(item) elif data['media_type_{}'.format(id)] == 'image': item['order'] = int(id) item['media_type'] = data['media_type_{}'.format(id)] item['image_title'] = data['media_image_title_{}'.format(id)] item['image_size'] = data.get('media_image_size_{}'.format(id), 'single') item['image_title_url'] = data.get('media_image_title_url_{}'.format(id), '') image_url = data['media_image_url_{}'.format(id)] # Upload images for topics if h.uploads_enabled(): image_upload = data['media_image_upload_{}'.format(id)] if isinstance(image_upload, cgi.FieldStorage): upload = uploader.get_uploader('portal', image_url) upload.update_data_dict(data, 'media_image_url_{}'.format(id), 'media_image_upload_{}'.format(id), 'image_clear_upload_{}'.format(id)) upload.upload(uploader.get_max_image_size()) image_url = upload.filename item['image_url'] = image_url media_items.append(item) _subdashboard['media'] = json.dumps(media_items) _subdashboard['map'] = [] _subdashboard['map_main_property'] = [] for k, v in sorted(data.items()): if k.startswith('map_main_property'): _subdashboard['map_main_property'].append(v) elif k.startswith('map_') and not k.startswith('map_enabled'): _subdashboard['map'].append(v) _subdashboard['map'] = ';'.join(_subdashboard['map']) _subdashboard['map_main_property'] = ';'.join(_subdashboard['map_main_property']) _subdashboard.update(data) _subdashboard['org_name'] = org_name _subdashboard['subdashboard_name'] = subdashboard try: junk = p.toolkit.get_action('orgportals_subdashboards_update')( data_dict=_subdashboard ) except p.toolkit.ValidationError, e: errors = e.error_dict error_summary = e.error_summary return self.orgportals_subdashboards_edit(org_name,'/' + subdashboard, data, errors, error_summary) p.toolkit.redirect_to(p.toolkit.url_for('orgportals_subdashboards_index', org_name=org_name))
def orgportals_pages_edit(self, org_name, page=None, data=None, errors=None, error_summary=None): if page: page = page[1:] data_dict = { 'org_name': org_name, 'page_name': page } _page = get_action('orgportals_pages_show')({}, data_dict) if _page is None and len(page) > 0: p.toolkit.abort(404, _('Page not found.')) if _page is None: _page = {} if p.toolkit.request.method == 'POST' and not data: if 'type' not in _page: _page['type'] = 'custom' data = dict(p.toolkit.request.POST) # Upload images for portal pages if 'image_upload' in dict(p.toolkit.request.params): image_upload = dict(p.toolkit.request.params)['image_upload'] if isinstance(image_upload, cgi.FieldStorage): upload = uploader.get_uploader('portal', data['image_url']) upload.update_data_dict(data, 'image_url', 'image_upload', 'clear_upload') upload.upload(uploader.get_max_image_size()) image_url = upload.filename else: image_url = data['image_url'] else: image_url = None if 'type' in _page and _page['type'] == 'data': _page['map'] = [] _page['map_main_property'] = [] for k, v in sorted(data.items()): if k.startswith('map_main_property'): _page['map_main_property'].append(v) elif k.startswith('map_') and not k.startswith('map_enabled'): _page['map'].append(v) _page['map'] = ';'.join(_page['map']) _page['map_main_property'] = ';'.join(_page['map_main_property']) topics = [] for k, v in data.items(): item = {} if k.startswith('topic_title'): id = k[-1] item['title'] = data['topic_title_{}'.format(id)] item['enabled'] = data['topic_enabled_{}'.format(id)] item['subdashboard'] = data['topic_subdashboard_{}'.format(id)] item['order'] = data['topic_order_{}'.format(id)] image_url = data['topic_image_url_{}'.format(id)] # Upload images for topics if h.uploads_enabled(): image_upload = data['topic_image_upload_{}'.format(id)] if isinstance(image_upload, cgi.FieldStorage): upload = uploader.get_uploader('portal', image_url) upload.update_data_dict(data, 'topic_image_url_{}'.format(id), 'topic_image_upload_{}'.format(id), 'topic_clear_upload_{}'.format(id)) upload.upload(uploader.get_max_image_size()) image_url = upload.filename item['image_url'] = image_url topics.append(item) _page['topics'] = json.dumps(topics) _page.update(data) _page['org_name'] = org_name _page['id'] = org_name _page['page_name'] = page _page['image_url'] = image_url try: junk = p.toolkit.get_action('orgportals_pages_update')( {'user': p.toolkit.c.user or p.toolkit.c.author}, data_dict=_page ) except p.toolkit.ValidationError, e: errors = e.error_dict error_summary = e.error_summary return self.orgportals_pages_edit(org_name,'/' + page, data, errors, error_summary) p.toolkit.redirect_to(p.toolkit.url_for('orgportals_pages_index', org_name=org_name))
def edit_visualizations(self, querytool=None, data=None, errors=None, error_summary=None): ''' Create or edit visualizations for the querytool :return: query edit template page ''' if querytool: querytool = querytool[1:] data_dict = { 'name': querytool } context = _get_context() try: check_access('querytool_update', context, data_dict) except NotAuthorized: abort(403, _('Not authorized to see this page')) _querytool = _get_action('querytool_get', data_dict) if _querytool is None and len(querytool) > 0: abort(404, _('Report not found.')) # Check if the data for this querytool still exists if _querytool['dataset_name']: try: _get_action('package_show', {'id': _querytool['dataset_name']}) except NotFound: abort(404, _('The data used for creating this ' 'report has been removed by ' 'the administrator.')) _visualization_items = \ _get_action('querytool_get_visualizations', data_dict) if _visualization_items is None: _visualization_items = { 'name': querytool } if toolkit.request.method == 'POST' and not data: data = dict(toolkit.request.POST) visualizations = [] text_boxes = [] images = [] maps = [] tables = [] break_lines = [] for k, v in data.items(): ''' TODO: save visualizations with key value e.g {'charts' :[] # 'images': []} for easier itteration ''' if k.startswith('chart_field_graph_'): visualization = {} id = k.split('_')[-1] visualization['type'] = 'chart' visualization['order'] = int(id) visualization['graph'] = \ data.get('chart_field_graph_{}'.format(id)) visualization['x_axis'] = \ data.get('chart_field_axis_x_{}'.format(id)) visualization['y_axis'] = \ data.get('chart_field_axis_y_{}'.format(id)) visualization['color'] = \ data.get('chart_field_color_{}'.format(id)) visualization['color_type'] = \ data.get('chart_field_color_type_{}'.format(id)) visualization['seq_color'] = \ data.get('chart_field_seq_color_{}'.format(id)) visualization['title'] = \ data.get('chart_field_title_{}'.format(id)) visualization['x_text_rotate'] = \ data.get('chart_field_x_text_rotate_{}'.format(id)) visualization['tooltip_name'] = \ data.get('chart_field_tooltip_name_{}'.format(id)) visualization['data_format'] = \ data.get('chart_field_data_format_{}'.format(id)) visualization['y_tick_format'] = \ data.get('chart_field_y_ticks_format_{}'.format(id)) visualization['x_tick_format'] = \ data.get('chart_field_x_ticks_format_{}'.format(id)) visualization['padding_bottom'] = \ data.get('chart_field_padding_bottom_{}'.format(id)) visualization['padding_top'] = \ data.get('chart_field_padding_top_{}'.format(id)) visualization['tick_count'] = \ data.get('chart_field_tick_count_{}'.format(id)) visualization['y_label'] = \ data.get('chart_field_y_label_{}'.format(id)) visualization['x_label'] = \ data.get('chart_field_x_label_{}'.format(id)) visualization['size'] = \ data.get('chart_field_size_{}'.format(id)) # visualization['chart_padding_left'] = \ # data.get('chart_field_chart_padding_left_{}'.format(id)) visualization['chart_padding_bottom'] = \ data.get('chart_field_chart_padding_bottom_{}'.format(id)) visualization['static_reference_columns'] = \ toolkit.request.POST.getall( 'chart_field_static_reference_columns_%s' % id) visualization['static_reference_label'] = \ data.get('chart_field_static_reference_label_%s' % id) visualization['dynamic_reference_type'] = \ data.get('chart_field_dynamic_reference_type_%s' % id) visualization['dynamic_reference_factor'] = \ data.get('chart_field_dynamic_reference_factor_%s' % id) visualization['dynamic_reference_label'] = \ data.get('chart_field_dynamic_reference_label_%s' % id) visualization['sort'] = \ data.get('chart_field_sort_{}'.format(id)) visualization['additional_description'] = \ data.get('chart_field_desc_{}'.format(id)) visualization['plotly'] = \ data.get('chart_field_plotly_{}'.format(id)) visualization['bar_width'] = \ data.get('chart_field_bar_width_{}'.format(id)) visualization['donut_hole'] = \ data.get('chart_field_donut_hole_{}'.format(id)) if 'chart_field_x_text_multiline_{}'.format(id) in data: visualization['x_text_multiline'] = 'true' else: visualization['x_text_multiline'] = 'false' visualization['x_tick_culling_max'] = \ data.get('chart_field_x_tick_culling_max_{}'.format(id)) if 'chart_field_legend_{}'.format(id) in data: visualization['show_legend'] = 'true' else: visualization['show_legend'] = 'false' if 'chart_field_show_annotations_{}'.format(id) in data: visualization['show_annotations'] = 'true' else: visualization['show_annotations'] = 'false' if 'chart_field_labels_{}'.format(id) in data: visualization['show_labels'] = 'true' else: visualization['show_labels'] = 'false' if 'chart_field_y_label_hide_{}'.format(id) in data: visualization['y_label_hide'] = 'true' else: visualization['y_label_hide'] = 'false' if 'chart_field_x_label_hide_{}'.format(id) in data: visualization['x_label_hide'] = 'true' else: visualization['x_label_hide'] = 'false' if 'chart_field_show_labels_as_percentages_{}'.format(id) in data: visualization['show_labels_as_percentages'] = 'true' else: visualization['show_labels_as_percentages'] = 'false' if 'chart_field_y_from_zero_{}'.format(id) in data: visualization['y_from_zero'] = 'true' else: visualization['y_from_zero'] = 'false' if 'chart_field_x_from_zero_{}'.format(id) in data: visualization['x_from_zero'] = 'true' else: visualization['x_from_zero'] = 'false' if data['chart_field_filter_name_{}'.format(id)]: visualization['filter_name'] = \ data['chart_field_filter_name_{}'.format(id)] visualization['filter_value'] = \ data['chart_field_filter_value_{}'.format(id)] visualization['filter_alias'] = \ data['chart_field_filter_alias_{}'.format(id)] visualization['filter_visibility'] = \ data['chart_field_filter_visibility_{}'.format(id)] else: visualization['filter_name'] = '' visualization['filter_value'] = '' visualization['filter_alias'] = '' visualization['filter_visibility'] = '' if 'chart_field_category_name_{}'.format(id) in data: visualization['category_name'] = \ data['chart_field_category_name_{}'.format(id)] else: visualization['category_name'] = '' print data visualizations.append(visualization) if k.startswith('text_box_description_'): text_box = {} id = k.split('_')[-1] text_box['type'] = 'text_box' text_box['order'] = int(id) text_box['description'] = \ data['text_box_description_{}'.format(id)] text_box['column_width'] = \ data.get('text_box_column_width_{}'.format(id), 'Half') text_boxes.append(text_box) if k.startswith('line_break_'): break_line = {} id = k.split('_')[-1] break_line['type'] = 'break_line' break_line['order'] = int(id) break_lines.append(break_line) if k.startswith('media_image_url_'): image = {} id = k.split('_')[-1] image['type'] = 'image' image['order'] = int(id) image_url = data['media_image_url_{}'.format(id)] if h.uploads_enabled(): image_upload = data['media_image_upload_{}'.format(id)] if isinstance(image_upload, cgi.FieldStorage): upload = uploader.get_uploader('vs', image_url) upload.update_data_dict(data, 'media_image_url_{}' .format( id), 'media_image_upload_{}' .format( id), 'False') upload.upload(uploader) image_url = upload.filename image['url'] = image_url images.append(image) if k.startswith('map_resource_'): map_item = {} id = k.split('_')[-1] map_item['type'] = 'map' map_item['order'] = int(id) map_item['map_resource'] = \ data['map_resource_{}'.format(id)] map_item['map_title_field'] = \ data['map_title_field_{}'.format(id)] map_item['map_key_field'] = \ data['map_key_field_{}'.format(id)] map_item['data_key_field'] = \ data['map_data_key_field_{}'.format(id)] map_item['map_color_scheme'] = \ data['map_color_scheme_{}'.format(id)] map_item['size'] = \ data.get('map_size_{}'.format(id)) if data.get('map_field_filter_name_{}'.format(id)): map_item['filter_name'] = \ data['map_field_filter_name_{}'.format(id)] map_item['filter_value'] = \ data['map_field_filter_value_{}'.format(id)] map_item['filter_alias'] = \ data['map_field_filter_alias_{}'.format(id)] map_item['filter_visibility'] = \ data['map_field_filter_visibility_{}'.format(id)] else: map_item['filter_name'] = '' map_item['filter_value'] = '' map_item['filter_alias'] = '' map_item['filter_visibility'] = '' maps.append(map_item) if k.startswith('table_field_title_'): table_item = {} id = k.split('_')[-1] table_item['type'] = 'table' table_item['order'] = int(id) table_item['y_axis'] = \ data['choose_y_axis_column'] table_item['main_value'] = \ data['table_main_value_{}'.format(id)] table_item['title'] = \ data['table_field_title_{}'.format(id)] table_item['data_format'] = \ data['table_data_format_{}'.format(id)] if data['table_field_filter_name_{}'.format(id)]: table_item['filter_name'] = \ data['table_field_filter_name_{}'.format(id)] table_item['filter_value'] = \ data['table_field_filter_value_{}'.format(id)] table_item['filter_alias'] = \ data['table_field_filter_alias_{}'.format(id)] table_item['filter_visibility'] = \ data['table_field_filter_visibility_{}'.format(id)] else: table_item['filter_name'] = '' table_item['filter_value'] = '' table_item['filter_alias'] = '' table_item['filter_visibility'] = '' if data['table_category_name_{}'.format(id)]: table_item['category_name'] = \ data['table_category_name_{}'.format(id)] else: table_item['category_name'] = '' tables.append(table_item) vis = visualizations + text_boxes + images + maps + tables + break_lines _visualization_items['visualizations'] = json.dumps(vis) if 'choose_y_axis_column' in data: _visualization_items['y_axis_column'] = \ data['choose_y_axis_column'] else: _visualization_items['y_axis_column'] = '' try: junk = _get_action('querytool_visualizations_update', _visualization_items) h.flash_success(_('Visualizations Successfully updated.')) except ValidationError, e: errors = e.error_dict error_summary = e.error_summary return self.querytool_edit('/' + querytool, data, errors, error_summary) if 'save-edit-data' in data.keys(): # redirect to edit data url = h.url_for('querytool_edit', querytool='/' + _querytool['name']) else: h.redirect_to('/'+h.lang()+'/group/'+_querytool['group']+'/reports') h.redirect_to(url)
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()
def _get_config_form_items(self): # Styles for use in the form.select() macro. styles = [{'text': 'Default', 'value': '/base/css/main.css'}, {'text': 'Red', 'value': '/base/css/red.css'}, {'text': 'Green', 'value': '/base/css/green.css'}, {'text': 'Maroon', 'value': '/base/css/maroon.css'}, {'text': 'Fuchsia', 'value': '/base/css/fuchsia.css'}] homepages = [{'value': '1', 'text': 'Introductory area, search, featured group and featured organization'}, {'value': '2', 'text': 'Search, stats, introductory area, featured organization and featured group'}, {'value': '3', 'text': 'Search, introductory area and stats'}] items = [ {'name': 'ckan.site_title', 'control': 'input', 'label': _('Site Title'), 'placeholder': ''}, {'name': 'ckan.main_css', 'control': 'select', 'options': styles, 'label': _('Style'), 'placeholder': ''}, {'name': 'ckan.site_description', 'control': 'input', 'label': _('Site Tag Line'), 'placeholder': ''}, {'name': 'ckan.site_logo', 'control': 'image_upload', 'label': _('Site Tag Logo'), 'placeholder': '', 'upload_enabled':h.uploads_enabled(), 'field_url': 'ckan.site_logo', 'field_upload': 'logo_upload', 'field_clear': 'clear_logo_upload'}, {'name': 'ckan.site_about', 'control': 'markdown', 'label': _('About'), 'placeholder': _('About page text')}, {'name': 'ckan.site_intro_text', 'control': 'markdown', 'label': _('Intro Text'), 'placeholder': _('Text on home page')}, {'name': 'ckan.site_custom_css', 'control': 'textarea', 'label': _('Custom CSS'), 'placeholder': _('Customisable css inserted into the page header')}, {'name': 'ckan.homepage_style', 'control': 'select', 'options': homepages, 'label': _('Homepage'), 'placeholder': ''}, ] return items
def post(self, name=None): context = self._prepare(name) research_question = context['research_question'] try: data_dict = logic.clean_dict( dictization_functions.unflatten( logic.tuplize_dict( logic.parse_params(request.form)))) except dictization_functions.DataError: abort(400, _(u'Integrity Error')) data_dict['id'] = research_question.get('id') data_dict.pop('save', '') if 'upload' in request.files: if h.uploads_enabled(): image_upload = request.files.get('upload') image_url = data_dict.get('image_url') image_ext = os.path.splitext(image_url)[1][1:] if image_ext not in ALLOWED_IMAGE_EXTENSIONS: errors = { 'url': ['Image extension not allowed!'], } error_summary = { 'url': 'Image extension not allowed!', } return self.get(data_dict, errors, error_summary) data_dict['upload'] = image_upload if isinstance(image_upload, FlaskFileStorage): try: upload = uploader.get_uploader( 'research_questions', image_url) upload.update_data_dict(data_dict, 'url', 'upload', 'False') upload.upload() data_dict['image_url'] = h.url_for_static( 'uploads/research_questions/%s' % upload.filename) except ValidationError as e: errors = e.error_dict error_summary = e.error_summary return self.get(data_dict, errors, error_summary) else: image_url = data_dict.get('image_url') if not image_url or image_url == 'placeholder-rq.png': data_dict['image_url'] = h.url_for_static( '/base/images/placeholder-rq.png') elif not (image_url.startswith('http') or image_url.startswith('https')): data_dict['image_url'] = h.url_for_static( 'uploads/research_questions/%s' % image_url) try: research_question = get_action( u'research_question_update')(context, data_dict) except NotAuthorized: abort(403, _(u'Unauthorized to update this research question')) except ValidationError as e: errors = e.error_dict error_summary = e.error_summary return self.get(name, data_dict, errors, error_summary) try: old_rq = context['research_question'] kwh_data = { 'type': 'rq', 'old_content': old_rq.get('title'), 'new_content': research_question.get('title') } logic.get_action(u'kwh_data_update')( context, kwh_data ) except Exception as e: log.debug('Error while storing KWH data: %s' % str(e)) return h.redirect_to(u'research_question.read', name=research_question.get(u'name'))