コード例 #1
0
ファイル: app.py プロジェクト: yorik-freecad-blog/hellolily
    def patch_forms(self, local_apps):
        """
        Patch all the forms to strip whitespaces from field input.
        """
        def is_form(member):
            """
            Allow only custom made classes which are a subclass from BaseForm to pass.
            """
            if not inspect.isclass(member):
                return False

            if not issubclass(member, BaseForm):
                return False

            return member.__module__.startswith(self.name)

        for app in local_apps:
            try:
                __import__('%s.forms' % app)
            except ImportError:
                continue
            else:
                forms_module = sys.modules['%s.forms' % app]
                form_classes = inspect.getmembers(forms_module, lambda member: is_form(member))

                for form_name, form in form_classes:
                    # Wrap the reference to this form with a function that strips the input from whitespace.
                    if hasattr(form, 'base_fields'):
                        form_class = autostrip(form)
                        setattr(forms_module, form_name, form_class)
コード例 #2
0
ファイル: app.py プロジェクト: noordzij/hellolily
    def ready(self):
        """
        Code run on startup of django.
        """
        # Call atfork because on heroku everything is a fork
        Random.atfork()

        # Patch all the forms to strip whitespace from field input
        local_installed_apps = [
            app for app in settings.INSTALLED_APPS
            if app.startswith('%s.' % __name__)
        ]
        for app in local_installed_apps:
            try:
                __import__('%s.forms' % app)
            except ImportError:
                continue
            else:
                forms_module = sys.modules['%s.forms' % app]
                form_classes = inspect.getmembers(
                    forms_module, lambda member: is_form(member))
                for form_name, form in form_classes:
                    # Wrap the reference to this form with a function that strips the input from whitespace.
                    if hasattr(form, 'base_fields'):
                        form_class = autostrip(form)
                        setattr(forms_module, form_name, form_class)
コード例 #3
0
ファイル: app.py プロジェクト: HelloLily/hellolily
    def patch_forms(self, local_apps):
        """
        Patch all the forms to strip whitespaces from field input.
        """
        def is_form(member):
            """
            Allow only custom made classes which are a subclass from BaseForm to pass.
            """
            if not inspect.isclass(member):
                return False

            if not issubclass(member, BaseForm):
                return False

            return member.__module__.startswith(self.name)

        for app in local_apps:
            try:
                __import__('%s.forms' % app)
            except ImportError:
                continue
            else:
                forms_module = sys.modules['%s.forms' % app]
                form_classes = inspect.getmembers(forms_module, lambda member: is_form(member))

                for form_name, form in form_classes:
                    # Wrap the reference to this form with a function that strips the input from whitespace.
                    if hasattr(form, 'base_fields'):
                        form_class = autostrip(form)
                        setattr(forms_module, form_name, form_class)
コード例 #4
0
ファイル: app.py プロジェクト: Fokko/hellolily
 def ready(self):
     """
     Code run on startup of django.
     """
     # Patch all the forms to strip whitespace from field input
     local_installed_apps = [app for app in settings.INSTALLED_APPS if app.startswith('%s.' % __name__)]
     for app in local_installed_apps:
         try:
             __import__('%s.forms' % app)
         except ImportError:
             continue
         else:
             forms_module = sys.modules['%s.forms' % app]
             form_classes = inspect.getmembers(forms_module, lambda member: self.is_form(member))
             for form_name, form in form_classes:
                 # Wrap the reference to this form with a function that strips the input from whitespace.
                 if hasattr(form, 'base_fields'):
                     form_class = autostrip(form)
                     setattr(forms_module, form_name, form_class)
コード例 #5
0
ファイル: __init__.py プロジェクト: rmoorman/hellolily

local_installed_apps = [app for app in settings.INSTALLED_APPS if app.startswith('%s.' % __name__)]


def is_form(member):
    """
    Allow only custom made classes which are a subclass from BaseForm to pass.
    """
    if not inspect.isclass(member):
        return False

    if not issubclass(member, BaseForm):
        return False

    return member.__module__.startswith(__name__)

for app in local_installed_apps:
    try:
        __import__('%s.forms' % app)
    except ImportError:
        continue
    else:
        forms_module = sys.modules['%s.forms' % app]
        form_classes = inspect.getmembers(forms_module, lambda member: is_form(member))
        for form_name, form in form_classes:
            # Wrap the reference to this form with a function that strips the input from whitespace.
            if hasattr(form, 'base_fields'):
                form_class = autostrip(form)
                setattr(forms_module, form_name, form_class)