2013-12-15 17:09:22 +01:00
|
|
|
"""
|
|
|
|
top-level url dispatching
|
|
|
|
"""
|
|
|
|
|
2018-10-19 00:45:04 +02:00
|
|
|
import six
|
|
|
|
|
2013-11-28 09:14:16 +01:00
|
|
|
from django.conf import settings
|
2017-05-27 00:55:55 +02:00
|
|
|
from django.conf.urls import include, url
|
2013-09-28 11:39:57 +02:00
|
|
|
from django.contrib import admin
|
2013-11-15 10:07:40 +01:00
|
|
|
from django.contrib.auth import views as auth_views
|
2017-05-27 00:55:55 +02:00
|
|
|
from django.conf.urls.static import static
|
2018-10-19 00:45:04 +02:00
|
|
|
from django.http import HttpResponse
|
2013-10-03 19:26:39 +02:00
|
|
|
|
2013-11-15 10:07:40 +01:00
|
|
|
|
2013-11-16 04:50:48 +01:00
|
|
|
def remember_me_login(request, *args, **kw):
|
|
|
|
"""
|
|
|
|
Wraps the default login view function. If user does not want to be
|
|
|
|
remembered, we change the cookie to a session cookie that gets cleared
|
|
|
|
when the browser is closed.
|
|
|
|
"""
|
|
|
|
if request.method == 'POST':
|
2013-11-28 09:14:16 +01:00
|
|
|
if request.POST.get('remember_me'):
|
|
|
|
request.session.set_expiry(settings.SESSION_COOKIE_AGE)
|
2013-11-16 04:50:48 +01:00
|
|
|
return auth_views.login(request, *args, **kw)
|
|
|
|
|
|
|
|
|
2017-05-27 00:55:55 +02:00
|
|
|
urlpatterns = [
|
2016-12-27 23:11:50 +01:00
|
|
|
url('', include('social_django.urls', namespace='social')),
|
2013-12-29 22:22:08 +01:00
|
|
|
url(r'^accounts/', include('nsupdate.login.urls')),
|
|
|
|
# registration and user settings
|
2013-10-17 20:50:44 +00:00
|
|
|
url(r'^account/', include('nsupdate.accounts.urls')),
|
2013-09-28 11:39:57 +02:00
|
|
|
url(r'^admin/', include(admin.site.urls)),
|
2014-08-25 00:01:26 +02:00
|
|
|
url(r'^i18n/', include('django.conf.urls.i18n')),
|
2013-10-17 20:50:44 +00:00
|
|
|
url(r'^', include('nsupdate.main.urls')),
|
2017-05-27 00:55:55 +02:00
|
|
|
]
|
2013-09-28 10:44:29 +02:00
|
|
|
|
2013-09-28 11:39:57 +02:00
|
|
|
if settings.DEBUG:
|
2017-05-27 00:55:55 +02:00
|
|
|
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
2013-12-08 14:42:58 +01:00
|
|
|
import debug_toolbar
|
2018-01-29 08:15:04 +01:00
|
|
|
urlpatterns += [url(r'^__debug__/', include(debug_toolbar.urls)), ]
|
2018-10-19 00:45:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
# we have expensive context processors and do not want to invoke them for the
|
|
|
|
# http error views, so we must not use templates (nor the django default views).
|
|
|
|
|
|
|
|
def http_error(request, status, exception=None):
|
|
|
|
if exception is not None:
|
|
|
|
exception_repr = exception.__class__.__name__
|
|
|
|
# Try to get an "interesting" exception message:
|
|
|
|
try:
|
|
|
|
message = exception.args[0]
|
|
|
|
except (AttributeError, IndexError):
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
if isinstance(message, six.text_type):
|
|
|
|
exception_repr = message
|
|
|
|
else:
|
|
|
|
# we do not have an exception for 500
|
|
|
|
exception_repr = 'Server Error'
|
|
|
|
body = """\
|
|
|
|
<h1>%(exception)s (error %(status)d)</h1>
|
|
|
|
""" % dict(
|
|
|
|
exception=exception_repr,
|
|
|
|
status=status,
|
|
|
|
)
|
|
|
|
return HttpResponse(body, content_type='text/html', status=status)
|
|
|
|
|
|
|
|
|
|
|
|
def bad_request(request, exception, template_name=None):
|
|
|
|
return http_error(request, 400, exception)
|
|
|
|
|
|
|
|
|
|
|
|
def permission_denied(request, exception, template_name=None):
|
|
|
|
return http_error(request, 403, exception)
|
|
|
|
|
|
|
|
|
|
|
|
def page_not_found(request, exception, template_name=None):
|
|
|
|
return http_error(request, 404, exception)
|
|
|
|
|
|
|
|
|
|
|
|
def server_error(request, template_name=None):
|
|
|
|
return http_error(request, 500)
|
|
|
|
|
|
|
|
|
|
|
|
handler400 = 'nsupdate.urls.bad_request'
|
|
|
|
handler403 = 'nsupdate.urls.permission_denied'
|
|
|
|
handler404 = 'nsupdate.urls.page_not_found'
|
|
|
|
handler500 = 'nsupdate.urls.server_error'
|