예제 #1
0
def post_delete_language(sender, instance, using, **kwargs):
    """
    **Signal receiver**. Update the supported languages to ensure that 
    a 404 will be raised when requesting the language's urls
    """
    #generate supported languages in case they are not initialized
    utils.get_supported_languages()
    utils._supported.remove(instance.name)
    def process_request(self, request):
        """
        Enable the default language if a supported db language can not
        be resolved.
        """
        #replace the original language detection method
        language = get_language_from_request(
            request, check_path=self.is_language_prefix_patterns_used())
        
        if language not in get_supported_languages():
            language = get_default_language()

        translation.activate(language)        
        request.LANGUAGE_CODE = translation.get_language()
    def process_request(self, request):
        """
        Enable the default language if a supported db language can not
        be resolved.
        """
        #replace the original language detection method
        language = get_language_from_request(
            request, check_path=self.is_language_prefix_patterns_used())

        if language not in get_supported_languages():
            language = get_default_language()

        translation.activate(language)
        request.LANGUAGE_CODE = translation.get_language()
예제 #4
0
    def __init__(self, *args, **kwargs):
        #calculate a queryset that retrieves all non-translated languages
        #for this instance 
        if 'instance' in kwargs and kwargs['instance']:
            #translations.all() is already prefetched, so we iterate over it to avoid the join
            queryset = Language.objects.exclude(
                name__in=[l.language_id for l in kwargs['instance'].translations.all()]).values_list(
                        'name', flat=True)
        else:
            #we do not use get_supported_language as this method
            #might return the default django LANGUAGE setting.
            queryset = Language.objects.values_list('name', flat=True)

        #provide initial data based on untranslated languages
        kwargs['initial'] = [ {'language' : x} for x in queryset]
        #should not allow more inlines than that of the number of languages
        self.max_num = len(get_supported_languages())
        self.extra = len(kwargs['initial']) 

        super(BaseTranslationFormSet, self).__init__(*args, **kwargs)
예제 #5
0
    def __init__(self, *args, **kwargs):
        #calculate a queryset that retrieves all non-translated languages
        #for this instance
        if 'instance' in kwargs and kwargs['instance']:
            #translations.all() is already prefetched, so we iterate over it to avoid the join
            queryset = Language.objects.exclude(name__in=[l.language_id \
                    for l in getattr(kwargs['instance'],
                                     self.translations_property).all()]) \
                               .values_list('name', flat=True)
        else:
            #we do not use get_supported_language as this method
            #might return the default django LANGUAGE setting.
            queryset = Language.objects.values_list('name', flat=True)

        #provide initial data based on untranslated languages
        kwargs['initial'] = [{'language': x} for x in queryset]
        #should not allow more inlines than that of the number of languages
        self.max_num = len(get_supported_languages())
        self.extra = len(kwargs['initial'])

        super(BaseTranslationFormSet, self).__init__(*args, **kwargs)