def __init__( self, byline_search, author_nick_selections=[], affiliation_nick_selections=[], author_matched_nick_fields=None, affiliation_matched_nick_fields=None, autoaccept=False ): if author_matched_nick_fields is None: author_matched_nick_fields = [ MatchedNickField(nick_search, required=False) for nick_search in byline_search.author_nick_searches ] if affiliation_matched_nick_fields is None: affiliation_matched_nick_fields = [ MatchedNickField(nick_search, required=False) for nick_search in byline_search.affiliation_nick_searches ] self.byline_search = byline_search # whether we should continue upon successfully resolving # all byline components, as opposed to re-showing the form self.autoaccept = autoaccept self.author_nick_selections = author_nick_selections self.affiliation_nick_selections = affiliation_nick_selections self.author_matched_nick_fields = author_matched_nick_fields self.affiliation_matched_nick_fields = affiliation_matched_nick_fields
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 value_from_datadict(self, data, files, name): search_term = self.search_widget.value_from_datadict( data, files, name + '_search') if not search_term: return None explicit_lookup_requested = self.lookup_widget.value_from_datadict( data, files, name + '_lookup') byline_search = BylineSearch(search_term) # byline_search now has the appropriate number of author_nick_searches and affiliation_nick_searches # for the passed search term; we can use that to construct the right number of MatchedNickFields author_matched_nick_fields = [ MatchedNickField(nick_search, required=False) for nick_search in byline_search.author_nick_searches ] affiliation_matched_nick_fields = [ MatchedNickField(nick_search, required=False) for nick_search in byline_search.affiliation_nick_searches ] # we can now use those MatchedNickFields to extract the NickSelections from the form submission - # unless explicit_lookup_requested is set, in which case those selections are discarded if explicit_lookup_requested: author_nick_selections = [] affiliation_nick_selections = [] else: author_nick_selections = [ field.widget.value_from_datadict( data, files, name + ('_author_match_%s' % i)) for i, field in enumerate(author_matched_nick_fields) ] affiliation_nick_selections = [ field.widget.value_from_datadict( data, files, name + ('_affiliation_match_%s' % i)) for i, field in enumerate(affiliation_matched_nick_fields) ] return BylineLookup( byline_search=byline_search, author_matched_nick_fields=author_matched_nick_fields, affiliation_matched_nick_fields=affiliation_matched_nick_fields, author_nick_selections=author_nick_selections, affiliation_nick_selections=affiliation_nick_selections, autoaccept=not explicit_lookup_requested)
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'))