Skip to content

Commit

Permalink
Free text as URL (#41)
Browse files Browse the repository at this point in the history
* Free text as URL

* Blacked

* Updated README
  • Loading branch information
raratiru authored Aug 16, 2020
1 parent 9f40f6a commit c754147
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ Settings
LETSAGREE_CACHE = False
LETSAGREE_CSS = {}
LETSAGREE_JS = ()
LETSAGREE_LOGOUT_APP_NAME = 'admin:logout'
LETSAGREE_LOGOUT_APP_NAME = 'admin:logout' (Deprecated)
LETSAGREE_LOGOUT_URL = 'admin:logout'
LETSAGREE_BROWSER_TITLE = ''
LETSAGREE_BORDER_HEADER = ''
```
Expand Down Expand Up @@ -194,7 +195,7 @@ In that case, bear in mind that if `{{ empty_form }}` is False, `{{ form }}` con

### Other settings

* `LETSAGREE_LOGOUT_APP_NAME`: String that represents a namespaced URL.
* `LETSAGREE_LOGOUT_URL`: String that represents a namespaced URL.

For example: `'admin:logout'` is the default.

Expand Down Expand Up @@ -251,6 +252,10 @@ Unfortunatelly, the test suite is rather complicated. Sorry!

Changelog
---------
1.1.4: Deprecated `LETSAGREE_LOGOUT_APP_NAME` in favor of `LETSAGREE_LOGOUT_URL`

1.1.3: Locked to Django-3.0 until #39 is resolved

1.1.2: Added the ability to set a namespaced url in the "logout application name" setting.

1.1.1: AnonymousUser should not access letsagree urls (receives 404)
Expand Down
13 changes: 10 additions & 3 deletions letsagree/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
# Creation Date : Sat 23 Mar 2019 08:42:45 PM EET (20:42)
#
# Last Modified : Fri 14 Aug 2020 03:39:22 PM EEST (15:39)
# Last Modified : Sun 16 Aug 2020 08:49:57 PM EEST (20:49)
#
# ==============================================================================

Expand All @@ -34,7 +34,8 @@
reason="Window Function is not supported in this SQLite version",
)
@pytest.mark.parametrize(
"terms_agreed,request_url,agree_queries", [(True, "/", 2), (False, "/", 1)]
"terms_agreed,request_url,agree_queries",
[(True, "/", 2), (False, "/", 1), (None, "/", 1)],
)
def test_view_structure(
queries,
Expand All @@ -51,6 +52,8 @@ def test_view_structure(
# Set once the logout url to test if it is rendered
if terms_agreed:
settings.LETSAGREE_LOGOUT_APP_NAME = None # By default is 'admin'
elif terms_agreed is None:
settings.LETSAGREE_LOGOUT_URL = "admin:logout"
else:
settings.LETSAGREE_LOGOUT_APP_NAME = "foo"
# Test Pending View
Expand All @@ -64,7 +67,9 @@ def test_view_structure(
if terms_agreed:
assert "There are no pending agreements" in response.rendered_content
assert reverse("admin:logout") in response.rendered_content

elif terms_agreed is None:
assert "There are no pending agreements" not in response.rendered_content
assert reverse("admin:logout") in response.rendered_content
else:
assert "There are no pending agreements" not in response.rendered_content
assert "LOG OUT" not in response.rendered_content
Expand All @@ -76,6 +81,8 @@ def test_view_structure(
("admin", "admin:logout"),
("admin:", "admin:logout"),
("admin:logout_view", "admin:logout_view"),
("", None),
(False, None),
],
)
def test_named_url(the_string, the_result):
Expand Down
28 changes: 18 additions & 10 deletions letsagree/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
# Creation Date : Sun 27 Jan 2019 07:54:42 PM EET (19:54)
#
# Last Modified : Fri 14 Aug 2020 03:53:16 PM EEST (15:53)
# Last Modified : Sun 16 Aug 2020 08:37:39 PM EEST (20:37)
#
# ==============================================================================

Expand Down Expand Up @@ -64,12 +64,15 @@ def form_valid(self, form):

@staticmethod
def get_logout_string(the_string):
prep = list(filter(None, the_string.split(":")))
choices = {
1: "{0}:logout".format(prep[0]),
2: "{0}:{1}".format(prep[0], prep[-1]),
}
return choices[len(prep)]
if the_string:
prep = list(filter(None, the_string.split(":")))
choices = {
1: "{0}:logout".format(prep[0]),
2: "{0}:{1}".format(prep[0], prep[-1]),
}
return choices[len(prep)]
else:
return None

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
Expand All @@ -80,10 +83,15 @@ def get_context_data(self, **kwargs):
context["user"] = self.request.user

try:
logout_url_app = (
getattr(settings, "LETSAGREE_LOGOUT_APP_NAME", "admin") or "admin"
logout_url = (
self.get_logout_string(
getattr(settings, "LETSAGREE_LOGOUT_APP_NAME", "admin")
)
or getattr(settings, "LETSAGREE_LOGOUT_URL", "admin:logout")
or "admin:logout"
)
context["logout_url"] = reverse(self.get_logout_string(logout_url_app))

context["logout_url"] = reverse(logout_url)
except NoReverseMatch:
pass

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
# Creation Date : Mon 08 Apr 2019 07:00:40 PM EEST (19:00)
#
# Last Modified : Sat 15 Aug 2020 08:14:01 PM EEST (20:14)
# Last Modified : Sun 16 Aug 2020 09:06:10 PM EEST (21:06)
#
# ==============================================================================

Expand All @@ -22,7 +22,7 @@

setup(
name="django-letsagree",
version="1.1.3",
version="1.1.4",
python_requires=">=3.5",
description=(
"A django application that associates Groups with Terms "
Expand Down

0 comments on commit c754147

Please sign in to comment.