-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59c2f3a
commit 816ce91
Showing
3 changed files
with
57 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
from django.urls.resolvers import URLResolver | ||
|
||
|
||
def insert_urls_before(urlpatterns: list, before_name: str, url: URLResolver): | ||
for index, pattern in enumerate(urlpatterns): | ||
# Insert before index if `name` or `app_name` matches | ||
if hasattr(pattern, 'name'): | ||
if pattern.name == before_name: | ||
urlpatterns.insert(index, url) | ||
break | ||
elif hasattr(pattern, 'app_name'): | ||
if pattern.app_name == before_name: | ||
urlpatterns.insert(index, url) | ||
break | ||
|
||
return urlpatterns | ||
|
||
|
||
def delete_urls(urlpatterns: list, delete_name: str): | ||
for index, pattern in enumerate(urlpatterns): | ||
if hasattr(pattern, 'name'): | ||
if pattern.name == delete_name: | ||
# Insert before index | ||
urlpatterns.pop(index) | ||
break | ||
|
||
return urlpatterns |