1. Luke Plant
  2. south

Commits

and...@69d324d9-c39d-4fdc-8679-7745eae9e2c8  committed ddac0e3

Fix the 'datetime doesn't have attribute now' errors people were getting, with a bit more parsing hackery. It hurts.

  • Participants
  • Parent commits fe975f9
  • Branches default

Comments (0)

Files changed (3)

File south/migration.py

View file
  • Ignore whitespace
         migclass = module.Migration
         migclass.orm = FakeORM(migclass, get_app_name(app))
         module._ = lambda x: x  # Fake i18n
+        module.datetime = datetime
         return migclass
     except ImportError:
         print " ! Migration %s:%s probably doesn't exist." % (get_app_name(app), name)

File south/modelsparser.py

View file
  • Ignore whitespace
 import symbol
 import token
 import keyword
+import datetime
 
 from django.db import models
 from django.utils.datastructures import SortedDict
                 # Hm, OK, we got a value. Callables are not frozen (see #132, #135)
                 else:
                     if callable(real_val):
-                        pass
+                        # HACK
+                        # However, if it's datetime.now, etc., that's special
+                        for datetime_key in datetime.datetime.__dict__.keys():
+                            # No, you can't use __dict__.values. It's different.
+                            dtm = getattr(datetime.datetime, datetime_key)
+                            if real_val == dtm:
+                                if not val.startswith("datetime.datetime"):
+                                    defn[2][arg] = "datetime." + val
+                                break
                     else:
                         defn[2][arg] = repr(real_val)
         

File south/orm.py

View file
  • Ignore whitespace
         # And a fake _ function
         fake_locals['_'] = lambda x: x
         
+        # Datetime; there should be no datetime direct accesses
+        fake_locals['datetime'] = datetime
+        
         # Use ModelsLocals to make lookups work right for CapitalisedModels
         fake_locals = ModelsLocals(fake_locals)