Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
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'
Exemplo n.º 4
0
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'
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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
Exemplo n.º 7
0
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
Exemplo n.º 8
0
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
Exemplo n.º 9
0
def beta_or_prod_asset():
    if 'qld.gov.au' in h.full_current_url():
        return 'global/prod-includes/'
    else:
        return 'global/beta-includes/'