示例#1
0
    def add_conf_to_pattern(self, pattern, conf, bases):
        """
        Coalesces an Application's configuration with the views in its urlconf.

        Takes a RegexURLPattern or RegexURLResolver, a conf object and a tuple
        of extra base classes to inherit from. Returns an object of the same
        type as its first argument with callbacks replaced with new views using
        conf and bases.
        """

        # Don't import at module scope as this module will be imported from a
        # settings file.
        from molly.utils.views import BaseView

        if isinstance(pattern, RegexURLResolver):
            # Recurse through the patterns
            patterns = []
            for subpattern in pattern.url_patterns:
                patterns.append(
                    self.add_conf_to_pattern(subpattern, conf, bases))
            # Create a new RegexURLResolver with the new patterns
            return RegexURLResolver(
                pattern.regex.pattern,  # The regex pattern string
                patterns,
                pattern.default_kwargs,
                pattern.app_name,
                pattern.namespace)
        elif isinstance(pattern, RegexURLPattern):
            # Get the callback and make sure it derives BaseView
            callback = pattern.callback
            if not issubclass(callback, BaseView):
                return callback

            if bases:
                # Create a new callback with the extra bases
                callback = type(callback.__name__ + 'Extended',
                                (callback, ) + bases, {})
                callback.__module__ = pattern.callback.__module__

            # Instantiate the callback with the conf object
            callback = callback(conf)

            # Transplant this new callback into a new RegexURLPattern, keeping
            # the same regex, default_args and name.
            return RegexURLPattern(pattern.regex.pattern, callback,
                                   pattern.default_args, pattern.name)
        else:
            raise TypeError(
                "Expected RegexURLResolver or RegexURLPattern instance, got %r."
                % type(pattern))
示例#2
0
def make_urlpatterns():
    patterns = []
    for app in models.get_apps():
        if hasattr(app, 'PAYMENT_PROCESSOR'):
            parts = app.__name__.split('.')
            key = parts[-2].upper()
            modulename = 'PAYMENT_%s' % key
            name = app.__name__
            name = name[:name.rfind('.')]
            #log.debug('payment module=%s, key=%s', modulename, key)
            # BJK: commenting out Bursar settings here
            # try:
            #     cfg = config_get(modulename, 'INTERFACE_MODULE')
            #     interface = cfg.editor_value
            # except SettingNotSet:
            #     interface = name[:name.rfind('.')]
            # urlmodule = "%s.urls" % interface
            urlmodule = '.'.join(parts[:-1]) + '.urls'
            urlbase = config_value(modulename, 'URL_BASE')
            log.debug('Found payment processor: %s, adding urls at %s', key, urlbase)
            patterns.append(url(urlbase, [urlmodule, '', '']))
    return tuple(patterns)