Revision c83d0ada snf-webproject/synnefo/webproject/management/commands/show_urls.py

b/snf-webproject/synnefo/webproject/management/commands/show_urls.py
18 18

  
19 19
try:
20 20
    # 2008-05-30 admindocs found in newforms-admin brand
21
    from django.contrib.admindocs.views import extract_views_from_urlpatterns, simplify_regex
21
    from django.contrib.admindocs.views import \
22
        extract_views_from_urlpatterns, simplify_regex
22 23
except ImportError:
23 24
    # fall back to trunk, pre-NFA merge
24
    from django.contrib.admin.views.doc import extract_views_from_urlpatterns, simplify_regex
25
    from django.contrib.admin.views.doc import \
26
        extract_views_from_urlpatterns, simplify_regex
27

  
25 28

  
26 29
class Command(BaseCommand):
27 30
    help = "Displays all of the url matching routes for the project."
......
35 38
        style = color_style()
36 39

  
37 40
        if settings.ADMIN_FOR:
38
            settings_modules = [__import__(m, {}, {}, ['']) for m in settings.ADMIN_FOR]
41
            settings_modules = [__import__(m, {}, {}, [''])
42
                                for m in settings.ADMIN_FOR]
39 43
        else:
40 44
            settings_modules = [settings]
41 45

  
......
46 50
            except Exception, e:
47 51
                if options.get('traceback', None):
48 52
                    import traceback
49
                    traceback.print_exc()
50
                print style.ERROR("Error occurred while trying to load %s: %s" % (settings_mod.ROOT_URLCONF, str(e)))
53
                    self.stderr.write(traceback.format_exc())
54
                self.stderr.write(
55
                    style.ERROR("Error occurred while trying to load %s: %s"
56
                                % (settings_mod.ROOT_URLCONF, str(e))))
51 57
                continue
52
            view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
58
            view_functions = \
59
                extract_views_from_urlpatterns(urlconf.urlpatterns)
53 60
            for (func, regex) in view_functions:
54
                func_name = hasattr(func, '__name__') and func.__name__ or repr(func)
55
                views.append("%(url)s\t%(module)s.%(name)s" % {'name': style.MODULE_NAME(func_name),
56
                                       'module': style.MODULE(getattr(func, '__module__', '<no module>')),
57
                                       'url': style.URL(simplify_regex(regex))})
61
                func_name = hasattr(func, '__name__') and \
62
                    func.__name__ or repr(func)
63
                views.append("%(url)s\t%(module)s.%(name)s"
64
                             % {'name': style.MODULE_NAME(func_name),
65
                                'module': style.MODULE(
66
                                    getattr(func, '__module__',
67
                                            '<no module>')),
68
                                'url': style.URL(simplify_regex(regex))})
58 69

  
59 70
        return "\n".join([v for v in views])

Also available in: Unified diff