def before_view(self, pkg_dict): # Redirect to correct URL based on schema name actions_accepted = ['read','edit','new'] if (c.action in actions_accepted and c.controller=='package'): schema_expected = pkg_dict['type'] schema_current = str(h.full_current_url()).replace(g.site_url, '').split('/')[1] if (schema_current != schema_expected): from pylons.controllers.util import redirect url_current = h.full_current_url() url_current = str(url_current).replace(g.site_url+'/'+schema_current, g.site_url+'/'+schema_expected) # print('redir_to',url_current) # print(schema_expected) # print(schema_current) redirect(url_current.replace(g.site_url,'')) return pkg_dict
def before_search(self, search_params): # Redirect for search page schemas = self.scheming_get_types() url_current = h.full_current_url() if(url_current.replace(g.site_url+'/','') in schemas): from pylons.controllers.util import redirect redirect(url_current.replace(g.site_url,'')+'s') return search_params
def get_schema_name(dataset_name=None): ''' Return schema name ''' if(dataset_name == None): schema_name = str(h.full_current_url()).replace(g.site_url, '').split('/')[1].split('?')[0] if(schema_name[-1:]=='s'): schema_name=schema_name[:-1] # print(schema_name) return schema_name return 'dataset'
def get_schema_name(dataset_name=None): ''' Return schema name ''' if (dataset_name == None): schema_name = str(h.full_current_url()).replace( g.site_url, '').split('/')[1].split('?')[0] if (schema_name[-1:] == 's'): schema_name = schema_name[:-1] # print(schema_name) return schema_name return 'dataset'
def wordpress_posts(type_content="", custom=10): # Get all posts if (type_content == "all"): # URL url = wordpress_get_domain() + "/wp-json/wp/v2/posts?per_page=" + str( custom) # Get posts and return return wordpress_cache_json(url) # Get single post if "noticias" in h.full_current_url(): items_url = h.full_current_url().split('/') items_url.pop() # remove slug post_id = items_url.pop() # get post id url = wordpress_get_domain() + "/wp-json/wp/v2/posts/" + str(post_id) return wordpress_cache_json(url) pass
def get_current_url(): ''' Get current url without the host part and query parameters etc., change it to secure ssl connection if not in debug mode :return: url path, e.g. https://host.name.fi/fi/dataset/abc-1234 ''' url = urlparse(h.full_current_url()) # Dropping the rest of the parameters because url encoding will too easily break stuff if g.debug: return 'http://' + url.netloc + url.path return 'https://' + url.netloc + url.path
def wordpress_pages(type_content="", custom=10): # Get single post if "paginas" in h.full_current_url(): items_url = h.full_current_url().split('/') page_slug = items_url.pop() # get page slug url = wordpress_get_domain( ) + "/wp-json/wp/v2/pages?filter[name]=" + str(page_slug) + "&_embed" # Check error j = wordpress_cache_json(url) if ('error' in j): print(dir(j)) print(str(j.values())) print('') return j else: print(dir(j[0])) print(str(j[0].values())) print('') return j[0] pass
def beta_or_prod_asset(): if 'qld.gov.au' in h.full_current_url(): return 'global/prod-includes/' else: return 'global/beta-includes/'