def search_list(context, data_dict): ''' List the search history :param limit: The number of items to show (optional, default: 10) :type limit: int ''' if db.search_history_table is None: db.init_db(context['model']) tk.check_access('search_history_list', context, data_dict) username = context.get('user') user = new_authz.get_user_id_for_username(username, allow_none=False) # Get the limit and put a hard upper limit on it limit = data_dict.get('limt', 10) if limit > 25: limit = 25 history = db.SearchHistory.search_history(user_id=user, limit=limit) result = [] if history: for item in history: data_dict = db.table_dictize(item, context) data_dict['params'] = json.loads(data_dict.get('params')) result.append(data_dict) return result
def search_add(context, data_dict): ''' Add an item to the search_history for the current user. :param content: Search query to add to history :type content: string ''' try: tk.check_access('ckanext_search_history_add', context, data_dict) except tk.NotAuthorized: #JOE# #tk.abort(401, tk._('Not authorized to add history item')) pass if db.search_history_table is None: db.init_db(context['model']) content = tk.get_or_bust(data_dict, 'content') username = context.get('user') #JOE# #user_id = new_authz.get_user_id_for_username(username, allow_none=False) user_id = new_authz.get_user_id_for_username(username, allow_none=True) search_history = db.SearchHistory() search_history.content = content search_history.user_id = user_id session = context['session'] session.add(search_history) session.commit() return db.table_dictize(search_history, context)
def _pages_show(context, data_dict): if db.pages_table is None: db.init_db(context['model']) org_id = data_dict.get('org_id') page = data_dict.get('page') out = db.Page.get(group_id=org_id, name=page) if out: out = db.table_dictize(out, context) return out
def yammer_config(id): try: context = {'for_view': True} yammer_config_options = yammer_user.Yammer_user().get(id) form = db.table_dictize(yammer_config_options, context) jsonform = json.dumps(form) print yammer_config_options return str(jsonform) except exc.SQLAlchemyError: return 'failure'
def _pages_show(context, data_dict): lang = get_language() if db.pages_table is None: db.init_db(context['model']) org_id = data_dict.get('org_id') page = data_dict.get('page') out = db.Page.get(group_id=org_id, name=page, lang=lang) if out: out = db.table_dictize(out, context) # if no entry was found load entry for default language if not out: lang = get_default_language() out = db.Page.get(group_id=org_id, name=page, lang=lang) return out
def _pages_show(context, data_dict): if db.pages_table is None: db.init_db(context['model']) org_id = data_dict.get('org_id') page = data_dict.get('page') order = data_dict.get('order') lang = data_dict.get('lang') out = None if page or org_id: out = db.Page.get(group_id=org_id, name=page) elif lang and order: out = db.Page.get(order=order, lang=lang) if out: out = db.table_dictize(out, context) return out
def search_list(context, data_dict): ''' List the search history :param limit: The number of items to show (optional, default: 10) :type limit: int ''' tk.check_access('ckanext_search_history_list', context, data_dict) if db.search_history_table is None: db.init_db(context['model']) username = context.get('user') user = new_authz.get_user_id_for_username(username, allow_none=False) limit = data_dict.get('limt') history = db.SearchHistory.search_history(user_id=user, limit=limit) result = [] if history: for item in history: result.append(db.table_dictize(item, context)) return result
def search_add(context, data_dict): ''' Add an item to the search_history for the current user. :param params: Search query to add to history :type params: string ''' tk.check_access('search_history_add', context, data_dict) if db.search_history_table is None: db.init_db(context['model']) data, errors = df.validate(data_dict, schema_add, context) username = context.get('user') user_id = new_authz.get_user_id_for_username(username, allow_none=False) search_history = db.SearchHistory() search_history.params = data.get('params') search_history.user_id = user_id session = context['session'] session.add(search_history) session.commit() return db.table_dictize(search_history, context)