Skip to content

Fix of admin_links for Django 2 #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ env:
- DJANGO_VERSION=https://github.com/django/django/archive/stable/1.11.x.zip
- DJANGO_VERSION=https://github.com/django/django/archive/stable/2.0.x.zip
- DJANGO_VERSION=https://github.com/django/django/archive/stable/2.1.x.zip
- DJANGO_VERSION=https://github.com/django/django/archive/stable/2.2.x.zip
python:
- "2.7"
- "3.4"
Expand All @@ -17,8 +18,12 @@ matrix:
env: DJANGO_VERSION=https://github.com/django/django/archive/stable/2.0.x.zip
- python: "2.7"
env: DJANGO_VERSION=https://github.com/django/django/archive/stable/2.1.x.zip
- python: "2.7"
env: DJANGO_VERSION=https://github.com/django/django/archive/stable/2.2.x.zip
- python: "3.4"
env: DJANGO_VERSION=https://github.com/django/django/archive/stable/2.1.x.zip
- python: "3.4"
env: DJANGO_VERSION=https://github.com/django/django/archive/stable/2.2.x.zip
install:
- pip install $DJANGO_VERSION
- pip install .
Expand Down
1 change: 1 addition & 0 deletions forms_builder/example_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
'django.contrib.messages',
'forms_builder.forms',
)

Expand Down
10 changes: 4 additions & 6 deletions forms_builder/forms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django import VERSION as DJANGO_VERSION
from django.contrib.sites.models import Site
from django.utils.html import format_html_join

try:
from django.urls import reverse
Expand Down Expand Up @@ -142,16 +143,13 @@ def get_absolute_url(self):
return reverse("form_detail", kwargs={"slug": self.slug})

def admin_links(self):
kw = {"args": (self.id,)}
links = [
kw = {"args": (self.id, )}
return format_html_join("\n", "<div><a href='{1}'>{0}</a></div>", (
(_("View form on site"), self.get_absolute_url()),
(_("Filter entries"), reverse("admin:form_entries", **kw)),
(_("View all entries"), reverse("admin:form_entries_show", **kw)),
(_("Export all entries"), reverse("admin:form_entries_export", **kw)),
]
for i, (text, url) in enumerate(links):
links[i] = "<a href='%s'>%s</a>" % (url, ugettext(text))
return "<br>".join(links)
))
admin_links.allow_tags = True
admin_links.short_description = ""

Expand Down
12 changes: 12 additions & 0 deletions forms_builder/forms/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import unicode_literals

from django.utils.safestring import SafeText
from django.conf import settings
from django.contrib.auth.models import User, AnonymousUser
from django.contrib.sites.models import Site
Expand Down Expand Up @@ -239,3 +240,14 @@ def test_input_dropdown_required_with_default(self):
<option value="two" selected>two</option>
<option value="three">three</option>
</select>""", html=True)

def test_admin_link(self):
form = Form.objects.create(title="Test")
content = form.admin_links()
self.assertIsInstance(content, SafeText)
self.assertInHTML(content, """
<div><a href='/forms/test/'>View form on site</a></div>
<div><a href='/admin/forms/form/1/entries/'>Filter entries</a></div>
<div><a href='/admin/forms/form/1/entries/show/'>View all entries</a></div>
<div><a href='/admin/forms/form/1/entries/export/'>Export all entries</a></div>
""")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"sphinx-me >= 0.1.2",
"unidecode",
"django-email-extras >= 0.2",
"django >= 1.8, < 2.2",
"django >= 1.11, < 2.2.99",
"future <= 0.15.0",
],
classifiers = [
Expand Down