1 | def load_app(self, app_name, can_postpone=False):
|
---|
2 | """
|
---|
3 | Loads the app with the provided fully qualified name, and returns the
|
---|
4 | model module.
|
---|
5 | """
|
---|
6 | self.handled[app_name] = None
|
---|
7 | self.nesting_level += 1
|
---|
8 | try:
|
---|
9 | mod = __import__(app_name, {}, {}, ['models'])
|
---|
10 | except Exception,e:
|
---|
11 | exctype, value, tb = sys.exc_info()
|
---|
12 | import traceback
|
---|
13 | last = traceback.extract_tb(tb)[-1]
|
---|
14 | del tb
|
---|
15 |
|
---|
16 | raise ImportError, "Failed to load models for %s, %s in %s line %s" % (app_name,e.message,last[0],last[1])
|
---|
17 | self.nesting_level -= 1
|
---|
18 | if not hasattr(mod, 'models'):
|
---|
19 | if can_postpone:
|
---|
20 | # Either the app has no models, or the package is still being
|
---|
21 | # imported by Python and the model module isn't available yet.
|
---|
22 | # We will check again once all the recursion has finished (in
|
---|
23 | # populate).
|
---|
24 | self.postponed.append(app_name)
|
---|
25 | return None
|
---|
26 | if mod.models not in self.app_store:
|
---|
27 | self.app_store[mod.models] = len(self.app_store)
|
---|
28 | return mod.models
|
---|
29 |
|
---|