def get_node_template_name(node): try: view = get_view_from_url(node.get_absolute_url()) except (AttributeError, Resolver404): return settings.DJANGOCMS_SPA_VUE_JS_ERROR_404_TEMPLATE if view.__module__ == 'cms.views': template = node.attr.get('template') if not template: template = node.attr.get('cms_page').get_template() return template else: return view.template_name
def get_node_route_for_cms_page(request, node, route_data): cms_page = node.attr['cms_page'] cms_page_title = cms_page.title_set.get(language=request.LANGUAGE_CODE) cms_template = cms_page.get_template() # Set name and component of the route. route_data['name'] = get_vue_js_router_name_for_cms_page(cms_page.pk) if not node.attr.get('redirect_url'): route_data['component'] = get_frontend_component_name_by_template( cms_template) # Add the link to fetch the data from the API. if not cms_page.application_urls: if not cms_page_title.path: # The home page does not have a path fetch_url = reverse('api:cms_page_detail_home') elif node.attr.get('named_route_path_pattern'): # Get the fetch_url of the parent node through the path of the parent node parent_node_path = cms_page_title.path.replace( '/%s' % cms_page_title.slug, '') fetch_url_of_parent_node = reverse( 'api:cms_page_detail', kwargs={'path': parent_node_path}) fetch_url = '{parent_url}{path_pattern}/'.format( parent_url=fetch_url_of_parent_node, path_pattern=node.attr.get('named_route_path_pattern')) else: fetch_url = reverse('api:cms_page_detail', kwargs={'path': cms_page_title.path}) route_data['api']['fetch'] = {'url': fetch_url} # Add redirect url if available. if node.attr.get('redirect_url'): route_data['redirect'] = node.attr['redirect_url'] else: # Apphooks use a view that has a custom API URL to fetch data from. view = get_view_from_url(node.get_absolute_url()) fetch_url = force_text(view().get_fetch_url()) route_data['api']['fetch'] = fetch_url # Add initial data for the selected page. if node.selected and node.get_absolute_url() == request.path: fetched_data = { 'response': { 'data': get_frontend_data_dict_for_cms_page( cms_page=cms_page, cms_page_title=cms_page_title, request=request, editable=request.user.has_perm('cms.change_page')) } } if node.attr.get('named_route_path_pattern'): url_param = node.attr['named_route_path_pattern'].replace(':', '') if url_param: fetched_data.update( {'params': { url_param: cms_page_title.slug }}) route_data['api']['fetched'] = fetched_data if len(settings.LANGUAGES) > 1: route_data['path'] = '/%s/%s' % (request.LANGUAGE_CODE, cms_page_title.path) else: route_data['path'] = '/%s' % cms_page_title.path return route_data
def get_node_route_for_cms_page(request, node, route_data): cms_page = node.attr['cms_page'] cms_page_title = cms_page.title_set.get(language=request.LANGUAGE_CODE) cms_template = cms_page.get_template() # Set name and component of the route. route_data['name'] = get_vue_js_router_name_for_cms_page(cms_page.pk) if not node.attr.get('redirect_url'): route_data['component'] = get_frontend_component_name_by_template( cms_template) # Add the link to fetch the data from the API. if cms_page.application_urls not in settings.DJANGOCMS_SPA_VUE_JS_APPHOOKS_WITH_ROOT_URL: if not cms_page_title.path: # The home page does not have a path if hasattr(settings, 'DJANGOCMS_SPA_USE_SERIALIZERS' ) and settings.DJANGOCMS_SPA_USE_SERIALIZERS: fetch_url = reverse( 'api:cms_page_detail', kwargs={'path': settings.DJANGOCMS_SPA_HOME_PATH}) else: fetch_url = reverse('api:cms_page_detail_home') elif node.attr.get('named_route_path_pattern'): # Get the fetch_url of the parent node through the path of the parent node parent_node_path = cms_page_title.path.replace( '/%s' % cms_page_title.slug, '') fetch_url_of_parent_node = reverse( 'api:cms_page_detail', kwargs={'path': parent_node_path}) fetch_url = '{parent_url}{path_pattern}/'.format( parent_url=fetch_url_of_parent_node, path_pattern=node.attr.get('named_route_path_pattern')) else: fetch_url = reverse('api:cms_page_detail', kwargs={'path': cms_page_title.path}) # Add redirect url if available. if node.attr.get('redirect_url'): route_data['redirect'] = node.attr['redirect_url'] else: # Apphooks use a view that has a custom API URL to fetch data from. view = get_view_from_url(node.get_absolute_url()) fetch_url = force_text(view().get_fetch_url()) route_data['api']['fetch'] = { 'url': fetch_url, } if cms_page.reverse_id: route_data['meta'] = {'id': cms_page.reverse_id} # Add initial data for the selected page. if node.selected and node.get_absolute_url() == request.path: if hasattr(settings, 'DJANGOCMS_SPA_USE_SERIALIZERS' ) and settings.DJANGOCMS_SPA_USE_SERIALIZERS: from djangocms_spa.serializers import PageSerializer data = PageSerializer(instance=cms_page).data else: data = get_frontend_data_dict_for_cms_page( cms_page=cms_page, cms_page_title=cms_page_title, request=request, editable=request.user.has_perm('cms.change_page')) fetched_data = {'response': {'data': data}} if node.attr.get('named_route_path_pattern'): url_param = node.attr['named_route_path_pattern'].replace(':', '') if url_param: fetched_data.update( {'params': { url_param: cms_page_title.slug }}) route_data['api']['fetched'] = fetched_data if settings.DJANGOCMS_SPA_VUE_JS_USE_I18N_PATTERNS: route_data['path'] = '/%s/%s' % (request.LANGUAGE_CODE, cms_page_title.path) else: route_data['path'] = '/%s' % cms_page_title.path return route_data