Esempio n. 1
0
 def mf_do_nothing( cls, record_instance_IN, merge_from_person_IN, merge_into_person_IN, logger_name_IN = None, *args, **kwargs ):
     
     '''
     merge function, does nothing.
     '''
     
     # return reference
     status_OUT = StatusContainer()
     
     # declare variables
     me = "mf_do_nothing"
     debug_message = ""
     my_logger_name = ""
     
     # set logger name.
     if ( ( logger_name_IN is not None ) and ( logger_name_IN != "" ) ):
     
         # got one - use it.
         my_logger_name = logger_name_IN
     
     else:
     
         # not set.  Use default.
         my_logger_name = cls.LOGGER_NAME
     
     #-- END check to see if loger name passed in. --#
     
     debug_message = "Doing nothing with record: " + str( record_instance_IN ) + "; merge from person = " + str( merge_from_person_IN ) + "; merge into person = " + str( merge_into_person_IN )
     LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name )
     
     # init status.
     status_OUT = status_OUT.set_status_code( StatusContainer.STATUS_CODE_SUCCESS )
     
     return status_OUT
Esempio n. 2
0
 def output_debug( cls, message_IN, method_IN = "", indent_with_IN = "", logger_name_IN = "" ):
     
     '''
     Accepts message string.  If debug is on, logs it.  If not,
        does nothing for now.
     '''
     
     # declare variables
 
     # got a message?
     if ( message_IN ):
     
         # only print if debug is on.
         if ( cls.DEBUG == True ):
         
             # use Logging Helper to log messages.
             LoggingHelper.output_debug( message_IN, method_IN, indent_with_IN, logger_name_IN )
    def output_debug( cls, message_IN, method_IN = "", indent_with_IN = "", logger_name_IN = "", debug_flag_IN = None ):
        
        '''
        Accepts message string.  If debug is on, logs it.  If not,
           does nothing for now.
        '''
        
        # declare variables
        my_debug_flag = False
        my_logger_name = ""
        
        if ( debug_flag_IN is None ):
        
            my_debug_flag = cls.DEBUG
            
        else:
        
            my_debug_flag = debug_flag_IN
        
        #-- END check to see if debug flag. --#
    
        # only print if debug is on.
        if ( my_debug_flag == True ):
        
            # got a logger name?
            my_logger_name = cls.LOGGER_NAME
            if ( ( logger_name_IN is not None ) and ( logger_name_IN != "" ) ):
            
                # use logger name passed in.
                my_logger_name = logger_name_IN
                
            #-- END check to see if logger name --#

            # call method in LoggingHelper.
            LoggingHelper.output_debug( message_IN,
                                        method_IN = method_IN,
                                        indent_with_IN = indent_with_IN,
                                        logger_name_IN = my_logger_name )
        
        #-- END check to see if debug is on --#
    
    #-- END method output_debug() --#

#-- END class DjangoViewHelper --#
Esempio n. 4
0
def output_debug( message_IN, method_IN = "", indent_with_IN = "", logger_name_IN = "" ):
    
    '''
    Accepts message string.  If debug is on, logs it.  If not,
       does nothing for now.
    '''
    
    # declare variables
    my_message = ""
    my_logger = None
    my_logger_name = ""

    # got a message?
    if ( message_IN ):
    
        # only print if debug is on.
        if ( DEBUG == True ):
        
            my_message = message_IN
        
            # got a method?
            if ( method_IN ):
            
                # We do - append to front of message.
                my_message = "In " + method_IN + ": " + my_message
                
            #-- END check to see if method passed in --#
            
            # indent?
            if ( indent_with_IN ):
                
                my_message = indent_with_IN + my_message
                
            #-- END check to see if we indent. --#
        
            # debug is on.  Start logging rather than using print().
            #print( my_message )
            
            # got a logger name?
            my_logger_name = "sourcenet.lookups"
            if ( ( logger_name_IN is not None ) and ( logger_name_IN != "" ) ):
            
                # use logger name passed in.
                my_logger_name = logger_name_IN
                
            #-- END check to see if logger name --#
                
            # get logger
            my_logger = LoggingHelper.get_a_logger( my_logger_name )
            
            # log debug.
            my_logger.debug( my_message )
    def potter_pi( cls, value_list_1_IN, value_list_2_IN, coder_count_IN, option_count_IN ):

        '''
        Accepts two lists of values that should be the same length, a count of
            the number of coders, and a count of the options from which the
            coders were choosing.  Uses coder count and option count to
            calculate probability of chance agreement, then uses that
            probability along with percentage agreement between the two lists
            to calculate Scott's Pi:
            - Pi = ( Po - Pe ) / ( 1 - Pe )
            - WHERE:
                - Po = observed agreement
                - Pe = modified probability of change agreement = 1 / ( coding_option_count ^ ( coder_count - 1 ) )
        Used in calculating Scott's Pi formula, modified per Potter and
            Levine-Donnerstein, 1999, to base chance agreement on numbers of
            choices and coders, not the distribution of values, since
            Krippendorff's Alpha breaks down when there is little variance in a
            set of coding values.

            - Potter, W. J., & Levine-Donnerstein, D. (1999). Rethinking validity and reliability in content analysis. Journal of Applied Communication Research, 27(3), 258-284. http://doi.org/10.1080/00909889909365539
        '''
        
        # return reference
        value_OUT = None
        
        # declare variables
        me = "StatsHelper.potter_pi"
        list_1_count = -1
        list_2_count = -1
        chance_agreement = -1
        percentage_agree = -1

        # got lists?
        if ( ( value_list_1_IN is not None ) and ( value_list_2_IN is not None ) ):
        
            # get counts of values in each list.
            list_1_count = len( value_list_1_IN )
            list_2_count = len( value_list_2_IN )
            
            # counts equal?
            if ( list_1_count == list_2_count ):
            
                # counts greater than 0?
                if ( list_1_count > 0 ):
                
                    # lists are good - got count of options?
                    if ( ( option_count_IN is not None ) and ( option_count_IN != "" ) and ( option_count_IN > 0 ) ):
                        
                        # got count of coders?
                        if ( ( coder_count_IN is not None ) and ( coder_count_IN != "" ) and ( coder_count_IN > 0 ) ):
                        
                            # yes - calculate probability of chance agreement...
                            chance_agreement = cls.potter_pi_calc_p_sub_e( coder_count_IN = coder_count_IN, option_count_IN = option_count_IN )

                            # ...then percentage agreement between the two numpy
                            #    arrays...
                            percentage_agree = cls.percentage_agreement( value_list_1_IN, value_list_2_IN )
                            
                            # ...and, finally, Scott's Pi.
                            value_OUT = ( percentage_agree - chance_agreement ) / ( 1.0 - chance_agreement )
            
                        else:
            
                            # no count of coders.  Return None.
                            value_OUT = None                
            
                        #-- END check to see if count of coders passed in. --#
                    
                    else:
                    
                        # no option count.  Return None.
                        value_OUT = None
                    
                    #-- END check to see if count of options passed in. --#
        
                else:
                
                    # nothing in lists.
                    LoggingHelper.output_debug( "ERROR - lists are not the same length ( " + str( list_1_count ) + " != " + str( list_2_count ) + " ), so can't calculate percentage agreement.", method_IN = me )
                    value_OUT = None
                    
                #-- END check to make sure something is in list. --#

            else:
            
                # lists of different length...
                LoggingHelper.output_debug( "ERROR - lists are not the same length ( " + str( list_1_count ) + " != " + str( list_2_count ) + " ), so can't calculate percentage agreement.", method_IN = me )
                value_OUT = None

            #-- END check to make sure list values are the same length. --#
        
        else:
        
            # one or both lists is empty.  Error.
            LoggingHelper.output_debug( "ERROR - one or both lists is None - Need 2 lists of values to calculate percentage agreement.", method_IN = me )
            value_OUT = None
            
        #-- END check to make sure lists passed in --#

        return value_OUT
    def percentage_agreement( cls, value_list_1_IN, value_list_2_IN ):

        '''
        Accepts two lists of values that must be the same length.  Calculates
            the percentage of pairs of numbers between the two groups where the
            values are the same.  Returns the percentage of agreement as a
            decimal between 0 and 1 (so you'll need to multiply by 100 to get
            percentage).
            
        If error, returns None.
        '''
        
        # return reference
        value_OUT = None
        
        # declare variables
        me = "StatsHelper.percentage_agreement"
        list_1_count = -1
        list_2_count = -1
        work_df = None
        column_name_list_1 = ""
        column_name_list_2 = ""
        column_name_is_equal = ""
        equal_sum = -1
        
        # got lists?
        if ( ( value_list_1_IN is not None ) and ( value_list_2_IN is not None ) ):
        
            # get counts of values in each list.
            list_1_count = len( value_list_1_IN )
            list_2_count = len( value_list_2_IN )
            
            # counts equal?
            if ( list_1_count == list_2_count ):
            
                # counts greater than 0?
                if ( list_1_count > 0 ):
                
                    # init column name holders
                    column_name_list_1 = "value_list_1"
                    column_name_list_2 = "value_list_2"
                    column_name_is_equal = "is_equal"
    
                    # combine into one data frame.
                    work_df = pandas.DataFrame()
                    work_df[ column_name_list_1 ] = value_list_1_IN
                    work_df[ column_name_list_2 ] = value_list_2_IN
                    
                    # make a new column that is 1 if values are the same, 0 if not.
                    work_df[ column_name_is_equal ] = numpy.where( work_df[ column_name_list_1 ] == work_df[ column_name_list_2 ], 1, 0 )
                    
                    # get sum of "is_equal" column.
                    equal_sum = work_df[ column_name_is_equal ].sum()
                    
                    # value out is equal_sum / list_1_count
                    # - relies on "from __future__ import division" above
                    value_OUT = equal_sum / list_1_count
                    
                else:
                
                    # nothing in lists.
                    LoggingHelper.output_debug( "ERROR - lists are not the same length ( " + str( list_1_count ) + " != " + str( list_2_count ) + " ), so can't calculate percentage agreement.", method_IN = me )
                    value_OUT = None
                    
                #-- END check to make sure something is in list. --#

            else:
            
                # lists of different length...
                LoggingHelper.output_debug( "ERROR - lists are not the same length ( " + str( list_1_count ) + " != " + str( list_2_count ) + " ), so can't calculate percentage agreement.", method_IN = me )
                value_OUT = None

            #-- END check to make sure list values are the same length. --#
        
        else:
        
            # one or both lists is empty.  Error.
            LoggingHelper.output_debug( "ERROR - one or both lists is None - Need 2 lists of values to calculate percentage agreement.", method_IN = me )
            value_OUT = None
            
        #-- END check to make sure lists passed in --#
        
        return value_OUT
Esempio n. 7
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
Esempio n. 8
0
    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
Esempio n. 9
0
    def merge_records( cls, record_qs_IN, merge_from_id_IN, merge_into_id_IN, do_delete_IN = False, logger_name_IN = None, *args, **kwargs ):
        
        '''
        accepts a QuerySet of related records of a specific type for the person
            we are merging INTO another person (the FROM user).  Loops over them
            to get a list of their IDs, so we can interact with them independent
            of the RelatedManager (not sure if this is necessary, but an
            overabundance of caution).  For the type, uses a dictionary that
            maps class name to function pointers to find and call a function to
            merge that class's rows.  Then, we loop over the rows once again
            to delete() each of them.

        preconditions: Deletes the merge_from person's data.  BE CAREFUL.
        postconditions: merges all the rows from the merge from person into the
            rows that belong to the merge into person, then deletes the rows for
            the merge_from person.  Again, deletes the merge_from person's data.
            BE CAREFUL.
        ''' 
        
        # return reference
        status_OUT = StatusContainer()
        
        # declare variables
        me = "delete_records"
        my_logger_name = ""
        debug_message = ""
        from_person = None
        into_person = None
        current_record = None
        related_class = None
        related_id = ""
        related_id_list = []
        merge_function = None
        related_qs = None
        related_record = None
        merge_status = None
        
        # set logger name.
        if ( ( logger_name_IN is not None ) and ( logger_name_IN != "" ) ):
        
            # got one - use it.
            my_logger_name = logger_name_IN
        
        else:
        
            # not set.  Use default.
            my_logger_name = cls.LOGGER_NAME
        
        #-- END check to see if loger name passed in. --#
        
        # got a QuerySet?
        if ( isinstance( record_qs_IN, QuerySet ) == True ):
            
            # yes.  anything in it?
            if ( record_qs_IN.count() > 0 ):
            
                debug_message = "QuerySet IS NOT empty."
                LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name )
                
                # load Person instances for the from and the into.
                from_person = Person.objects.get( pk = merge_from_id_IN )
                into_person = Person.objects.get( pk = merge_into_id_IN )                

                # loop over records in related set to get class and get IDs.
                #     Don't make changes here yet.  Wait so we aren't looping
                #     inside a related 
                for current_record in record_qs_IN:
                
                    debug_message = "Current record: " + str( current_record )
                    LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "====> ", logger_name_IN = my_logger_name )
                
                    # is related class set?
                    if ( related_class is None ):
                    
                        related_class = type( current_record )
                        
                    #-- END check to see if we have related class --#
                    
                    # get ID and add it to list.
                    record_id = current_record.id
                    record_id_list.append( record_id )
                    
                #-- END loop over records to get ID list. --#
                
                # look up the record merge function for this class.
                merge_function = cls.get_merge_function( related_class )
                
                # now, use the class to get a result set of the same rows that
                #     is not related to one of the persons.
                related_qs = related_class.objects.filter( id__in = record_id_list )
                
                # in theory, we now have a QuerySet of the related records for
                #     the person we are merging from.  Loop and call the merge
                #     function on each.
                for related_record in related_qs:
                
                    # call the merge_function (just merge, don't delete).
                    merge_status = merge_function( related_record, from_person, into_person )
                    
                #-- END merge loop --#
                
                # do we delete?
                if ( do_delete_IN == True ):
                
                    # OK...
                    for related_record in related_qs:
                    
                        # delete()
                        related_record.delete()
                        
                        debug_message = "DELETED!!!"
                        LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "========> ", logger_name_IN = my_logger_name )
                    
                    #-- END merge loop --#
                    
                #-- END check to see if we delete. --#
                
                # status is success.
                status_OUT.set_status_code( StatusContainer.STATUS_CODE_SUCCESS )

            else:
            
                debug_message = "QuerySet is EMPTY."
                LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "====> ", logger_name_IN = my_logger_name )
            
            #-- END check to see if anything in list. --#
            
        else:
        
            debug_message = "record_qs_IN is not a QuerySet: " + str( record_qs_IN )
            LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "====> ", logger_name_IN = my_logger_name )
            status_OUT.set_status_code( StatusContainer.STATUS_CODE_ERROR )
            status_OUT.add_message( debug_message )
            
        #-- END check to see if QuerySet instance passed in. --#
        
        return status_OUT
    def is_form_empty( cls, form_IN, logger_name_IN = "", *args, **kwargs ):
        
        '''
        Accepts django Form or ModelForm in form_IN.  Goes through the fields in
            the form and checks to see if any has been populated.  If not,
            returns True (it is empty!).  If there is a value in any of them,
            returns False (not empty).
            
        Preconditions: Must be called after is_valid() is called on the form.
            If not, there will not be any "cleaned_data".
        '''
        
        # return reference
        is_empty_OUT = True
        
        # declare variables
        me = "is_form_empty"
        my_logger_name = ""
        debug_message = ""
        my_cleaned_data = None
        input_counter = -1
        current_key = None
        current_value = None
        is_value_empty = False
        
        # set logger name.
        if ( ( logger_name_IN is not None ) and ( logger_name_IN != "" ) ):
        
            # got one - use it.
            my_logger_name = logger_name_IN
        
        else:
        
            # not set.  Use default.
            my_logger_name = cls.LOGGER_NAME
        
        #-- END check to see if loger name passed in. --#
        
        # got a form?
        if ( form_IN is not None ):
        
            # get cleaned data.
            my_cleaned_data = form_IN.cleaned_data
            
            # loop over keys
            input_counter = 0
            is_empty_OUT = True
            for current_key in six.iterkeys( my_cleaned_data ):
            
                # increment counter
                input_counter += 1
    
                # get value.
                current_value = my_cleaned_data.get( current_key, cls.IAMEMPTY )
                
                debug_message = "input " + str( input_counter ) + ": key = " + str( current_key ) + "; value = \"" + str( current_value ) + "\" ( class = \"" + str( current_value.__class__ ) + "\" )"
                LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name )
                
                # empty?
                is_value_empty = cls.is_value_empty( current_value )
                if ( is_value_empty == False ):
                
                    # value is not empty, so form is not empty.
                    is_empty_OUT = False
                    
                #-- END check to see if value is empty --#

            #-- END loop over keys in data dictionary --#
            
        else:
        
            # no form passed in.  I'd call that empty...
            is_empty_OUT = True
        
        #-- END check to see if form passed in. --#

        return is_empty_OUT
    def data_to_html_as_hidden_inputs( cls, form_IN, logger_name_IN = "", *args, **kwargs ):

        '''
        Accepts django Form or ModelForm in form_IN.  Goes through the fields in
            the form and for each, creates HTML string of a hidden input that
            contains the value.  If no data, returns empty string.  If error
            returns None.
            
        Preconditions: Must be called after is_valid() is called on the form.
            If not, there will not be any "cleaned_data".
        '''
        
        # return reference
        html_OUT = ""

        # declare variables
        me = "data_to_html_as_hidden_inputs"
        my_logger_name = ""
        debug_message = ""
        my_cleaned_data = None
        input_counter = -1
        current_key = None
        current_value = None
        current_value_string = ""
        input_html = ""
        is_value_empty = False
        value_list = None
        current_instance = None
        current_id = -1
        
        # set logger name.
        if ( ( logger_name_IN is not None ) and ( logger_name_IN != "" ) ):
        
            # got one - use it.
            my_logger_name = logger_name_IN
        
        else:
        
            # not set.  Use default.
            my_logger_name = cls.LOGGER_NAME
        
        #-- END check to see if loger name passed in. --#
        
        # got a form?
        if ( form_IN is not None ):
        
            # get cleaned data.
            my_cleaned_data = form_IN.cleaned_data
            
            # loop over keys
            input_counter = 0
            for current_key in six.iterkeys( my_cleaned_data ):
            
                # increment counter
                input_counter += 1
    
                # get value.
                current_value = my_cleaned_data.get( current_key, cls.IAMEMPTY )
                
                debug_message = "input " + str( input_counter ) + ": key = " + str( current_key ) + "; value = \"" + str( current_value ) + "\" ( class = \"" + str( current_value.__class__ ) + "\" )"
                LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name )
                
                # default current_value_string to current_value
                current_value_string = current_value
                
                # empty?
                is_value_empty = cls.is_value_empty( current_value )
                if ( is_value_empty == True ):
                
                    # value is empty.  Set to empty string.
                    current_value_string = ""
                
                else:
                
                    # not empty - convert value to string if needed.
                    if ( current_value is not None ):
                    
                        # got a QuerySet?
                        if ( isinstance( current_value, QuerySet ) == True ):
                            
                            # yes.  anything in it?
                            if ( current_value.count() > 0 ):
    
                                debug_message = "QuerySet IS NOT empty."
                                LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "====> ", logger_name_IN = my_logger_name )
                                
                                # ! convert QuerySet to list of IDs?
                                value_list = []
                                for current_instance in current_value:
                                
                                    # add string ID value to list.
                                    current_id = current_instance.id
                                    value_list.append( str( current_id ) )
                                    
                                #-- END loop over instances in QuerySet --#
                                
                                # and, combine into a comma-delimited string list
                                current_value_string = ",".join( value_list )
                        
                            else:
                            
                                debug_message = "QuerySet is EMPTY."
                                LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "====> ", logger_name_IN = my_logger_name )
                                
                                # set value string to ""
                                current_value_string = ""
                            
                            #-- END check to see if anything in QuerySet. --#
            
                        elif ( isinstance( current_value, list ) == True ):
                            
                            # yes.  Is there anything in list?
                            if ( len( current_value ) > 0 ):
                                    
                                debug_message = "LIST IS NOT empty."
                                LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "====> ", logger_name_IN = my_logger_name )
                                
                                # combine into a comma-delimited string list.
                                current_value_string = ",".join( current_value )
            
                            else:
                                    
                                debug_message = "LIST is EMPTY."
                                LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "====> ", logger_name_IN = my_logger_name )
                                    
                                # set value string to ""
                                current_value_string = ""
                            
                            #-- END check to see if anything in list. --#
                                
                        else:
                            
                            # not list - probably a string.
                            if ( ( current_value != "" ) and ( current_value != cls.IAMEMPTY ) ):
                                
                                debug_message = "STRING IS NOT empty."
                                LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "====> ", logger_name_IN = my_logger_name )
                                
                                # just use the value as-is
                                current_value_string = current_value
            
                            else:
                                
                                debug_message = "STRING is EMPTY."
                                LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "====> ", logger_name_IN = my_logger_name )
                                
                                # set value string to ""
                                current_value_string = ""                            
                                
                            #-- END check to see if empty string, or set to cls.IAMEMPTY --#
                            
                        #-- END check to see if list. --#
                    
                    else:
                    
                        # empty.
                        debug_message = "Value is None, and so EMPTY."
                        LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "====> ", logger_name_IN = my_logger_name )
                        
                        # set value string to ""
                        current_value_string = ""                            
                    
                    #-- END check to see if None. --#
                
                #-- END check to see if value is empty...else not empty --#

                # render <input> HTML
                input_html = "<input type=\"hidden\" name=\"" + str( current_key ) +  "\" value=\"" + str( current_value_string ) + "\" />"

                # add to HTML
                html_OUT += input_html

            #-- END loop over keys in data dictionary --#
            
        else:
        
            # no form passed in.  No HTML returned.
            html_OUT = ""
        
        #-- END check to see if form passed in. --#

        return html_OUT
    def is_value_empty( cls, value_IN, logger_name_IN = "", *args, **kwargs ):
        
        """
        Looks at value passed in, decides if it is empty.  Returns True if
            empty, False if not.
        """
    
        # return reference
        is_empty_OUT = True
        
        # declare variables
        me = "is_value_empty"
        my_logger_name = ""
        debug_message = ""
        current_value = None
    
        # set logger name.
        if ( ( logger_name_IN is not None ) and ( logger_name_IN != "" ) ):
        
            # got one - use it.
            my_logger_name = logger_name_IN
        
        else:
        
            # not set.  Use default.
            my_logger_name = cls.LOGGER_NAME
        
        #-- END check to see if loger name passed in. --#
        
        # get value.
        current_value = value_IN
        
        debug_message = "value = \"" + str( current_value ) + "\" ( class = \"" + str( current_value.__class__ ) + "\" )"
        LoggingHelper.output_debug( debug_message, method_IN = me, logger_name_IN = my_logger_name )
        
        # empty?
        is_empty_OUT = True
        if ( current_value is not None ):
            
            # got a QuerySet?
            if ( isinstance( current_value, QuerySet ) == True ):
                
                # yes.  anything in it?
                if ( current_value.count() > 0 ):
                
                    is_empty_OUT = False
                    
                    debug_message = "QuerySet IS NOT empty."
                    LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "====> ", logger_name_IN = my_logger_name )
            
                else:
                
                    debug_message = "QuerySet is EMPTY."
                    LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "====> ", logger_name_IN = my_logger_name )
                
                #-- END check to see if anything in list. --#

            elif ( isinstance( current_value, list ) == True ):
                
                # yes.  Is there anything in list?
                if ( len( current_value ) > 0 ):
                        
                    is_empty_OUT = False
                        
                    debug_message = "LIST IS NOT empty."
                    LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "====> ", logger_name_IN = my_logger_name )

                else:
                        
                    debug_message = "LIST is EMPTY."
                    LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "====> ", logger_name_IN = my_logger_name )
                        
                #-- END check to see if anything in list. --#
                    
            else:
                
                # not list - probably a string.
                if ( ( current_value != "" ) and ( current_value != cls.IAMEMPTY ) ):
                    
                    # not an empty string.
                    is_empty_OUT = False
                    
                    debug_message = "STRING IS NOT empty."
                    LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "====> ", logger_name_IN = my_logger_name )

                else:
                    
                    debug_message = "STRING is EMPTY."
                    LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "====> ", logger_name_IN = my_logger_name )
                    
                #-- END check to see if empty string, or set to cls.IAMEMPTY --#
                
            #-- END check to see if list. --#
        
        else:
        
            # empty.
            debug_message = "Value is None, and so EMPTY."
            LoggingHelper.output_debug( debug_message, method_IN = me, indent_with_IN = "====> ", logger_name_IN = my_logger_name )
            is_empty_OUT = True
        
        #-- END check to see if empty. --#
        
        return is_empty_OUT