Skip to content

Commit

Permalink
allow custom get params in the url
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierdalang committed Jun 8, 2016
1 parent 553cee0 commit b89ea33
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
 
<a class="related-widget-wrapper-link change-related" id="edit_id_{{ name }}"
href=""
href-base="{{ edit_related_url }}?{{ url_params }}"
href-base="{{ edit_related_url }}{{ edit_parameter_separator }}{{ url_params }}"
title="{% blocktrans %}Edit related{% endblocktrans %}">
<img src="{% static edit_icon %}" alt="{% trans 'Edit' %}"/>
</a>
Expand All @@ -16,7 +16,7 @@
{% if add_related_url %}
&nbsp;
<a class="related-widget-wrapper-link add-related" id="add_id_{{ name }}"
href="{{ add_related_url }}?{{ url_params }}"
href="{{ add_related_url }}{{ add_parameter_separator }}{{ url_params }}"
title="{% blocktrans %}Add another{% endblocktrans %}">
<img src="{% static add_icon %}" alt="{% trans 'Add' %}"/>
</a>
Expand Down
4 changes: 4 additions & 0 deletions django_addanother/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,18 @@ def __init__(self, widget, add_related_url, edit_related_url, add_icon=None, edi

def render(self, name, value, *args, **kwargs):
self.widget.choices = self.choices
add_parameter_separator = '?' if (self.add_related_url and '?' not in self.add_related_url) else '&'
edit_parameter_separator = '?' if (self.edit_related_url and '?' not in self.edit_related_url) else '&'

url_params = "%s=%s" % (IS_POPUP_VAR, 1)
context = {
'widget': self.widget.render(name, value, *args, **kwargs),
'name': name,
'url_params': url_params,
'add_parameter_separator': add_parameter_separator,
'add_related_url': self.add_related_url,
'add_icon': self.add_icon,
'edit_parameter_separator': edit_parameter_separator,
'edit_related_url': self.edit_related_url,
'edit_icon': self.edit_icon,
'edit_icon_disabled': self.edit_icon_disabled,
Expand Down

0 comments on commit b89ea33

Please sign in to comment.