original_docstring: Initialize advanced search form formsets based on the query.
      Used when the GET of advanced search includes URL parameters, in other words
      we are returning to modify the search
      
docstring: Initialize advanced search form formsets based on the query.
  Used when the GET of advanced search includes URL parameters, in other words
  we are returning to modify the search
docstring_tokens: Initialize advanced search form formsets based on the query . Used when the GET of advanced search includes URL parameters in other words we are returning to modify the search
code: def initialize_formsets(query):
      """Initialize advanced search form formsets based on the query.
      Used when the GET of advanced search includes URL parameters, in other words
      we are returning to modify the search
      """
      RulesFormset0 = formset_factory(RulesForm, extra=0)
      RulesFormset1 = formset_factory(RulesForm, extra=1)
  
      qinitial = []
      ninitial = []
  
      while query:
          query = query.lstrip()
          if re.search(contain_pattern, query):
              match = re.search(contain_pattern, query)
              d = {'field': match.groupdict()['field'],
                   'value': match.groupdict()['value'],
                   'qualifier': 'contains'}
              if match.groupdict()['neg']:
                  ninitial.append(d)
              else:
                  qinitial.append(d)
              query, n = re.subn(contain_pattern, '', query, 1)
          elif re.search(exact_pattern, query):
              match = re.search(exact_pattern, query)
              d = {'field': match.groupdict()['field'],
                   'value': match.groupdict()['value'],
                   'qualifier': 'exact'}
              if match.groupdict()['neg']:
                  ninitial.append(d)
              else:
                  qinitial.append(d)
              query, n = re.subn(exact_pattern, '', query, 1)
          else:
              query = query[1:]
  
      if qinitial:
          query_formset = RulesFormset0(prefix='query', initial=qinitial)
      else:
          query_formset = RulesFormset1(prefix='query')
      if ninitial:
          not_formset = RulesFormset0(prefix='not', initial=ninitial)
      else:
          not_formset = RulesFormset1(prefix='not')
  
      return query_formset, not_formset
code_tokens: def initialize_formsets ( query ) : RulesFormset0 = formset_factory ( RulesForm , extra = 0 ) RulesFormset1 = formset_factory ( RulesForm , extra = 1 ) qinitial = [ ] ninitial = [ ] while query : query = query . lstrip ( ) if re . search ( contain_pattern , query ) : match = re . search ( contain_pattern , query ) d = { 'field' : match . groupdict ( ) [ 'field' ] , 'value' : match . groupdict ( ) [ 'value' ] , 'qualifier' : 'contains' } if match . groupdict ( ) [ 'neg' ] : ninitial . append ( d ) else : qinitial . append ( d ) query , n = re . subn ( contain_pattern , '' , query , 1 ) elif re . search ( exact_pattern , query ) : match = re . search ( exact_pattern , query ) d = { 'field' : match . groupdict ( ) [ 'field' ] , 'value' : match . groupdict ( ) [ 'value' ] , 'qualifier' : 'exact' } if match . groupdict ( ) [ 'neg' ] : ninitial . append ( d ) else : qinitial . append ( d ) query , n = re . subn ( exact_pattern , '' , query , 1 ) else : query = query [ 1 : ] if qinitial : query_formset = RulesFormset0 ( prefix = 'query' , initial = qinitial ) else : query_formset = RulesFormset1 ( prefix = 'query' ) if ninitial : not_formset = RulesFormset0 ( prefix = 'not' , initial = ninitial ) else : not_formset = RulesFormset1 ( prefix = 'not' ) return query_formset , not_formset
short_docstring: Initialize advanced search form formsets based on the query.
short_docstring_tokens: Initialize advanced search form formsets based on the query .
comment: """Initialize advanced search form formsets based on the query.
      Used when the GET of advanced search includes URL parameters, in other words
      we are returning to modify the search
      """