Exemple #1
0
def discover_modules():
    patterns = __flatten_patterns_tree__(urls.urlpatterns, excluded=urls.excluded)

    # Remove all existing modules
    Module.objects.all().delete()
        
    try:
        for pattern in patterns:
            module = Module(
                url=pattern['url'],
                name=pattern['name'],
                view=pattern['view'],
                multiple=False
            )
            module.save()

            module.update(set__multiple=is_module_managing_occurencies(module))
            module.reload()
    except ValidationError:
        Module.objects.all().delete()

        error_msg = 'A validation error occured during the module discovery. Please provide a name to all modules urls '
        error_msg += 'using the name argument.'
        raise ModuleError(error_msg)
        # something went wrong, delete already added modules
    except Exception, e:
        Module.objects.all().delete()
        raise e