Skip to content

Commit 342bc5b

Browse files
committed
Merged in the merge work branch personal/henrik/r6270 which provides the agenda scheduling tool step 3, from a merge of branch/ssw/agenda/v4.70 from mcr@sandelman.ca; and also substantial fixes to the test framework, and more.
- Legacy-Id: 6328
2 parents d2df8ca + 983785d commit 342bc5b

405 files changed

Lines changed: 69723 additions & 1227 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dajaxice/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VERSION = (0, 2, 0, 0, 'beta')

dajaxice/core/Dajaxice.py

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#import logging
2+
3+
from django.conf import settings
4+
5+
# Python 2.7 has an importlib with import_module.
6+
# For older Pythons, Django's bundled copy provides it.
7+
# For older Django's dajaxice reduced_import_module.
8+
try:
9+
from importlib import import_module
10+
except:
11+
try:
12+
from django.utils.importlib import import_module
13+
except:
14+
from dajaxice.utils import simple_import_module as import_module
15+
16+
#log = logging.getLogger('dajaxice.DajaxiceRequest')
17+
import syslog
18+
def warning(msg):
19+
syslog.syslog(syslog.LOG_WANRNING, msg)
20+
log = syslog
21+
log.warning = warning
22+
23+
24+
class DajaxiceFunction(object):
25+
26+
def __init__(self, name, path, doc=None):
27+
self.name = name
28+
self.path = path
29+
self.doc = doc
30+
31+
def get_callable_path(self):
32+
return '%s.%s' % (self.path.replace('.ajax', ''), self.name)
33+
34+
def __cmp__(self, other):
35+
return (self.name == other.name and self.path == other.path)
36+
37+
38+
class DajaxiceModule(object):
39+
def __init__(self, module):
40+
self.functions = []
41+
self.sub_modules = []
42+
self.name = module[0]
43+
44+
sub_module = module[1:]
45+
if len(sub_module) != 0:
46+
self.add_submodule(sub_module)
47+
48+
def get_module(self, module):
49+
"""
50+
Recursively get_module util we found it.
51+
"""
52+
if len(module) == 0:
53+
return self
54+
55+
for dajaxice_module in self.sub_modules:
56+
if dajaxice_module.name == module[0]:
57+
return dajaxice_module.get_module(module[1:])
58+
return None
59+
60+
def add_function(self, function):
61+
self.functions.append(function)
62+
63+
def has_sub_modules(self):
64+
return len(self.sub_modules) > 0
65+
66+
def add_submodule(self, module):
67+
"""
68+
Recursively add_submodule, if it's not registered, create it.
69+
"""
70+
if len(module) == 0:
71+
return
72+
else:
73+
sub_module = self.exist_submodule(module[0])
74+
75+
if type(sub_module) == int:
76+
self.sub_modules[sub_module].add_submodule(module[1:])
77+
else:
78+
self.sub_modules.append(DajaxiceModule(module))
79+
80+
def exist_submodule(self, name):
81+
"""
82+
Check if submodule name was already registered.
83+
"""
84+
for module in self.sub_modules:
85+
if module.name == name:
86+
return self.sub_modules.index(module)
87+
return False
88+
89+
90+
class Dajaxice(object):
91+
def __init__(self):
92+
self._registry = []
93+
self._callable = []
94+
95+
for function in getattr(settings, 'DAJAXICE_FUNCTIONS', ()):
96+
function = function.rsplit('.', 1)
97+
self.register_function(function[0], function[1])
98+
99+
def register(self, function):
100+
self.register_function(function.__module__, function.__name__, function.__doc__)
101+
102+
def register_function(self, module, name, doc=None):
103+
"""
104+
Register function at 'module' depth
105+
"""
106+
#Create the dajaxice function.
107+
function = DajaxiceFunction(name=name, path=module, doc=doc)
108+
109+
#Check for already registered functions.
110+
full_path = '%s.%s' % (module, name)
111+
if full_path in self._callable:
112+
log.warning('%s already registered as dajaxice function.' % full_path)
113+
return
114+
115+
self._callable.append(full_path)
116+
117+
#Dajaxice path without ajax.
118+
module_without_ajax = module.replace('.ajax', '').split('.')
119+
120+
#Register module if necessary.
121+
exist_module = self._exist_module(module_without_ajax[0])
122+
123+
if type(exist_module) == int:
124+
self._registry[exist_module].add_submodule(module_without_ajax[1:])
125+
else:
126+
self._registry.append(DajaxiceModule(module_without_ajax))
127+
128+
#Register Function
129+
module = self.get_module(module_without_ajax)
130+
if module:
131+
module.add_function(function)
132+
133+
def get_module(self, module):
134+
"""
135+
Recursively get module from registry
136+
"""
137+
for dajaxice_module in self._registry:
138+
if dajaxice_module.name == module[0]:
139+
return dajaxice_module.get_module(module[1:])
140+
return None
141+
142+
def is_callable(self, name):
143+
return name in self._callable
144+
145+
def _exist_module(self, module_name):
146+
for module in self._registry:
147+
if module.name == module_name:
148+
return self._registry.index(module)
149+
return False
150+
151+
def get_functions(self):
152+
return self._registry
153+
154+
155+
LOADING_DAJAXICE = False
156+
157+
158+
def dajaxice_autodiscover():
159+
"""
160+
Auto-discover INSTALLED_APPS ajax.py modules and fail silently when
161+
not present.
162+
NOTE: dajaxice_autodiscover was inspired/copied from django.contrib.admin autodiscover
163+
"""
164+
global LOADING_DAJAXICE
165+
if LOADING_DAJAXICE:
166+
return
167+
LOADING_DAJAXICE = True
168+
169+
import imp
170+
from django.conf import settings
171+
172+
for app in settings.INSTALLED_APPS:
173+
174+
try:
175+
app_path = import_module(app).__path__
176+
except AttributeError:
177+
continue
178+
179+
try:
180+
imp.find_module('ajax', app_path)
181+
except ImportError:
182+
continue
183+
184+
import_module("%s.ajax" % app)
185+
186+
LOADING_DAJAXICE = False

0 commit comments

Comments
 (0)