from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.admindocs import urls as admindocs_urls

admin.autodiscover()

include_app = lambda name: url(
    r'^{}/'.format(name),
    include(
        '{}.urls'.format(name),
        app_name=name
    )
)

urlpatterns = patterns(
    '',
    url(r'^$', include('common.urls', app_name='global')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^admindocs/', include(admindocs_urls)),

    include_app('pizza'),
    include_app('tournaments'),
    include_app('flags'),
    include_app('schedule')
)

# load in the legacy url rewrites
import importlib
for app in settings.INSTALLED_APPS:
    try:
        urls = importlib.import_module(app + '.urls')
    except ImportError:
        pass
    else:
        if hasattr(urls, 'legacy_patterns'):
            urlpatterns += getattr(urls, 'legacy_patterns')

if settings.DEBUG:
    import debug_toolbar
    urlpatterns += patterns(
        '',
        url(r'^__debug__/', include(debug_toolbar.urls)),
    )

# add the static files
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

@@ -675,16 +675,17 @@
 le')%0A)%0A%0A
+%0A
 # load i
@@ -714,59 +714,33 @@
 tes%0A
-import importlib%0Afor app in settings.INSTALLED_APPS
+def load_legacy_urls(app)
 :%0A  
@@ -836,12 +836,17 @@
     
-pass
+return %5B%5D
 %0A   
@@ -909,30 +909,22 @@
         
-urlpatterns +=
+return
  getattr
@@ -949,16 +949,150 @@
 terns')%0A
+        else:%0A            return %5B%5D%0A%0A%0Aimport importlib%0Afor app in settings.INSTALLED_APPS:%0A    urlpatterns += load_legacy_urls(app)%0A%0A%0A
 %0Aif sett

Split into function