def test_build_table_and_orm(self): # Check if 'ngds_system_info' table exists, build it if it doesn't table = Table('ngds_system_info', model.meta.metadata) if not table.exists(): db.init(model) assert (table.exists())
def test_build_table_and_orm(self): # Check if 'ngds_system_info' table exists, build it if it doesn't table = Table('ngds_system_info', model.meta.metadata) if not table.exists(): db.init(model) assert(table.exists())
def config(self, items): """ If this method gets called from the vanilla admin page for custom UI settings, then we update the ckan.* config variables through the 'app_globals' module and CKAN stores that information in the 'system_info' table so that custom configs will persist through a server failure. If this method gets called from the NGDS admin page for data settings, then the 'app_globals' module gets updated in memory but we write the configs to a custom 'ngds_system_info' table. @param items: pylons global config options @return: dictionary """ data = request.POST if 'data-config' in data: if db.ngds_system_info is None: db.init(model) update_db = db.SysadminConfig.get(active_config=True) if data.get('data-config') == 'save': class Featured: def __init__(self, config, description): self.config = config self.description = description posted_data = tuple([Featured(key, value) for (key, value) in data.iteritems() for item in items if key == item['name']]) if posted_data: posted_key = posted_data[0].config featured_data = [] for post in posted_data: featured_data.append({post.config: post.description}) featured_json = json.dumps(featured_data) app_globals.set_global(posted_key, featured_json) setattr(update_db, posted_key, featured_json) app_globals.reset() update_db.last_edited = datetime.datetime.utcnow() update_db.save() session = model.Session session.add(update_db) session.commit() h.redirect_to(controller=self.controller, action='data_config') if data.get('data-config') == 'reset': app_globals.set_global('ngds.featured_data', None) setattr(update_db, 'ngds.featured_data', None) app_globals.reset() update_db.last_edited = datetime.datetime.utcnow() update_db.save() session = model.Session session.add(update_db) session.commit() h.redirect_to(controller=self.controller, action='data_config') if 'save-operating-config' in data: # Set up ORM if it's not already set if db.ngds_system_info is None: db.init(model) # Get db data to update update_db = db.SysadminConfig.get(active_config=True) for item in items: name = item['name'] if name in data: # Update app_globals in memory app_globals.set_global(name, data[name]) # Update database setattr(update_db, name, data.get(name)) app_globals.reset() update_db.last_edited = datetime.datetime.utcnow() update_db.save() session = model.Session session.add(update_db) session.commit() h.redirect_to(controller=self.controller, action='operating_config') if 'save-style-config' in data: for item in items: name = item['name'] if name in data: app_globals.set_global(name, data[name]) app_globals.reset() h.redirect_to(controller=self.controller, action='style_config') data = {} for item in items: name = item['name'] data[name] = config.get(name) try: data = json.loads(data) except: pass return {'data': data, 'errors': {}, 'form_items': items}
def config(self, items): """ If this method gets called from the vanilla admin page for custom UI settings, then we update the ckan.* config variables through the 'app_globals' module and CKAN stores that information in the 'system_info' table so that custom configs will persist through a server failure. If this method gets called from the NGDS admin page for data settings, then the 'app_globals' module gets updated in memory but we write the configs to a custom 'ngds_system_info' table. @param items: pylons global config options @return: dictionary """ data = request.POST if 'data-config' in data: if db.ngds_system_info is None: db.init(model) update_db = db.SysadminConfig.get(active_config=True) if data.get('data-config') == 'save': class Featured: def __init__(self, config, description): self.config = config self.description = description posted_data = tuple([ Featured(key, value) for (key, value) in data.iteritems() for item in items if key == item['name'] ]) if posted_data: posted_key = posted_data[0].config featured_data = [] for post in posted_data: featured_data.append({post.config: post.description}) featured_json = json.dumps(featured_data) app_globals.set_global(posted_key, featured_json) setattr(update_db, posted_key, featured_json) app_globals.reset() update_db.last_edited = datetime.datetime.utcnow() update_db.save() session = model.Session session.add(update_db) session.commit() h.redirect_to(controller=self.controller, action='data_config') if data.get('data-config') == 'reset': app_globals.set_global('ngds.featured_data', None) setattr(update_db, 'ngds.featured_data', None) app_globals.reset() update_db.last_edited = datetime.datetime.utcnow() update_db.save() session = model.Session session.add(update_db) session.commit() h.redirect_to(controller=self.controller, action='data_config') if 'save-operating-config' in data: # Set up ORM if it's not already set if db.ngds_system_info is None: db.init(model) # Get db data to update update_db = db.SysadminConfig.get(active_config=True) for item in items: name = item['name'] if name in data: # Update app_globals in memory app_globals.set_global(name, data[name]) # Update database setattr(update_db, name, data.get(name)) app_globals.reset() update_db.last_edited = datetime.datetime.utcnow() update_db.save() session = model.Session session.add(update_db) session.commit() h.redirect_to(controller=self.controller, action='operating_config') if 'save-style-config' in data: for item in items: name = item['name'] if name in data: app_globals.set_global(name, data[name]) app_globals.reset() h.redirect_to(controller=self.controller, action='style_config') data = {} for item in items: name = item['name'] data[name] = config.get(name) try: data = json.loads(data) except: pass return {'data': data, 'errors': {}, 'form_items': items}