def test05_lock(self):
     languages.lock('en')
     self.assertEqual(languages.is_locked(), True)
     self.assertEqual(languages.get_active(), 'en')
     languages.release()
     self.assertEqual(languages.is_locked(), False)
     self.assertEqual(languages.get_active(), 'cs')
    def test_lock(self):
        activate('en')
        self.assertFalse(languages.is_locked())
        self.assertEqual(languages.get_active(), 'en')

        languages.lock('fr')

        self.assertTrue(languages.is_locked())
        self.assertEqual(languages.get_active(), 'fr')

        languages.release()

        self.assertFalse(languages.is_locked())
        self.assertEqual(languages.get_active(), 'en')
예제 #3
0
        def query_from_untranslated_model():
            lock('en')
            try:
                # Use prefetch_related; start the query from an untranslated model
                qs = Untranslated.objects\
                    .select_related('basic')\
                    .prefetch_related('basic__translations')

                self.assertEqual(
                    ','.join(
                        '%s %s' % (u.name, u.basic.title) for u in qs
                    ),
                    'u1 content,u2 only english'
                )
            finally:
                release()
예제 #4
0
    def render(self, context):
        # If language_code is string, strip quotes
        # otherwise resolve variable
        if self.language_code[0] == self.language_code[-1] and self.language_code[0] in ('"',"'"):
            language_code = self.language_code[1:-1]
        else:
            # Do not catch VariableDoesNotExist exception
            language_code = template.Variable(self.language_code).resolve(context)

        # Lock language, store code into context, render, restore context and release lock
        languages.lock(language_code)
        context.push()
        context[self.varname] = languages.get_active()
        output = self.nodelist.render(context)
        context.pop()
        languages.release()
        return output
예제 #5
0
    def change_view(self, request, object_id, extra_context=None):
        """
        Lock language over change_view and add extra_context
        """
        try:
            lock(request.POST.get("language", request.GET.get("language", get_active())))

            model = self.model
            opts = model._meta
            context = {
                "title": _("Add %s for language %s")
                % (force_unicode(opts.verbose_name), force_unicode(get_dict()[get_active()]))
            }
            context.update(extra_context or {})
            return super(MultilingualModelAdmin, self).change_view(request, object_id, context)
        finally:
            release()
예제 #6
0
    def add_view(self, request, form_url='', extra_context=None):
        """
        Lock language over 'add' view and update context.
        """
        try:
            lock(request.POST.get('ml_admin_language', request.GET.get('ml_admin_language', get_active())))

            model = self.model
            opts = model._meta
            context = {
                'title': _('Add %s for language %s') % (
                    force_unicode(opts.verbose_name),
                    force_unicode(get_dict()[get_active()])
                ),
            }
            context.update(extra_context or {})
            return super(MultilingualModelAdmin, self).add_view(request, form_url=form_url, extra_context=context)
        finally:
            release()
예제 #7
0
    def test03_proxy_fields_fallbacks(self):
        # Test proxy fields reading
        obj = Basic.objects.get(pk=2)
        self.assertEqual(obj.title, u'pouze čeština')
        self.assertEqual(obj.title_cs, u'pouze čeština')
        self.assertEqual(obj.title_en, None)
        lock('en')
        self.assertEqual(obj.title, u'pouze čeština')
        release()

        obj = Basic.objects.get(pk=3)
        # Do not forget we have activated czech language
        self.assertEqual(obj.title, None)
        self.assertEqual(obj.title_cs, None)
        self.assertEqual(obj.title_en, u'only english')

        obj = Basic.objects.get(pk=4)
        self.assertEqual(obj.title, None)
        self.assertEqual(obj.title_cs, None)
        self.assertEqual(obj.title_en, None)
    def change_view(self, request, object_id, **kwargs):
        """
        Lock language over change_view and add extra_context
        """
        # In Django 1.4 number of arguments have changed.
        extra_context = kwargs.get('extra_context')
        try:
            lock(request.POST.get('language', request.GET.get('language', get_active())))

            model = self.model
            opts = model._meta
            context = {
                'title': _('Change %s for language %s') % (
                    force_unicode(opts.verbose_name),
                    force_unicode(get_dict()[get_active()])
                ),
            }
            context.update(extra_context or {})
            kwargs['extra_context'] = context
            return super(MultilingualModelAdmin, self).change_view(request, object_id, **kwargs)
        finally:
            release()
예제 #9
0
	def wrapped(cls, request, *args, **kwargs):
		lock(request.POST.get('language', request.GET.get('language', get_active())))
		resp = func(cls, request, *args, **kwargs)
		release()
		return resp
예제 #10
0
 def tearDown(self):
     deactivate_all()
     release()
예제 #11
0
 def tearDown(self):
     # Remove language locks if any remains
     # TODO: rollback after each test, to get database to the same initial state
     release()
 def tearDown(self):
     # Reset old language
     activate(self.old_language)
     languages.release()
     settings.LANGUAGES = self.old_languages
     settings.LANGUAGE_CODE = self.old_language_code
 def tearDown(self):
     # Reset languages
     deactivate_all()
     languages.release()
예제 #14
0
 def tearDown(self):
     # Remove language locks if any remains
     release()