Skip to content

Commit

Permalink
Add get_link_attr() method to allow for dynamic link attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
michel4j committed Jan 2, 2020
1 parent a966a88 commit 464a7eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions itemlist/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ def get_link_url(self, obj):
else:
return None

def get_link_attr(self, obj):
return self.link_attr

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['query_string'] = self.get_query_string(remove=[PAGE_VAR, CSV_VAR])
Expand Down Expand Up @@ -338,9 +341,10 @@ def get_row(self, obj):
# replace text with link for link field of column
if field_name == link_field:
url = self.get_link_url(obj)
attr = self.get_link_attr(obj)
if url:
if self.link_attr:
value = safestring.mark_safe('<a href="#!" {attr}="{url}">{value}</a>'.format(url=url, value=value, attr=self.link_attr))
if attr:
value = safestring.mark_safe('<a href="#!" {attr}="{url}">{value}</a>'.format(url=url, value=value, attr=attr))
else:
value = safestring.mark_safe('<a href="{href}">{value}</a>'.format(href=url, value=value))

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='django-itemlist',
version='0.2.5',
version='0.2.6',
packages=find_packages(),
url='https://github.com/michel4j/django-itemlist',
include_package_data=True,
Expand Down

0 comments on commit 464a7eb

Please sign in to comment.