def get_parent_active_language_choices(parent_object, exclude_current=False):
    """
    .. versionadded:: 1.0

    Get the currently active languages of an parent object.

    Note: if there is no content at the page, the language won't be returned.
    """
    assert parent_object is not None, "Missing parent_object!"

    from .db import ContentItem
    qs = ContentItem.objects \
        .parent(parent_object, limit_parent_language=False) \
        .values_list('language_code', flat=True).distinct()

    languages = set(qs)

    if exclude_current:
        parent_lang = get_parent_language_code(parent_object)
        try:
            languages.remove(parent_lang)
        except KeyError:
            pass

    # No multithreading issue here, object is instantiated for this user only.
    choices = [(lang, str(get_language_title(lang))) for lang in languages
               if lang]
    choices.sort(key=lambda tup: tup[1])
    return choices
def get_parent_active_language_choices(parent_object, exclude_current=False):
    """
    .. versionadded:: 1.0

    Get the currently active languages of an parent object.

    Note: if there is no content at the page, the language won't be returned.
    """
    assert parent_object is not None, "Missing parent_object!"

    from .db import ContentItem
    qs = ContentItem.objects \
        .parent(parent_object, limit_parent_language=False) \
        .values_list('language_code', flat=True).distinct()

    languages = set(qs)

    if exclude_current:
        parent_lang = get_parent_language_code(parent_object)
        try:
            languages.remove(parent_lang)
        except KeyError:
            pass

    # No multithreading issue here, object is instantiated for this user only.
    choices = [(lang, str(get_language_title(lang))) for lang in languages if lang]
    choices.sort(key=lambda tup: tup[1])
    return choices
    def preview_view(self, request, object_id):
        obj = self.get_object(request, object_id)
        email_format = request.GET.get('format', None) or 'html'
        TITLES = {
            'html': _("Preview HTML: {subject}"),
            'text': _("Preview plain text: {subject}"),
        }
        TITLES['txt'] = TITLES['text']
        if email_format not in TITLES:
            email_format = 'html'

        context = {
            'title': TITLES[email_format].format(subject=obj.subject),
            'app_label': obj._meta.app_label,
            'opts': obj._meta,
            'media': self.media,
            'object': obj,
            'email_format': email_format
        }

        # Add django-parler language tabs (copied from TranslatableAdmin.render_change_form())
        lang_code = self.get_form_language(request, obj)
        lang = get_language_title(lang_code)

        available_languages = self.get_available_languages(obj)
        language_tabs = self.get_language_tabs(request, obj, available_languages)
        context['language_tabs'] = language_tabs
        if language_tabs:
            context['title'] = '%s (%s)' % (context['title'], lang)

        return TemplateResponse(request, self.preview_template, context)
Beispiel #4
0
def get_parent_active_language_choices(parent_object, exclude_current=False):
    """
    .. versionadded:: 1.0

    Get the currently active languages of an parent object.

    Note: if there is no content at the page, the language won't be returned.
    """
    assert parent_object is not None, "Missing parent_object!"

    from .db import ContentItem
    qs = ContentItem.objects \
        .parent(parent_object, limit_parent_language=False) \
        .values_list('language_code', flat=True).distinct()

    languages = set(qs)

    if exclude_current:
        parent_lang = get_parent_language_code(parent_object)
        languages.discard(parent_lang)

    if parler_appsettings.PARLER_LANGUAGES and not parler_appsettings.PARLER_SHOW_EXCLUDED_LANGUAGE_TABS:
        site_id = get_parent_site_id(parent_object)
        try:
            lang_dict = parler_appsettings.PARLER_LANGUAGES[site_id]
        except KeyError:
            lang_dict = ()

        allowed_languages = set(item['code'] for item in lang_dict)
        languages &= allowed_languages

    # No multithreading issue here, object is instantiated for this user only.
    choices = [(lang, str(get_language_title(lang))) for lang in languages if lang]
    choices.sort(key=lambda tup: tup[1])
    return choices
Beispiel #5
0
 def __str__(self):
     # Note this representation is optimized for the admin delete page.
     return u"'{type} {id:d}' in '{language} {placeholder}'".format(
         type=ContentType.objects.get_for_id(
             self.polymorphic_ctype_id).model_class()._meta.verbose_name,
         id=self.id or 0,
         language=get_language_title(self.language_code),
         placeholder=self.placeholder)
 def __unicode__(self):
     # Note this representation is optimized for the admin delete page.
     return u"'{type} {id:d}' in '{language} {placeholder}'".format(
         type=ContentType.objects.get_for_id(self.polymorphic_ctype_id).model_class()._meta.verbose_name,
         id=self.id or 0,
         language=get_language_title(self.language_code),
         placeholder=self.placeholder
     )
Beispiel #7
0
def get_language_tabs(request,
                      current_language,
                      available_languages,
                      css_class=None):
    """
    Determine the language tabs to show.
    """
    tabs = TabsList(css_class=css_class)
    get = request.GET.copy()  # QueryDict object
    tab_languages = []

    site_id = getattr(settings, 'SITE_ID', None)
    for lang_dict in appsettings.PARLER_LANGUAGES.get(site_id, ()):
        code = lang_dict['code']
        title = get_language_title(code)
        get['language'] = code
        url = '?{0}'.format(get.urlencode())

        if code == current_language:
            status = 'current'
        elif code in available_languages:
            status = 'available'
        else:
            status = 'empty'

        tabs.append((url, title, code, status))
        tab_languages.append(code)

    # Additional stale translations in the database?
    if appsettings.PARLER_SHOW_EXCLUDED_LANGUAGE_TABS:
        for code in available_languages:
            if code not in tab_languages:
                get['language'] = code
                url = '?{0}'.format(get.urlencode())

                if code == current_language:
                    status = 'current'
                else:
                    status = 'available'

                tabs.append((url, get_language_title(code), code, status))

    tabs.current_is_translated = current_language in available_languages
    tabs.allow_deletion = len(available_languages) > 1
    return tabs
Beispiel #8
0
def get_language_tabs(request, current_language, available_languages, css_class=None):
    """
    Determine the language tabs to show.
    """
    tabs = TabsList(css_class=css_class)
    get = request.GET.copy()  # QueryDict object
    tab_languages = []

    base_url = '{0}://{1}{2}'.format(request.is_secure() and 'https' or 'http', request.get_host(), request.path)

    site_id = getattr(settings, 'SITE_ID', None)
    for lang_dict in appsettings.PARLER_LANGUAGES.get(site_id, ()):
        code = lang_dict['code']
        title = get_language_title(code)
        get['language'] = code
        url = '{0}?{1}'.format(base_url, get.urlencode())

        if code == current_language:
            status = 'current'
        elif code in available_languages:
            status = 'available'
        else:
            status = 'empty'

        tabs.append((url, title, code, status))
        tab_languages.append(code)

    # Additional stale translations in the database?
    if appsettings.PARLER_SHOW_EXCLUDED_LANGUAGE_TABS:
        for code in available_languages:
            if code not in tab_languages:
                get['language'] = code
                url = '{0}?{1}'.format(base_url, get.urlencode())

                if code == current_language:
                    status = 'current'
                else:
                    status = 'available'

                tabs.append((url, get_language_title(code), code, status))

    tabs.current_is_translated = current_language in available_languages
    tabs.allow_deletion = len(available_languages) > 1
    return tabs
Beispiel #9
0
 def clean(self):
     if self.critical_incident.public is False:
         raise ValidationError(_("The reporter did not agreed to publish this incident!"))
     if self.publish is True:
         languages =  ", ".join(
             [unicode(get_language_title(lang)) for lang in self.mandatory_languages])
         missing_message = _(
             "All text fields in mandatory languages (%s) has to be filled before 'publish' can be checked!") % languages
         if self.translation_status == 'incomplete':
             raise ValidationError({'publish': missing_message})
Beispiel #10
0
 def clean(self):
     # TODO: show all error messages if multiple validation errors occur at the same time?
     if self.send_notification is True:
         if (settings.EMAIL_HOST == '' or settings.EMAIL_HOST == 'localhost'):
             raise ValidationError(self.EMAIL_HOST_ERROR)
         if self.notification_recipients.all().count() == 0:
             raise ValidationError(_('You have to choose at least one notification recipient.'))
         if self.notification_sender_email == '':
             raise ValidationError(_('You have to enter valid sender email.'))
     # default language
     default_lang = settings.PARLER_DEFAULT_LANGUAGE_CODE
     verbose_lang = unicode(get_language_title(default_lang))
     if default_lang not in self.mandatory_languages:
         raise ValidationError(
             _('You have to reactivate %s as it is default language.') % verbose_lang)
    def __str__(self):
        # Note this representation is optimized for the admin delete page.
        # Make sure that the
        try:
            real_type = ContentType.objects.get_for_id(self.polymorphic_ctype_id).model_class()
        except ContentType.DoesNotExist:
            real_type_text = "(type deleted)"
        else:
            if real_type is None:
                real_type_text = "(type deleted)"
            else:
                real_type_text = "(type deleted)"

        return u"'{type} {id:d}' in '{language} {placeholder}'".format(
            type=real_type_text,
            id=self.id or 0,
            language=get_language_title(self.language_code) if self.language_code else None,
            placeholder=self.placeholder
        )
Beispiel #12
0
    def __str__(self):
        # Note this representation is optimized for the admin delete page.
        # Make sure that the
        try:
            real_type = ContentType.objects.get_for_id(self.polymorphic_ctype_id).model_class()
        except ContentType.DoesNotExist:
            real_type_text = "(type deleted)"
        else:
            if real_type is None:
                real_type_text = "(type deleted)"
            else:
                real_type_text = "(type deleted)"

        return u"'{type} {id:d}' in '{language} {placeholder}'".format(
            type=real_type_text,
            id=self.id or 0,
            language=get_language_title(self.language_code) if self.language_code else None,
            placeholder=self.placeholder
        )
Beispiel #13
0
 def __str__(self):
     return u"{0}: {1}".format(get_language_title(self.language_code),
                               self.title)
Beispiel #14
0
 def __unicode__(self):
     return u"{0}: {1}".format(get_language_title(self.language_code), self.title)