def get_property_list_value( cls, application_IN, property_name_IN, default_IN = None, delimiter_IN = ",", *args, **kwargs ): # return reference value_OUT = None # declare variables prop_value = None # get property prop_value = cls.get_property_value( application_IN, property_name_IN, default_IN ) # convert to int if not None. if ( prop_value != None ): # Not none - convert to int. value_OUT = ListHelper.get_value_as_list( prop_value, delimiter_IN ) else: # None - empty list. value_OUT = [] #-- END check to make sure we don't try to convert None to list. --# return value_OUT
def get_dict_value_as_list( cls, dict_IN, name_IN, default_IN = [], delimiter_IN = ',' ): # return reference list_OUT = [] # declare variables me = "get_dict_value_as_list" list_param_value = "" working_list = [] current_value = "" current_value_clean = "" missing_string = "get_list_param-missing" # first, try getting raw param, see if it is already a list. # get raw value list_param_value = cls.get_dict_value( dict_IN, name_IN, default_IN = missing_string ) # check if None if ( list_param_value is None ): # None is a valid value - return it. list_OUT = list_param_value #print( "None!" ) # check if list elif ( isinstance( list_param_value, list ) == True ): # already a list - return it. list_OUT = list_param_value #print( "List! : " + str( list_param_value ) ) # string elif ( isinstance( list_param_value, six.string_types ) == True ): #print( "String! : " + str( list_param_value ) ) # it is a string. Is it missing_string? if ( list_param_value == missing_string ): # value not present in dictionary - return default. list_OUT = default_IN # empty string? elif ( list_param_value == "" ): # empty string - return default list_OUT = default_IN else: # Not missing, and not an empty string. Try parsing as # delimited list. # get list param's original value as str() list_param_value = cls.get_dict_value_as_str( dict_IN, name_IN, missing_string ) # print( "====> list param value: " + list_param_value ) # sanity check - still got a value? if ( ( list_param_value != "" ) and ( list_param_value != missing_string ) ): # yes - use ListHelper to convert to list. list_OUT = ListHelper.get_value_as_list( list_param_value, delimiter_IN ) elif list_param_value == "": # empty string - return default. list_OUT = default_IN elif list_param_value == missing_string: # missing key-value pair list_OUT = default_IN else: # not sure how we got here - return default. list_OUT = default_IN #-- END check to see what was in value. --# #-- END check for empty string --# else: # not None, a list or a string... place the reference in a # single-item list. list_OUT = [] list_OUT.append( list_param_value ) #-- END check to see if already a list --# return list_OUT
def lookup_person_by_id( cls, request_inputs_IN, person_qs_IN = None, response_dictionary_IN = None, *args, **kwargs ): ''' Accepts request inputs we'd expect to contain the fields defined for this form. Uses this information to lookup Persons 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_id" my_logger_name = "sourcenet.forms.PersonLookupByIDForm" debug_message = "" request_inputs = None person_qs = None person_id_in_list_string = "" person_id_in_list = [] article_author_id = -1 article_subject_id = -1 article_author = None article_subject = None temp_list = [] # first, make sure we have request inputs. if ( request_inputs_IN is not None ): # store off the inputs. request_inputs = request_inputs_IN # got a person qs? if ( person_qs_IN is not None ): person_qs = person_qs_IN #-- END check to see if person_qs --# # get values from form person_id_in_list_string = request_inputs.get( "person_id_in_list", None ) # convert string to list if ( ( person_id_in_list_string is not None ) and ( person_id_in_list_string != "" ) ): # got something. Try to coerce it into a python list. person_id_in_list = ListHelper.get_value_as_list( person_id_in_list_string, delimiter_IN = "," ) debug_message = "found person ID list - using it." LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name ) else: # no ID list passed in. Make an empty list. person_id_in_list = [] debug_message = "no straight up list of person IDs passed in - creating empty list," LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name ) #-- END check to see if person ID list passed in --# # see if there are Article_Subject or Article_Author IDs. article_author_id = request_inputs.get( "article_author_id", None ) article_subject_id = request_inputs.get( "article_subject_id", None ) debug_message = "article_author_id: " + str( article_author_id ) LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name ) debug_message = "article_subject_id: " + str( article_subject_id ) LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name ) # Article_Author? if ( ( article_author_id is not None ) and ( article_author_id != "" ) and ( int( article_author_id ) > 0 ) ): try: # Got one. Look up instance based on ID. article_author = Article_Author.objects.get( pk = article_author_id ) debug_message = "found Article_Author: " + str( article_author ) LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name ) # see if any associated Persons. temp_list = article_author.get_associated_person_id_list() if ( ( temp_list is not None ) and ( isinstance( temp_list, list ) == True ) and ( len( temp_list ) > 0 ) ): # got something in list. Append it to the end of # the person_id_in_list. person_id_in_list.extend( temp_list ) #-- END check to see if associated Persons. --# except Article_Author.DoesNotExist as dne: debug_message = "No Article_Author found for ID " + str( article_author_id ) LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name ) if ( response_dictionary_IN is not None ): response_dictionary_IN[ 'output_string' ] = debug_message #-- END check to see if response dictionary. --# #-- END try/except lookup for Article_Author --# #-- END check to see if article_author_id --# # Article_Subject? if ( ( article_subject_id is not None ) and ( article_subject_id != "" ) and ( int( article_subject_id ) > 0 ) ): try: # Got one. Look up instance based on ID. article_subject = Article_Subject.objects.get( pk = article_subject_id ) debug_message = "found Article_Subject: " + str( article_subject ) LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name ) # see if any associated Persons. temp_list = article_subject.get_associated_person_id_list() debug_message = "Associated Person IDs in Article_Subject: " + str( article_subject ) + ", ID list = " + str( temp_list ) LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name ) if ( ( temp_list is not None ) and ( isinstance( temp_list, list ) == True ) and ( len( temp_list ) > 0 ) ): # got something in list. Append it to the end of # the person_id_in_list. person_id_in_list.extend( temp_list ) #-- END check to see if associated Persons. --# except Article_Subject.DoesNotExist as dne: debug_message = "No Article_Subject found for ID " + str( article_subject_id ) LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name ) if ( response_dictionary_IN is not None ): response_dictionary_IN[ 'output_string' ] = debug_message #-- END check to see if response dictionary. --# #-- END try/except lookup for Article_Author --# #-- END check to see if article_subject_id --# debug_message = "Before filtering: person_id_in_list = " + str( person_id_in_list ) + "; person_qs = " + str( person_qs ) LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name ) # anything in person_id_in_list? if ( ( person_id_in_list is not None ) and ( isinstance( person_id_in_list, list ) == True ) and ( len( person_id_in_list ) > 0 ) ): # there are IDs to look for. Do we have a QuerySet # already? if ( person_qs is None ): # no. Initialize to all() person_qs = Person.objects.all() #-- END check to see if Person QuerySet --# # filter. person_qs = person_qs.filter( pk__in = person_id_in_list ) #-- END check to see if anything in ID list. --# 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