__init__.py 1.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
import re
import django.dispatch
from forum.modules import get_modules_script_classes
from forum.authentication.base import AuthenticationConsumer, ConsumerTemplateContext

class ConsumerAndContext:
    def __init__(self, id, consumer, context):
        self.id = id
        self._consumer = consumer

        if context:
            context.id = id
        self.context = context

    @property
    def consumer(self):
        return self._consumer()

consumers = dict([
            (re.sub('AuthConsumer$', '', name).lower(), cls) for name, cls
            in get_modules_script_classes('authentication', AuthenticationConsumer).items()
            if not re.search('AbstractAuthConsumer$', name)
        ])

contexts = dict([
            (re.sub('AuthContext$', '', name).lower(), cls) for name, cls
            in get_modules_script_classes('authentication', ConsumerTemplateContext).items()
        ])

AUTH_PROVIDERS = dict([
            (name, ConsumerAndContext(name, consumers[name], contexts.get(name, None))) for name in consumers.keys()
        ])