Esempio n. 1
0
def translation_links(context, calling_page):
    """Take the inclusion template 'translation_links.html' and return a snippet of HTML with links to the requesting page in all offered languages."""
    language_results = []

    query = ''
    try:
        query = context['request'].GET
        query = '?%s' % query.urlencode() if query else ''
    except Exception:
        pass

    if calling_page != "":
        for language_code, language_name in settings.ACTIVE_LANGUAGES:
            with use_language(language_code):
                language_url = pageurl(context, calling_page)
                language_name_local = get_language_info(language_code)['name_local']
                language_results.append({
                    "code": language_code,
                    "name": language_name,
                    "url": language_url,
                    "name_local": language_name_local,
                    "query": query,
                })

    return {
        'languages': language_results,
    }
Esempio n. 2
0
def translation_links(context, calling_page):
    """Take the inclusion template 'translation_links.html' and return a snippet of HTML with links to the requesting page in all offered languages."""
    language_results = []
    if calling_page != "":
        for language_code, language_name in settings.ACTIVE_LANGUAGES:
            with use_language(language_code):
                language_url = pageurl(context, calling_page)
                language_results.append({
                    "code": language_code,
                    "name": language_name,
                    "url": language_url
                })

    return {
        'languages': language_results,
    }
Esempio n. 3
0
    def handle(self, *args, **options):
        """Implement the command handler."""
        if not options['old_pk']:
            raise CommandError('Please pass the old primary key as first positional argument.')
        if not options['new_pk']:
            raise CommandError('Please pass the new primary key as second positional argument.')

        home_page = HomePage.objects.first()

        old_link_str = '<a id=\\"{}\\" linktype=\\"page\\">'.format(options['old_pk'])
        new_link_str = '<a id=\\"{}\\" linktype=\\"page\\">'.format(options['new_pk'])

        for page in Page.objects.all():
            specific_page = page.specific
            for language_code, language_name in settings.ACTIVE_LANGUAGES:
                content_field_name = "content_editor_{}".format(language_code)
                if hasattr(specific_page, content_field_name):
                    content_field = getattr(specific_page, content_field_name)
                    content_str = json.dumps(content_field.raw_data)
                    if old_link_str in content_str:
                        self.stdout.write(self.style.SUCCESS('Replacing soft-link in page: {}'.format(specific_page.title)))
                        edited_content_str = content_str.replace(old_link_str, new_link_str)
                        setattr(specific_page, content_field_name, edited_content_str)
                        if specific_page.live:
                            specific_page.save_revision().publish()
                        else:
                            specific_page.save_revision()

        for language_code, language_name in settings.ACTIVE_LANGUAGES:
            with use_language(language_code):
                old_page = Page.objects.get(pk=options['old_pk'])
                new_page = Page.objects.get(pk=options['new_pk'])
                redirect, created = Redirect.objects.get_or_create(
                    site=home_page.get_site(),
                    old_path=old_page.url
                )
                redirect.redirect_page = new_page
                redirect.save()

        self.stdout.write(self.style.SUCCESS('Successfully replaced {} with {}'.format(options['old_pk'], options['new_pk'])))
 def handle(self, **options):
     with use_language(mt_settings.DEFAULT_LANGUAGE):
         for node in Page.get_root_nodes():
             self.set_subtree(node, None)
Esempio n. 5
0
 def handle(self, **options):
     with use_language(mt_settings.DEFAULT_LANGUAGE):
         for node in Page.get_root_nodes():
             self.set_subtree(node, None)