def get_query( self, q, request ): """ return a query set. you also have access to request.user if needed. """ # return reference query_set_OUT = None # declare variables me = "get_query" my_logger_name = "" person_name = "" match_count = -1 name_part_list = None human_name = None # init logging info my_logger_name = "sourcenet.lookups.PersonLookup" # store q in a real variable person_name = q # output string passed in output_debug( "q = " + str( q ), method_IN = me, logger_name_IN = my_logger_name ) # is the q a number and is it the ID of an contributor? query_set_OUT = self.get_instance_query( person_name, request, self.my_class ) # got anything back? if ( query_set_OUT is None ): # No exact match for q as ID. Try Person.find_person_from_name() query_set_OUT = Person.find_person_from_name( person_name ) #-- END retrieval of QuerySet when no ID match. --# return query_set_OUT
# look at how that turned out: print( "Empty HumanName?:" ) print( Person.HumanName_to_str( manual ) ) # override parsed values with correct name parts manual.first = "Van" manual.last = "Conway" # look at how that turned out: print( "after manual configuration:" ) print( Person.HumanName_to_str( manual ) ) # now, try some lookups # let the lookup parse the name. test1 = Person.look_up_person_from_name( name ) print( "test1 = " + str( test1 ) ) # pass in manually configured HumanName test2 = Person.look_up_person_from_name( name, manual ) print( "test2 = " + str( test2 ) ) # try exact match test3 = Person.look_up_person_from_name( name, manual, do_strict_match_IN = True ) print( "test3 (strict) = " + str( test3 ) ) # how to best deal with two word names? name_part_list = name.split() name_part_count = len( name_part_list ) print( "Name list: " + str( name_part_list ) + "; len: " + str( name_part_count ) )
def lookup_person_by_name( cls, request_inputs_IN, lookup_type_IN = None, person_qs_IN = None, *args, **kwargs ): ''' Accepts request inputs we'd expect to contain the fields defined for this form and a lookup type that is one of those in the form class PersonLookupTypeForm defined above. Uses this information to lookup a person and returns the QuerySet that contains the results of the lookup. If error, returns None. ''' # return reference qs_OUT = None # declare variables me = "lookup_person_by_name" my_logger_name = "sourcenet.forms.PersonLookupByNameForm" debug_message = "" request_inputs = None lookup_type = "" person_qs = None my_person_details = None human_name = None name_string = None do_strict_match = False do_partial_match = False # first, make sure we have request inputs. if ( request_inputs_IN is not None ): # store off the inputs. request_inputs = request_inputs_IN # and the lookup type. lookup_type = lookup_type_IN debug_message = "lookup_type = " + str( lookup_type ) LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name ) # got a person qs? if ( person_qs_IN is not None ): person_qs = person_qs_IN #-- END check to see if person_qs --# # retrieve Person records specified by the input parameters, # ordered by Last Name, then First Name. Then, create HTML # output of list of articles. For each, output (to start): # - Person string # populate PersonDetails from request_inputs: my_person_details = PersonDetails.get_instance( request_inputs ) # get HumanName instance... human_name = my_person_details.to_HumanName() name_string = str( human_name ) # do lookup based on lookup_type if ( lookup_type == PersonLookupTypeForm.PERSON_LOOKUP_TYPE_GENERAL_QUERY ): debug_message = "performing general query" LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name ) # not strict do_strict_match = False do_partial_match = True person_qs = Person.look_up_person_from_name( name_IN = name_string, parsed_name_IN = human_name, do_strict_match_IN = do_strict_match, do_partial_match_IN = do_partial_match, qs_IN = person_qs ) elif ( lookup_type == PersonLookupTypeForm.PERSON_LOOKUP_TYPE_EXACT_QUERY ): debug_message = "performing exact query" LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name ) # strict do_strict_match = True do_partial_match = False person_qs = Person.look_up_person_from_name( name_IN = name_string, parsed_name_IN = human_name, do_strict_match_IN = do_strict_match, do_partial_match_IN = do_partial_match, qs_IN = person_qs ) else: debug_message = "no lookup_type, so doing general query" LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name ) # default to not strict do_strict_match = False do_partial_match = True person_qs = Person.look_up_person_from_name( name_IN = name_string, parsed_name_IN = human_name, do_strict_match_IN = do_strict_match, do_partial_match_IN = do_partial_match, qs_IN = person_qs ) #-- END decide how to lookup based on lookup_type --# else: debug_message = "no request_inputs_IN, so no query - returning None." LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name ) person_qs = None #-- END check to see if request_inputs_IN --# # return person_qs qs_OUT = person_qs return qs_OUT