Doh, here it is with hopefully fixed formatting:

            """ The following code searches records based on query and
            checkboxes checked in the search form. Query can have
words
            with minus in front (e.g.: -word) to exclude terms. There
are
            three checkboxes, titles, problems and solutions; any
            combination can be checked. Respective field in db table
is
            searched when checkbox for it is checked.  """

            # perform search
            r = Solution.objects.all()
            queries = {}
            for word in qw + exclude:
                queries[word] = []
            if titles == "on":
                for word in qw + exclude:
                    queries[word].append(Q(title__icontains=word))
            if solutions == "on":
                for word in qw + exclude:
                    queries[word].append(Q(solution__icontains=word))

            # if nothing is checked (or problems), search problems
            # note that we're implicitly using last word created by
code
            # above, because the number of types of search checked
will
            # be the same for all words.
            if problems == "on" or not queries[word]:
                for word in qw + exclude:
                    queries[word].append(Q(problem__icontains=word))

            if len(queries[word]) == 3:
                for w in qw: r = r.filter(
                  queries[w][0] | queries[w][1] | queries[w][2])
                for w in exclude: r = r.exclude(
                  queries[w][0] | queries[w][1] | queries[w][2])
            if len(queries[word]) == 2:
                for w in qw: r = r.filter(
                  queries[w][0] | queries[w][1])
                for w in exclude: r = r.exclude(
                  queries[w][0] | queries[w][1])
            else:
                for w in qw: r = r.filter(queries[w][0])
                for w in exclude: r = r.exclude(queries[w][0])


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to