245 | | settings.ROOT_URLCONF = self.urls |
| 248 | if settings.TEST_COMBINE_URLCONFS: |
| 249 | # Put the module instance of self.urls into specified_urlconf |
| 250 | if not isinstance(self.urls, basestring): |
| 251 | specified_urlconf = self.urls |
| 252 | else: |
| 253 | specified_urlconf = import_module(self.urls) |
| 254 | # Choose between settings.TEST_COMBINE_URLCONFS_WITH and settings.ROOT_URLCONF |
| 255 | urls_to_combine = settings.TEST_COMBINE_URLCONFS_WITH or settings.ROOT_URLCONF |
| 256 | # Do the above action, this time with urls_to_combine |
| 257 | if not isinstance(urls_to_combine, basestring): |
| 258 | extra_urlconf = urls_to_combine |
| 259 | else: |
| 260 | extra_urlconf = import_module(urls_to_combine) |
| 261 | # Create a dynamic URLconf module that combines the urlpatterns |
| 262 | # of specified_urlconf and extra_urlconf |
| 263 | dynamic_urlconf_name = 'dynamic_urls' |
| 264 | dynamic_urlconf = imp.new_module(dynamic_urlconf_name) |
| 265 | dynamic_urlconf.urlpatterns = specified_urlconf.urlpatterns + \ |
| 266 | extra_urlconf.urlpatterns |
| 267 | # Also combine handler404 and 500, favoring specified_urlconf |
| 268 | handler404 = getattr(specified_urlconf, 'handler404', None) or \ |
| 269 | getattr(extra_urlconf, 'handler404', None) |
| 270 | if handler404: |
| 271 | dynamic_urlconf.handler404 = handler404 |
| 272 | handler500 = getattr(specified_urlconf, 'handler404', None) or \ |
| 273 | getattr(extra_urlconf, 'handler404', None) |
| 274 | if handler500: |
| 275 | dynamic_urlconf.handler500 = handler500 |
| 276 | # Add our dynamic_urlconf to sys.modules and set |
| 277 | # settings.ROOT_URLCONF to it |
| 278 | sys.modules[dynamic_urlconf_name] = dynamic_urlconf |
| 279 | settings.ROOT_URLCONF = dynamic_urlconf |
| 280 | else: |
| 281 | settings.ROOT_URLCONF = self.urls |