Esempio n. 1
0
# 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 ) )
Esempio n. 2
0
    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