Permalink
Browse files

Now hopefully 100% working

  • Loading branch information...
1 parent b9f5138 commit 0a7529eed6e177b84c6b1701c5af71937309b9a6 @akaariai committed Dec 4, 2011
Showing with 17 additions and 7 deletions.
  1. +16 −7 astmodel/astmodel.py
  2. +1 −0 tester.py
View
@@ -14,13 +14,17 @@ def __init__(self, *args, **kwargs):
try:
self._asted_init(*args, **kwargs)
except AttributeError:
- for field in self._meta.fields:
+ for field in self._meta.fields + self._meta.virtual_fields:
if (isinstance(field, GenericForeignKey)
- or isinstance(field, ImageField)):
+ or isinstance(field, ImageField)):
self.send_init_signals = True
new_init = self._create_ast_init()
self.__class__._asted_init = new_init
- # Lets see if we can use a fast-path?
+
+ # Lets see if we can use a fast-path, that is, we
+ # do not need to visit this proxy __init__ again.
+ # If there is no overriding __init__ in the class
+ # hierarchy, we are good to go.
if self.__class__.__init__ == ASTModel.__init__:
self.__class__.__init__ = new_init
self._asted_init(*args, **kwargs)
@@ -92,7 +96,6 @@ def _create_ast_init(self):
return init_context['__init__']
-
class RewriteInit(ast.NodeTransformer):
def __init__(self, new_if_body, len_fields, send_init_signals):
self.new_if_body = new_if_body
@@ -101,9 +104,15 @@ def __init__(self, new_if_body, len_fields, send_init_signals):
def visit_If(self, node):
try:
- if (not self.send_init_signals and hasattr(node.test, 'attr')
- and node.test.attr == 'send_init_signals'):
- return None
+ # Rewrite the init signal sending into:
+ # - Nothing, if we are not sending signals
+ # - pre/post_init.send() if we are sending signals
+ if (hasattr(node.test, 'attr')
+ and node.test.attr == 'send_init_signals'):
+ if self.send_init_signals:
+ return node.body
+ else:
+ return None
if (hasattr(node.test, 'comparators')
and hasattr(node.test.comparators[0], 'n')
and node.test.comparators[0].n == -999):
View
@@ -7,6 +7,7 @@
@commit_on_success
def create_data(count):
+ print "deleting / creating test data"
while Foo10.objects.count() > 0:
Foo10.objects.filter(pk__in=Foo10.objects.all()[0:500]).delete()
for i in range(0, count):

0 comments on commit 0a7529e

Please sign in to comment.