def _update_service_announcement(text, is_published): ToolSetting.upsert('SERVICE_ANNOUNCEMENT_TEXT', text) ToolSetting.upsert('SERVICE_ANNOUNCEMENT_IS_PUBLISHED', is_published) return { 'text': text, 'isPublished': is_published, }
def update_service_announcement(): params = request.get_json() text = process_input_from_rich_text_editor(params.get('text', '')) if not text and _is_service_announcement_published(): raise BadRequestError('If the service announcement is published then API requires \'text\'') ToolSetting.upsert('SERVICE_ANNOUNCEMENT_TEXT', text) return tolerant_jsonify(_get_service_announcement())
def _is_service_announcement_published(): is_published = ToolSetting.get_tool_setting( 'SERVICE_ANNOUNCEMENT_IS_PUBLISHED') return False if is_published is None else to_bool_or_none(is_published)
def _get_service_announcement(): return { 'text': ToolSetting.get_tool_setting('SERVICE_ANNOUNCEMENT_TEXT'), 'isPublished': _is_service_announcement_published(), }
def publish_service_announcement(): publish = to_bool_or_none(request.get_json().get('publish')) if publish is None: raise BadRequestError('API requires \'publish\' arg') ToolSetting.upsert('SERVICE_ANNOUNCEMENT_IS_PUBLISHED', publish) return tolerant_jsonify(_get_service_announcement())