Exemple #1
0
    def process_path(path, request):
        default_language = settings.PARLER_DEFAULT_LANGUAGE_CODE
        prefix_default = settings.PREFIX_DEFAULT_LANGUAGE

        query = build_select_path_query(path)
        data, success, *_ = execute_query(query)

        path_item = py_.find(data, lambda item: item['lang'] == get_language())

        if not path_item and len(data):
            lang_code = data[0]['lang']
            protocol = request.scheme + '://'
            redirect = ''
            if lang_code == default_language and not prefix_default:
                redirect = request.get_host() + '/' + path
            else:
                redirect = request.get_host() + '/' + lang_code + '/' + path

            query = '?' + request.META.get('QUERY_STRING') if request.META.get(
                'QUERY_STRING') else ''

            return {'redirect': protocol + redirect + query}

        if not path_item:
            return {'not_found': True}

        return {
            'page_id': path_item.get('page_id'),
            'pattern': path_item.get('pattern')
        }
Exemple #2
0
    def get_section_props_raw(ids):
        section_ids = '(' + ','.join([str(id) for id in ids]) + ')'
        query = build_select_section_prop_query(section_ids, get_language())
        data, success, *_ = execute_query(query)
        props = {}
        for prop in data:
            props.setdefault(prop['id'], {})[prop['name']] = prop['value']

        return props
Exemple #3
0
 def get_page_meta(page_id, request):
     query = build_select_page_meta_query(page_id, get_language())
     data, success, *_ = execute_query(query)
     meta = data[0] if success and len(data) else None
     if not meta: return {}
     meta['locale'] = get_language()
     meta['site_name'] = request.META['HTTP_HOST']
     meta['image'] = {
         'url':
         request.build_absolute_uri('/static/img/page_thumbnail.png'),
         'type': 'image/png',
         'width': 550,
         'height': 540,
         'alt': 'rkam page thumbnail',
     }
     return meta
Exemple #4
0
 def get_menus_raw(page_id):
     query = build_select_page_menus_query(page_id, get_language())
     data, success, *_ = execute_query(query)
     menus = {}
     for row in data:
         menus.setdefault(
             row.get('id'), {
                 'id': row['id'],
                 'name': row['name'],
                 'template': row['template'],
                 'style': row['style'],
                 'items': []
             })['items'].append({
                 'text': row['item_text'],
                 'url': row['item_url']
             })
     return list(menus.values())
Exemple #5
0
 def get_sections_raw(page_id):
     query = build_select_section_query(page_id)
     data, success, *_ = execute_query(query)
     return data
Exemple #6
0
 def get_page_raw(page_id):
     query = build_select_page_query(page_id)
     page, success, *_ = execute_query(query)
     return [page[0].get('name'), page[0].get('template')
             ] if success else []