예제 #1
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)
예제 #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('<taggy>good</taggy>') != -1)
        assert (data.index('<taggy>ugly</taggy>') != -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('<taggy>bad</taggy>') != -1)
예제 #3
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("<taggy>good</taggy>") != -1
        assert data.index("<taggy>ugly</taggy>") != -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("<taggy>bad</taggy>") != -1
예제 #4
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)
예제 #5
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
        )
예제 #6
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)
예제 #7
0
def createquote(request, risk_id):

    r = get_object_or_404(Risk, pk=risk_id)

    ratingxml = xml(r)
    # ratingjson = serializers.serialize('json', Risk.objects.all(), indent=4, relations={'vehicle':{'relations':('vehicleaddress')}, 'maindriver'})
    # ratingjson = serializers.serialize('json', Risk.objects.filter(pk=risk_id), indent=4, relations=('Vehicle', 'maindriver', 'Quote', 'Policy'))

    p_year = float(random.randint(50000, 99999)) / 100
    p_month = Decimal(float(p_year / 12 * 1.05)).quantize(Decimal(".01"), rounding=ROUND_HALF_UP)

    return render_to_response(
        "commercialvehicle/quote.html",
        {"ratingxml": ratingxml, "yearly": p_year, "monthly": p_month},
        context_instance=RequestContext(request),
    )
예제 #8
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.xml.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 = xmltree.xml(object)

    result = transform(xml, str(xsl_path), params)
    return result
예제 #9
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.xml.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 = xmltree.xml(object)
    
    result = transform(xml, str(xsl_path), params)
    return result
예제 #10
0
def createquote(request, risk_id):

    r = get_object_or_404(Risk, pk=risk_id)

    ratingxml = xml(r)
    #ratingjson = serializers.serialize('json', Risk.objects.all(), indent=4, relations={'vehicle':{'relations':('vehicleaddress')}, 'maindriver'})
    #ratingjson = serializers.serialize('json', Risk.objects.filter(pk=risk_id), indent=4, relations=('Vehicle', 'maindriver', 'Quote', 'Policy'))

    p_year = float(random.randint(50000, 99999)) / 100
    p_month = Decimal(float(p_year / 12 * 1.05)).quantize(
        Decimal('.01'), rounding=ROUND_HALF_UP)

    return render_to_response('commercialvehicle/quote.html', {
        'ratingxml': ratingxml,
        'yearly': p_year,
        'monthly': p_month
    },
                              context_instance=RequestContext(request))
예제 #11
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.xml.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 = xmltree.xml(object)
    
    result = transform(xml, str(xsl_path), params)
    return HttpResponse(result, mimetype=mimetype)
예제 #12
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.xml.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 = xmltree.xml(object)

    result = transform(xml, str(xsl_path), params)
    return HttpResponse(result, mimetype=mimetype)
예제 #13
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)))
예제 #14
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
예제 #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)))
예제 #16
0
def raw(request):
    """shows untransformed hierarchical xml output"""
    foos = foobar_models.Foo.objects.all()
    return HttpResponse(tree.xml(foos), mimetype='text/xml')
예제 #17
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)
예제 #18
0
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')
예제 #19
0
def raw(request):
    """shows untransformed hierarchical xml output"""
    foos = foobar_models.Foo.objects.all()
    return HttpResponse(tree.xml(foos), mimetype='text/xml')
예제 #20
0
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')