diff options
Diffstat (limited to 'ishtar_common/widgets.py')
| -rw-r--r-- | ishtar_common/widgets.py | 12 | 
1 files changed, 10 insertions, 2 deletions
| diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index 2105b73e3..71d88d062 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -134,7 +134,7 @@ class JQueryDate(forms.TextInput):  class JQueryAutoComplete(forms.TextInput):
      def __init__(self, source, associated_model=None, options={}, attrs={},
 -                 new=False, multiple=False):
 +                 new=False, multiple=False, limit={}):
          """
          Source can be a list containing the autocomplete values or a
          string containing the url used for the request.
 @@ -148,6 +148,7 @@ class JQueryAutoComplete(forms.TextInput):          self.attrs.update(attrs)
          self.new = new
          self.multiple = multiple
 +        self.limit = limit
      def value_from_datadict(self, data, files, name):
          if self.multiple:
 @@ -222,7 +223,14 @@ class JQueryAutoComplete(forms.TextInput):          new = ''
          if self.new:
              model_name = self.associated_model._meta.object_name.lower()
 -            url_new = reverse('new-' + model_name, args=[attrs_select['id']])
 +            limits = []
 +            for k in self.limit:
 +                limits.append(k + "__" + "-".join(
 +                            [unicode(v) for v in self.limit[k]]))
 +            args = [attrs_select['id']]
 +            if limits:
 +                args.append(';'.join(limits))
 +            url_new = reverse('new-' + model_name, args=args)
              new = u'  <a href="#" class="add-button" '\
                    u'onclick="open_window(\'%s\');">+</a>' % url_new
          html = u'''<input%(attrs_select)s/>%(new)s\
 | 
