Exemple #1
0
 def wrapped(cls, request, *args, **kwargs):
     cls.use_language = request.GET.get(
         'lang', request.GET.get('language', get_default_language()))
     GLL.lock(cls.use_language)
     resp = func(cls, request, *args, **kwargs)
     GLL.release()
     return resp
    def test_11_inline_admin(self):
        """Test admin with inlines"""
        username = '******'
        password = '******'
        email = '*****@*****.**'
        User.objects.create_superuser(username, email, password)
        c = Client()
        self.assertEqual(c.login(username=username, password=password), True)
        r = c.get('/admin/testproject/multimodel2/1/')
        self.assertEquals(r.status_code, 200)

        en_field = "relation_en"
        mm = MultiModel2.objects.create(field1="abcd", field2="default language")
        GLL.lock('en')
        mm.field2 = "en"
        mm.multiinlinemodel_set.create(field1=en_field)
        mm.save()
        GLL.release()

        jp_field = "relation_jp"
        GLL.lock('jp')
        mm.field2 = "jp"
        mm.multiinlinemodel_set.create(field1=jp_field)
        mm.save()
        GLL.release()

        r = c.get('/admin/testproject/multimodel2/%d/' % mm.pk, {"language":"en"})
        self.assertEquals(r.status_code, 200)
        self.assertTrue('value="%s"'%en_field in r.content)
        self.assertFalse('value="%s"'%jp_field in r.content)
 def render(self, context):
     if self.language_code[0] == self.language_code[-1] and self.language_code[0] in ('"',"'"):
         language_code = self.language_code[1:-1]
     else:
         language_code = template.Variable(self.language_code).resolve(context) 
     GLL.lock(language_code)
     output = self.nodelist.render(context)
     GLL.release()
     return output
 def test_02_gll(self):
     mfp = MultilingualFlatPage.objects.get(url='/test2/')
     GLL.lock('en')
     self.assertEqual(mfp.title, None)
     self.assertEqual(mfp.content, None)
     GLL.release()
     GLL.lock('ja')
     self.assertEqual(mfp.title, 'MLFP-Title2-ja')
     self.assertEqual(mfp.content, 'MLFP-Content2-ja')
     GLL.release()
Exemple #5
0
 def test_02_gll(self):
     mfp = MultilingualFlatPage.objects.get(url='/test2/')
     GLL.lock('en')
     self.assertEqual(mfp.title, None)
     self.assertEqual(mfp.content, None)
     GLL.release()
     GLL.lock('ja')
     self.assertEqual(mfp.title, 'MLFP-Title2-ja')
     self.assertEqual(mfp.content, 'MLFP-Content2-ja')
     GLL.release()
 def render(self, context):
     if self.language_code[0] == self.language_code[
             -1] and self.language_code[0] in ('"', "'"):
         language_code = self.language_code[1:-1]
     else:
         language_code = template.Variable(
             self.language_code).resolve(context)
     GLL.lock(language_code)
     output = self.nodelist.render(context)
     GLL.release()
     return output
Exemple #7
0
def question_detail(request, slug, template_name='faq/question_detail.html', extra_context={}):
    """
    Displays an individual question.
    
    """
    # doesn't make sense that I need to do this
    from multilingual.utils import GLL
    GLL.lock(request.LANGUAGE_CODE)

    return object_detail(
        request,
        template_name = template_name,
        extra_context = extra_context,
        slug = slug,
        slug_field = 'slug',
        queryset = Question.objects.active(user=request.user),
    )    
Exemple #8
0
def question_list( request, template_name='faq/question_list.html',
					extra_context={}, slug=None, group=False):
    '''
    Displays a list of all the questions.
    '''
    
    # NOTE:
    # The code shown here is NOT REALLY NEEDED, but it is a good example
    # of extending an app using extra_content and such.
    # Specifically note how we set the dict value and then allow the user
    # to pass along their own additional extra_context using 'update'.

    kwargs = {'group': group, 'user': request.user}
    if slug:
        topic = Topic.objects.get(slug=slug)
        kwargs.update({'topic': topic})
    query_set = Question.objects.active(**kwargs)
    
    if len(query_set) == 0:
	raise Http404()

    last_update = query_set.values('updated_on').order_by('-updated_on',)[0]    
    extra = { 'updated_on': last_update['updated_on'] }
 
    extra.update( extra_context )
    
    from multilingual.utils import GLL
    GLL.lock(request.LANGUAGE_CODE)

    resp = object_list(
        request,
        template_name = template_name,
        extra_context = extra,
        queryset = query_set
    )
    GLL.release()
    return resp
 def wrapped(cls, request, *args, **kwargs):
     cls.use_language = request.GET.get('lang', request.GET.get('language', get_default_language()))
     GLL.lock(cls.use_language)
     resp = func(cls, request, *args, **kwargs)
     GLL.release()
     return resp