Skip to content
This repository has been archived by the owner on Jul 9, 2020. It is now read-only.

Commit

Permalink
[controller] Added get_controller_urls
Browse files Browse the repository at this point in the history
Allow to reduce boilerplate in third party apps.
  • Loading branch information
nemesifier committed Feb 13, 2017
1 parent 6ea9764 commit 7b783f0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
18 changes: 2 additions & 16 deletions django_netjsonconfig/controller/urls.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
from django.conf.urls import url

from . import views
from ..utils import get_controller_urls

urlpatterns = [
url(r'^controller/checksum/(?P<pk>[^/]+)/$',
views.checksum,
name='checksum'),
url(r'^controller/download-config/(?P<pk>[^/]+)/$',
views.download_config,
name='download_config'),
url(r'^controller/report-status/(?P<pk>[^/]+)/$',
views.report_status,
name='report_status'),
url(r'^controller/register/$',
views.register,
name='register'),
]
urlpatterns = get_controller_urls(views)
22 changes: 22 additions & 0 deletions django_netjsonconfig/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

from django.conf.urls import url
from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404 as base_get_object_or_404

Expand Down Expand Up @@ -82,3 +83,24 @@ def invalid_response(request, error, status, content_type='text/plain'):
"""
logger.warning(error, extra={'request': request, 'stack': True})
return ControllerResponse(error, content_type=content_type, status=status)


def get_controller_urls(views_module):
"""
used by third party apps to reduce boilerplate
"""
urls = [
url(r'^controller/checksum/(?P<pk>[^/]+)/$',
views_module.checksum,
name='checksum'),
url(r'^controller/download-config/(?P<pk>[^/]+)/$',
views_module.download_config,
name='download_config'),
url(r'^controller/report-status/(?P<pk>[^/]+)/$',
views_module.report_status,
name='report_status'),
url(r'^controller/register/$',
views_module.register,
name='register'),
]
return urls
1 change: 1 addition & 0 deletions tests/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.conf.urls import include, url
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

from django_netjsonconfig.admin_theme.admin import admin, openwisp_admin

openwisp_admin()
Expand Down

0 comments on commit 7b783f0

Please sign in to comment.