'Helper function to update an existing user activity log entry.'

@classmethod
def update_user_activity(cls, user, activity_type='login', update_datetime=None, language=None, suppress_save=False):

    if (not cls.is_enabled()):
        return
    if (not user):
        raise ValidationError('A    valid    user    must    always    be    specified.')
    if (not update_datetime):
        update_datetime = datetime.now()
    activity_type = cls.get_activity_int(activity_type)
    cur_log = cls.get_latest_open_log_or_None(user=user, activity_type=activity_type)
    if cur_log:
        if (cur_log.start_datetime > update_datetime):
            raise ValidationError('Update    time    must    always    be    later    than    the    login    time.')
    else:
        logging.warn(('%s:    Had    to    create    a    user    log    entry    on    an    UPDATE(%d)!    @    %s' % (user.username, activity_type, update_datetime)))
        cur_log = cls.begin_user_activity(user=user, activity_type=activity_type, start_datetime=update_datetime, suppress_save=True)
    logging.debug(('%s:    UPDATE    activity    (%d)    @    %s' % (user.username, activity_type, update_datetime)))
    cur_log.last_active_datetime = update_datetime
    cur_log.language = (language or cur_log.language)
    if (not suppress_save):
        cur_log.save()
    return cur_log
