Skip to content

Commit 6e97c2c

Browse files
committed
Merged in the port from Django 1.2 to Django 1.6 from olau@iola.dk: branch/iola/djangoport@7121, and fixed some merge issues.
- Legacy-Id: 7152
2 parents 9417351 + 7e00fa1 commit 6e97c2c

4,464 files changed

Lines changed: 367248 additions & 362464 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.

changelog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
ietfdb (4.95) ietf; urgency=medium
2+
3+
This release upgrades Django from version 1.2 to version 1.6, including a
4+
large number of refactorings and adjustments (about 140 individual changes)
5+
to adapt to changes in both interfaces and the style of how things are done
6+
between Django 1.2 and 1.6. The full list of changes is available here:
7+
8+
http://tools.ietf.org/tools/ietfdb/log/branch/iola/djangoport
9+
10+
-- Henrik Levkowetz <henrik@levkowetz.com> 13 Jan 2014 19:14:05 +0100
11+
112
ietfdb (4.90) ietf; urgency=medium
213

314
This release removes almost all parts of the shim-layer code which was

dajaxice/__init__.py

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

dajaxice/core/Dajaxice.py

Lines changed: 81 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,165 +1,116 @@
1-
#import logging
1+
import logging
22

3-
from django.conf import settings
3+
from django.utils.importlib import import_module
44

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
5+
log = logging.getLogger('dajaxice')
226

237

248
class DajaxiceFunction(object):
9+
""" Basic representation of a dajaxice ajax function."""
2510

26-
def __init__(self, name, path, doc=None):
11+
def __init__(self, function, name, method):
12+
self.function = function
2713
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)
14+
self.method = method
3315

34-
def __cmp__(self, other):
35-
return (self.name == other.name and self.path == other.path)
16+
def call(self, *args, **kwargs):
17+
""" Call the function. """
18+
return self.function(*args, **kwargs)
3619

3720

3821
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)
22+
""" Basic representation of a dajaxice module. """
6223

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
24+
def __init__(self, name=None):
25+
self.name = name
26+
self.functions = {}
27+
self.submodules = {}
28+
29+
def add(self, name, function):
30+
""" Add this function at the ``name`` deep. If the submodule already
31+
exists, recusively call the add method into the submodule. If not,
32+
create the module and call the add method."""
33+
34+
# If this is not the final function name (there are more modules)
35+
# split the name again an register a new submodule.
36+
if '.' in name:
37+
module, extra = name.split('.', 1)
38+
if module not in self.submodules:
39+
self.submodules[module] = DajaxiceModule(module)
40+
self.submodules[module].add(extra, function)
7241
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
42+
self.functions[name] = function
8843

8944

9045
class Dajaxice(object):
91-
def __init__(self):
92-
self._registry = []
93-
self._callable = []
9446

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__)
47+
def __init__(self):
48+
self._registry = {}
49+
self._modules = None
10150

102-
def register_function(self, module, name, doc=None):
51+
def register(self, function, name=None, method='POST'):
10352
"""
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)
53+
Register this function as a dajaxice function.
11654
117-
#Dajaxice path without ajax.
118-
module_without_ajax = module.replace('.ajax', '').split('.')
55+
If no name is provided, the module and the function name will be used.
56+
The final (customized or not) must be unique. """
11957

120-
#Register module if necessary.
121-
exist_module = self._exist_module(module_without_ajax[0])
58+
method = self.clean_method(method)
12259

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
60+
# Generate a default name
61+
if not name:
62+
module = ''.join(str(function.__module__).rsplit('.ajax', 1))
63+
name = '.'.join((module, function.__name__))
14464

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
65+
if ':' in name:
66+
log.error('Ivalid function name %s.' % name)
67+
return
15068

151-
def get_functions(self):
152-
return self._registry
69+
# Check for already registered functions
70+
if name in self._registry:
71+
log.error('%s was already registered.' % name)
72+
return
15373

74+
# Create the dajaxice function.
75+
function = DajaxiceFunction(function=function,
76+
name=name,
77+
method=method)
78+
79+
# Register this new ajax function
80+
self._registry[name] = function
81+
82+
def is_callable(self, name, method):
83+
""" Return if the function callable or not. """
84+
return name in self._registry and self._registry[name].method == method
85+
86+
def clean_method(self, method):
87+
""" Clean the http method. """
88+
method = method.upper()
89+
if method not in ['GET', 'POST']:
90+
method = 'POST'
91+
return method
92+
93+
def get(self, name):
94+
""" Return the dajaxice function."""
95+
return self._registry[name]
96+
97+
@property
98+
def modules(self):
99+
""" Return an easy to loop module hierarchy with all the functions."""
100+
if not self._modules:
101+
self._modules = DajaxiceModule()
102+
for name, function in self._registry.items():
103+
self._modules.add(name, function)
104+
return self._modules
154105

155106
LOADING_DAJAXICE = False
156107

157108

158109
def dajaxice_autodiscover():
159110
"""
160111
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
112+
not present. NOTE: dajaxice_autodiscover was inspired/copied from
113+
django.contrib.admin autodiscover
163114
"""
164115
global LOADING_DAJAXICE
165116
if LOADING_DAJAXICE:

0 commit comments

Comments
 (0)