Exemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     size = kwargs.pop('size', 0)
     super(SearchForm, self).__init__(*args, **kwargs)
     indexes = {}
     for name, model in DEFAULT_INDEXES.iteritems():
         indexes[name] = model._meta.verbose_name.capitalize()
     for name in DataBag.objects.values_list('name', flat=True):
         if name not in indexes:
             indexes[name] = name.capitalize()
     self.fields['index'].choices = sorted(indexes.iteritems())
     # If the query is too big to see, scale up to field (capped at 150)
     if 'q' in self.data and len(self.data['q']) > size - 10:
         size = min(len(self.data['q']) + 20, 150)
     if size:
         self.fields['q'].widget.attrs['size'] = size
     self._sqs = None