Move templates and urls to apps.

Implement url hooks.
Many apps are now removable.
Default to assuming services have been migrated.
This commit is contained in:
Adarnof
2017-06-07 22:49:46 -04:00
parent 9cc9a36766
commit 97fe2ddfd0
62 changed files with 685 additions and 469 deletions

View File

@@ -7,17 +7,9 @@
The menu hooks allow you to dynamically specify menu items from your plugin app or service. To achieve this you should subclass or instantiate the `services.hooks.MenuItemHook` class and then register the menu item with one of the hooks.
There are three levels of Menu Item Hooks
- `menu_main_hook`
- `menu_aux_hook`
- `menu_util_hook`
These represent the 3 levels of menu displayed on the site.
To register a MenuItemHook class you would do the following:
@hooks.register('menu_util_hook')
@hooks.register('menu_item_hook')
def register_menu():
return MenuItemHook('Example Item', 'glyphicon glyphicon-heart', 'example_url_name', 150)
@@ -34,5 +26,7 @@ The classes that should be applied to the bootstrap menu item icon
The name of the Django URL to use
#### order
An integer which specifies the order of the menu item, lowest to highest
#### navactive
A list of views or namespaces the link should be highlighted on. See [django-navhelper](https://github.com/geelweb/django-navhelper#navactive) for usage. Defaults to the supplied `url_name`.
If you cannot get the menu item to look the way you wish, you are free to subclass and override the default render function and the template used.

View File

@@ -0,0 +1,54 @@
# URL Hooks
```eval_rst
.. note::
Currently most URL patterns are statically defined in the project's core urls.py file. Ideally this behaviour will change over time with each module of Alliance Auth providing all of its menu items via the hook. New modules should aim to use the hook over statically adding URL patterns to the project's patterns.
```
The URL hooks allow you to dynamically specify URL patterns from your plugin app or service. To achieve this you should subclass or instantiate the `services.hooks.UrlHook` class and then register the URL patterns with the hook.
To register a UrlHook class you would do the following:
@hooks.register('url_hook')
def register_urls():
return UrlHook(app_name.urls, 'app_name', r^'app_name/')
The `UrlHook` class specifies some parameters/instance variables required for URL pattern inclusion.
`UrlHook(urls, app_name, base_url)`
#### urls
The urls module to include. See [the Django docs](https://docs.djangoproject.com/en/dev/topics/http/urls/#example) for designing urlpatterns.
#### namespace
The URL namespace to apply. This is usually just the app name.
#### base_url
The URL prefix to match against in regex form. Example `r'^app_name/'`. This prefix will be applied in front of all URL patterns included. It is possible to use the same prefix as existing apps (or no prefix at all) but [standard URL resolution](https://docs.djangoproject.com/en/dev/topics/http/urls/#how-django-processes-a-request) ordering applies (hook URLs are the last ones registered).
### Example
An app called `plugin` provides a single view:
def index(request):
return render(request, 'plugin/index.html')
The app's `urls.py` would look like so:
from django.conf.urls import url
import plugin.views
urlpatterns = [
url(r^'index$', plugins.views.index, name='index'),
]
Subsequently it would implement the UrlHook in a dedicated `auth_hooks.py` file like so:
from alliance_auth import hooks
from services.hooks import UrlHook
import plugin.urls
@hooks.register('url_hook')
def register_urls():
return UrlHook(plugin.urls, 'plugin', r^'plugin/')
When this app is included in the project's `settings.INSTALLED_APPS` users would access the index view by navigating to `https://example.com/plugin/index`.