Ejemplo n.º 1
0
    def handle_m2m_field(self, obj, field):
        """
        while easymode follows inverse relations for foreign keys,
        for manytomayfields it follows the forward relation.
        
        While easymode excludes all relations to "self" you could
        still create a loop if you add one extra level of indirection.
        """

        if field.rel.through._meta.auto_created:  #  and obj.__class__ is not field.rel.to:
            # keep approximate recursion level
            with recursion_depth('handle_m2m_field') as recursion_level:

                # a stack trace is better than python crashing.
                if recursion_level > getattr(settings, 'RECURSION_LIMIT',
                                             sys.getrecursionlimit() / 10):
                    raise Exception(MANY_TO_MANY_RECURSION_LIMIT_ERROR %
                                    (field.name, obj.__class__.__name__,
                                     field.rel.to.__name__))

                self._start_relational_field(field)

                s = RecursiveXmlSerializer()
                s.serialize(getattr(obj, field.name).iterator(),
                            xml=self.xml,
                            stream=self.stream)

                self.xml.endElement("field")
Ejemplo n.º 2
0
    def handle_m2m_field(self, obj, field):
        """
        while easymode follows inverse relations for foreign keys,
        for manytomayfields it follows the forward relation.
        
        While easymode excludes all relations to "self" you could
        still create a loop if you add one extra level of indirection.
        """
        
        if field.rel.through._meta.auto_created:#  and obj.__class__ is not field.rel.to:
            # keep approximate recursion level
            with recursion_depth('handle_m2m_field') as recursion_level:
                
                # a stack trace is better than python crashing.
                if recursion_level > getattr(settings, 'RECURSION_LIMIT', sys.getrecursionlimit() / 10):
                    raise Exception(MANY_TO_MANY_RECURSION_LIMIT_ERROR % 
                            (field.name, obj.__class__.__name__, field.rel.to.__name__))

                self._start_relational_field(field)

                s = RecursiveXmlSerializer()
                s.serialize( getattr(obj, field.name).iterator(), xml=self.xml, stream=self.stream)

                self.xml.endElement("field")
Ejemplo n.º 3
0
 def recurse(arr):
     with recursion_depth('test_recursion_depth') as recursion_level:
         if recursion_level > 10:
             raise Exception('error')
         if arr and arr.pop():
             recurse(arr)