Return a list of views from a list of urlpatterns. Each object in the returned list is a 4-tuple: (view_func, regex, namespace, name)
(urlpatterns, base="", namespace=None)
| 478 | |
| 479 | |
| 480 | def extract_views_from_urlpatterns(urlpatterns, base="", namespace=None): |
| 481 | """ |
| 482 | Return a list of views from a list of urlpatterns. |
| 483 | |
| 484 | Each object in the returned list is a 4-tuple: |
| 485 | (view_func, regex, namespace, name) |
| 486 | """ |
| 487 | views = [] |
| 488 | for p in urlpatterns: |
| 489 | if hasattr(p, "url_patterns"): |
| 490 | try: |
| 491 | patterns = p.url_patterns |
| 492 | except ImportError: |
| 493 | continue |
| 494 | views.extend( |
| 495 | extract_views_from_urlpatterns( |
| 496 | patterns, |
| 497 | base + str(p.pattern), |
| 498 | (namespace or []) + (p.namespace and [p.namespace] or []), |
| 499 | ) |
| 500 | ) |
| 501 | elif hasattr(p, "callback"): |
| 502 | try: |
| 503 | views.append((p.callback, base + str(p.pattern), namespace, p.name)) |
| 504 | except ViewDoesNotExist: |
| 505 | continue |
| 506 | else: |
| 507 | raise TypeError(_("%s does not appear to be a urlpattern object") % p) |
| 508 | return views |
| 509 | |
| 510 | |
| 511 | def simplify_regex(pattern): |
no test coverage detected