コード例 #1
0
ファイル: testi18n.py プロジェクト: alexanbj/viktigpedia
    def test_translated_fields_handle_correctly_under_to_xml(self):
        """A field that is translated should show the correct value when converted to xml"""

        i = self.setup_l10n_model()

        poentry = polib.POEntry(msgid=u'Ik ben de groot moeftie van cambodja', msgstr=u'Ik ben een zwerver')        
        self.setup_mofile_with_entry(poentry, 'de')

        xml_representation = tree.xml(i)

        # todo:
        # DefaultFieldDescriptor is now serialized as a charfield type.
        # add the different serializable types to the xslt and the test should be able
        # to verify the correct workings then.
        # contains_default_field_descriptor = re.search(r'DefaultFieldDescriptor', xml_representation)
        # self.assertTrue(contains_default_field_descriptor)
        
        contains_moeftie = re.search(r'Ik ben de groot moeftie van cambodja', xml_representation)
        contains_konijntje = contains_konijntje = re.search(r'Ik ben een konijntje', xml_representation)        
        self.assertTrue(contains_moeftie)
        self.assertFalse(contains_konijntje)

        translation.activate('de')
        i.title = u'Ik ben een duits konijntje'
        xml_representation = tree.xml(i)
        contains_konijntje = re.search(r'Ik ben een duits konijntje', xml_representation)
        self.assertTrue(contains_konijntje)

        i.title_de = u'Ik ben geen konijntje'
        i.save()

        xml_representation = tree.xml(i)
        contains_konijntje = re.search(r'Ik ben geen konijntje', xml_representation)
        self.assertTrue(contains_konijntje)
コード例 #2
0
 def test_many_to_many_field(self):
     "ManyToManyField should be followed in one direction, like foreign keys"
     
     data = tree.xml(TestModel.objects.all())
     assert(data.index('<field type="CharField" name="value">good</field>')!= -1)
     assert(data.index('<field type="CharField" name="value">ugly</field>')!= -1)
     
     bad_tag = TagModel.objects.get(value_en='bad')
     first_item = TestModel.objects.get(pk=1)
     first_item.tags.add(bad_tag)
     first_item.save()
     data = tree.xml(TestModel.objects.all())
     assert(data.index('<field type="CharField" name="value">bad</field>')!= -1)
コード例 #3
0
    def test_diocore_fields_are_special(self):
        """Diocore fields should have a font attribute after serialization"""
        i = TestL10nModel.objects.get(pk=1)
        xml = tree.xml(i)

        title_has_font = re.search(r'field font="arial" type="CharField" name="title"', xml)
        body_has_font = re.search(r'field font="arial" type="TextField" name="body"', xml)

        self.assertTrue(title_has_font)
        self.assertTrue(body_has_font)
コード例 #4
0
    def test_diocore_fields_are_special(self):
        """Diocore fields should have a font attribute after serialization"""
        i = TestL10nModel.objects.get(pk=1)
        xml = tree.xml(i)

        title_has_font = re.search(
            r'field font="arial" type="CharField" name="title"', xml)
        body_has_font = re.search(
            r'field font="arial" type="TextField" name="body"', xml)

        self.assertTrue(title_has_font)
        self.assertTrue(body_has_font)
コード例 #5
0
    def test_translated_fields_handle_correctly_under_to_xml(self):
        """A field that is translated should show the correct value when converted to xml"""

        i = self.setup_l10n_model()

        poentry = polib.POEntry(msgid=u'Ik ben de groot moeftie van cambodja',
                                msgstr=u'Ik ben een zwerver')
        self.setup_mofile_with_entry(poentry, 'de')

        xml_representation = tree.xml(i)

        # todo:
        # DefaultFieldDescriptor is now serialized as a charfield type.
        # add the different serializable types to the xslt and the test should be able
        # to verify the correct workings then.
        # contains_default_field_descriptor = re.search(r'DefaultFieldDescriptor', xml_representation)
        # self.assertTrue(contains_default_field_descriptor)

        contains_moeftie = re.search(r'Ik ben de groot moeftie van cambodja',
                                     xml_representation)
        contains_konijntje = contains_konijntje = re.search(
            r'Ik ben een konijntje', xml_representation)
        self.assertTrue(contains_moeftie)
        self.assertFalse(contains_konijntje)

        translation.activate('de')
        i.title = u'Ik ben een duits konijntje'
        xml_representation = tree.xml(i)
        contains_konijntje = re.search(r'Ik ben een duits konijntje',
                                       xml_representation)
        self.assertTrue(contains_konijntje)

        i.title_de = u'Ik ben geen konijntje'
        i.save()

        xml_representation = tree.xml(i)
        contains_konijntje = re.search(r'Ik ben geen konijntje',
                                       xml_representation)
        self.assertTrue(contains_konijntje)
コード例 #6
0
ファイル: response.py プロジェクト: alexanbj/viktigpedia
def render_to_string(template, object, params=None):
    """
    ``object`` will be converted to xml using :func:`easymode.tree.xml`. The resulting xml 
    will be transformed using ``template``.
    The result is a unicode string containing the transformed xml.
    
    :param template: an xslt template name.
    :param object: an object that has an ``__xml__`` method. (See :func:`easymode.tree.decorators.toxml`).
    :param params: A dictionary containing xslt parameters. Use :func:`~easymode.xslt.prepare_string_param`\
        on strings you want to pass in.
    :rtype: :class:`unicode`
    """
    xsl_path = find_template_path(template)
    xml = tree.xml(object)
    
    result = transform(xml, str(xsl_path), params)
    return result
コード例 #7
0
def render_to_string(template, object, params=None):
    """
    ``object`` will be converted to xml using :func:`easymode.tree.xml`. The resulting xml 
    will be transformed using ``template``.
    The result is a unicode string containing the transformed xml.
    
    :param template: an xslt template name.
    :param object: an object that has an ``__xml__`` method. (See :func:`easymode.tree.decorators.toxml`).
    :param params: A dictionary containing xslt parameters. Use :func:`~easymode.xslt.prepare_string_param`\
        on strings you want to pass in.
    :rtype: :class:`unicode`
    """
    xsl_path = find_template_path(template)
    xml = tree.xml(object)

    result = transform(xml, str(xsl_path), params)
    return result
コード例 #8
0
ファイル: response.py プロジェクト: alexanbj/viktigpedia
def render_to_response(template, object, params=None, mimetype='text/html'):
    """
    ``object`` will be converted to xml using :func:`easymode.tree.xml`. The resulting xml 
    will be transformed using ``template``.
    The result will be a :class:`~django.http.HttpResponse` object,
    containing the transformed xml as the body.
    
    :param template: an xslt template name.
    :param object: an object that has an ``__xml__`` method. (See :func:`easymode.tree.decorators.toxml`).
    :param params: A dictionary containing xslt parameters. Use :func:`~easymode.xslt.prepare_string_param`\
        on strings you want to pass in.
    :param mimetype: The mimetype of the :class:`~django.http.HttpResponse`
    :rtype: :class:`django.http.HttpResponse`
    """
    xsl_path = find_template_path(template)
    xml = tree.xml(object)
    
    result = transform(xml, str(xsl_path), params)
    return HttpResponse(result, mimetype=mimetype)
コード例 #9
0
def render_to_response(template, object, params=None, mimetype='text/html'):
    """
    ``object`` will be converted to xml using :func:`easymode.tree.xml`. The resulting xml 
    will be transformed using ``template``.
    The result will be a :class:`~django.http.HttpResponse` object,
    containing the transformed xml as the body.
    
    :param template: an xslt template name.
    :param object: an object that has an ``__xml__`` method. (See :func:`easymode.tree.decorators.toxml`).
    :param params: A dictionary containing xslt parameters. Use :func:`~easymode.xslt.prepare_string_param`\
        on strings you want to pass in.
    :param mimetype: The mimetype of the :class:`~django.http.HttpResponse`
    :rtype: :class:`django.http.HttpResponse`
    """
    xsl_path = find_template_path(template)
    xml = tree.xml(object)

    result = transform(xml, str(xsl_path), params)
    return HttpResponse(result, mimetype=mimetype)
コード例 #10
0
 def test_natural_keys(self):
     "natural keys will show up in the xml"
     
     xml_with_natural_keys = tree.xml(TestModel.objects.all())
     assert(xml_with_natural_keys.find('<natural>In lectus est, viverra a, ultricies ut, pulvinar vitae, tellus.</natural>') != -1)
コード例 #11
0
 def test_model_to_xml_with_xml_function(self):
     """test the xml function in package tree"""
     xml = tree.xml(TestModel.objects.get(pk=1))
     assert( md5(xml).hexdigest() == CONFIRMED_XML_DIGEST)
コード例 #12
0
ファイル: views.py プロジェクト: aronchi/django-easymode
def chain(request):
    """shows how the XmlQuerySetChain can be used instead of @toxml decorator"""
    bars = foobar_models.Bar.objects.all()
    bazs = foobar_models.Baz.objects.all()
    qsc = XmlQuerySetChain(bars, bazs)
    return HttpResponse(tree.xml(qsc), mimetype='text/xml')
コード例 #13
0
ファイル: views.py プロジェクト: aronchi/django-easymode
def raw(request):
    """shows untransformed hierarchical xml output"""
    foos = foobar_models.Foo.objects.all()
    return HttpResponse(tree.xml(foos), mimetype='text/xml')
コード例 #14
0
 def test_xslt_changes_the_xml(self):
     """docstring for test_xslt_changes_the_xml"""
     data = TestModel.objects.get(pk=1)
     resp = response.render_to_response('xslt/model-to-xml.xsl', data)
     assert(resp != HttpResponse(tree.xml(data)))
コード例 #15
0
 def test_xslt_changes_the_xml(self):
     """docstring for test_xslt_changes_the_xml"""
     data = TestModel.objects.get(pk=1)
     resp = response.render_to_response("xslt/model-to-xml.xsl", data)
     assert resp != HttpResponse(tree.xml(data))