Source code for searches.utils

# Copyright (C) 2017 Semester.ly Technologies, LLC
#
# Semester.ly is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Semester.ly is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

import operator
from django.db.models import Q
from timetable.models import Course
from functools import reduce





[docs]def course_name_contains_token(token): """Returns a query set of courses where tokens are contained in code or name.""" return ( Q(code__icontains=token) | Q(name__icontains=token.replace("&", "and")) | Q(name__icontains=token.replace("and", "&")) )