def match(request): initial_query = request.GET.get('q').lstrip( ) # only lstrip, because whitespace on right may be significant for autocompletion autocomplete = request.GET.get('autocomplete', False) sceners_only = request.GET.get('sceners_only', False) groups_only = request.GET.get('groups_only', False) # irritating workaround for not being able to pass an "omit this parameter" value to jquery if autocomplete == 'false' or autocomplete == 'null' or autocomplete == '0': autocomplete = False filters = {} # also doubles up as options to pass to NickSearch if sceners_only: filters['sceners_only'] = True elif groups_only: filters['groups_only'] = True if autocomplete: query = initial_query + NickVariant.autocomplete( initial_query, **filters) else: query = initial_query nick_search = NickSearch(query.rstrip(), **filters) data = { 'query': query, 'initial_query': initial_query, 'match': nick_search.match_data, } # to simulate network lag: #import time #time.sleep(2) return HttpResponse(json.dumps(data), mimetype="text/javascript")
def __init__( self, search_term=None, autoaccept=False, nick_selection=None, sceners_only=False, groups_only=False, prefer_members_of=None ): self.search_term = search_term # the search term being looked up # whether we should continue upon successfully resolving a nick, # as opposed to re-showing the form self.autoaccept = autoaccept self.nick_selection = nick_selection if prefer_members_of: group_ids = [group.id for group in prefer_members_of] else: group_ids = [] nick_search = NickSearch( search_term, sceners_only=sceners_only, groups_only=groups_only, group_ids=group_ids ) self.matched_nick_field = MatchedNickField(nick_search, required=False)
def __init__(self, search_term=None, autoaccept=False, nick_selection=None, sceners_only=False, groups_only=False): self.search_term = search_term # the search term being looked up self.autoaccept = autoaccept # whether we should continue upon successfully resolving a nick, # as opposed to re-showing the form self.nick_selection = nick_selection nick_search = NickSearch(search_term, sceners_only=sceners_only, groups_only=groups_only) self.matched_nick_field = MatchedNickField(nick_search, None)
class MatchedNickForm(forms.Form): nick = MatchedNickField(NickSearch('ra'))