mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-10 09:06:21 +01:00
Restructure Alliance Auth package (#867)
* Refactor allianceauth into its own package * Add setup * Add missing default_app_config declarations * Fix timerboard namespacing * Remove obsolete future imports * Remove py2 mock support * Remove six * Add experimental 3.7 support and multiple Dj versions * Remove python_2_unicode_compatible * Add navhelper as local package * Update requirements
This commit is contained in:
0
allianceauth/thirdparty/__init__.py
vendored
Normal file
0
allianceauth/thirdparty/__init__.py
vendored
Normal file
0
allianceauth/thirdparty/navhelper/__init__.py
vendored
Normal file
0
allianceauth/thirdparty/navhelper/__init__.py
vendored
Normal file
0
allianceauth/thirdparty/navhelper/templatetags/__init__.py
vendored
Normal file
0
allianceauth/thirdparty/navhelper/templatetags/__init__.py
vendored
Normal file
63
allianceauth/thirdparty/navhelper/templatetags/navactive.py
vendored
Normal file
63
allianceauth/thirdparty/navhelper/templatetags/navactive.py
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
"""
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Guillaume Luchet
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
"""
|
||||
from django.template import Library
|
||||
from django.core.urlresolvers import resolve
|
||||
from django.conf import settings
|
||||
import re
|
||||
|
||||
register = Library()
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def renavactive(request, pattern):
|
||||
"""
|
||||
{% renavactive request "^/a_regex" %}
|
||||
"""
|
||||
if re.search(pattern, request.path):
|
||||
return getattr(settings, "NAVHELPER_ACTIVE_CLASS", "active")
|
||||
return getattr(settings, "NAVHELPER_NOT_ACTIVE_CLASS", "")
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def navactive(request, urls):
|
||||
"""
|
||||
{% navactive request "view_name another_view_name" %}
|
||||
"""
|
||||
url_list = set(urls.split())
|
||||
|
||||
resolved = resolve(request.path)
|
||||
resolved_urls = set()
|
||||
if resolved.url_name:
|
||||
resolved_urls.add(resolved.url_name)
|
||||
if resolved.namespaces:
|
||||
resolved_urls = resolved_urls.union(["{}:{}".format(namespace, resolved.url_name) for namespace in resolved.namespaces])
|
||||
resolved_urls = resolved_urls.union(["{}:".format(namespace) for namespace in resolved.namespaces])
|
||||
if getattr(resolved, 'app_name', None):
|
||||
resolved_urls = resolved_urls.union(["{}:{}".format(resolved.app_name, resolved.url_name), "{}:".format(resolved.app_name)])
|
||||
if getattr(resolved, 'app_names', []):
|
||||
resolved_urls = resolved_urls.union(["{}:{}".format(app_name, resolved.url_name) for app_name in resolved.app_names])
|
||||
resolved_urls = resolved_urls.union(["{}:".format(app_name) for app_name in resolved.app_names])
|
||||
if url_list and resolved_urls and bool(resolved_urls & url_list):
|
||||
return getattr(settings, "NAVHELPER_ACTIVE_CLASS", "active")
|
||||
return getattr(settings, "NAVHELPER_NOT_ACTIVE_CLASS", "")
|
||||
88
allianceauth/thirdparty/navhelper/tests.py
vendored
Normal file
88
allianceauth/thirdparty/navhelper/tests.py
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
"""
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Guillaume Luchet
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
"""
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from django.template import Context, Template
|
||||
from django.test import TestCase, RequestFactory
|
||||
|
||||
|
||||
class NavhelperTemplateTagTests(TestCase):
|
||||
def setUp(self):
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_navactive(self):
|
||||
self._navactive_common('active', '')
|
||||
|
||||
with self.settings(NAVHELPER_ACTIVE_CLASS='my-active-class',
|
||||
NAVHELPER_NOT_ACTIVE_CLASS='my-not-active-class'):
|
||||
self._navactive_common('my-active-class', 'my-not-active-class')
|
||||
|
||||
def test_renavactive(self):
|
||||
self._renavactive_common('active', '')
|
||||
|
||||
with self.settings(NAVHELPER_ACTIVE_CLASS='my-active-class',
|
||||
NAVHELPER_NOT_ACTIVE_CLASS='my-not-active-class'):
|
||||
self._renavactive_common('my-active-class', 'my-not-active-class')
|
||||
|
||||
def _navactive_common(self, active, not_active):
|
||||
request = self.factory.get('/main-page/')
|
||||
|
||||
out = Template(
|
||||
"{% load navactive %}"
|
||||
"{% navactive request 'p1' %}"
|
||||
).render(Context({"request": request}))
|
||||
self.assertEqual(out, active)
|
||||
|
||||
out = Template(
|
||||
"{% load navactive %}"
|
||||
"{% navactive request 'p1-s1' %}"
|
||||
).render(Context({"request": request}))
|
||||
self.assertEqual(out, not_active)
|
||||
|
||||
out = Template(
|
||||
"{% load navactive %}"
|
||||
"{% navactive request 'p1 p1-s1' %}"
|
||||
).render(Context({"request": request}))
|
||||
self.assertEqual(out, active)
|
||||
|
||||
out = Template(
|
||||
"{% load navactive %}"
|
||||
"{% navactive request 'p2' %}"
|
||||
).render(Context({"request": request}))
|
||||
self.assertEqual(out, not_active)
|
||||
|
||||
def _renavactive_common(self, active, not_active):
|
||||
t1 = "{% load navactive %}{% renavactive request '^/main-page' %}"
|
||||
|
||||
request = self.factory.get('/main-page/')
|
||||
out = Template(t1).render(Context({"request": request}))
|
||||
self.assertEqual(out, active)
|
||||
|
||||
request = self.factory.get('/main-page/sub-section/')
|
||||
out = Template(t1).render(Context({"request": request}))
|
||||
self.assertEqual(out, active)
|
||||
|
||||
request = self.factory.get('/second-page/')
|
||||
out = Template(t1).render(Context({"request": request}))
|
||||
self.assertEqual(out, not_active)
|
||||
Reference in New Issue
Block a user