huskar_api/models/audit/audit.py
def create(cls, user_id, remote_addr, action, rollback_to=None):
        """Creates a new audit log.

        :param int user_id: The id of operator.
        :param str remote_addr: The IP address of operator.
        :param tuple action: Use :meth:`action_creator.make_action` to create
                             this tuple.
        :param int rollback_to: Optional. Default is :obj:`None`. If this is
                                a rollback operation, pass id of the audit log
                                want to rollback.
        :returns: The created instance.
        """
        if rollback_to is not None and cls.get(rollback_to) is None:
            raise ValueError('rollback_to is not a valid id')

        action_type, action_data, action_indices = action
        trace_all_application_events(action_type, action_data)
        action_data = json.dumps(
            action_data, sort_keys=True, ensure_ascii=False)
        if len(action_data) >= cls.MAX_AUDIT_LENGTH:
            _publish_new_action(user_id, remote_addr, action)
            raise AuditLogTooLongError('The audit log is too long.')

        instance = cls(
            user_id=user_id, remote_addr=remote_addr, action_type=action_type,
            action_data=action_data, rollback_id=rollback_to)
        try:
            with DBSession().close_on_exit(False) as db:
                db.add(instance)
                db.flush()
                for args in action_indices:
                    create_index(db, instance.id, instance.created_at, args)
        except SQLAlchemyError:
            _publish_new_action(user_id, remote_addr, action)
            raise AuditLogLostError()
        date = instance.created_at.date()
        for index_args in action_indices:
            flush_index_cache(date, index_args)
        _publish_new_action(user_id, remote_addr, action)
        return instance
Creates a new audit log.

        :param int user_id: The id of operator.
        :param str remote_addr: The IP address of operator.
        :param tuple action: Use :meth:`action_creator.make_action` to create
                             this tuple.
        :param int rollback_to: Optional. Default is :obj:`None`. If this is
                                a rollback operation, pass id of the audit log
                                want to rollback.
        :returns: The created instance.
        
Creates a new audit log.
Creates a new audit log .
def create(cls, user_id, remote_addr, action, rollback_to=None):
        if rollback_to is not None and cls.get(rollback_to) is None:
            raise ValueError('rollback_to is not a valid id')
        action_type, action_data, action_indices = action
        trace_all_application_events(action_type, action_data)
        action_data = json.dumps(
            action_data, sort_keys=True, ensure_ascii=False)
        if len(action_data) >= cls.MAX_AUDIT_LENGTH:
            _publish_new_action(user_id, remote_addr, action)
            raise AuditLogTooLongError('The audit log is too long.')
        instance = cls(
            user_id=user_id, remote_addr=remote_addr, action_type=action_type,
            action_data=action_data, rollback_id=rollback_to)
        try:
            with DBSession().close_on_exit(False) as db:
                db.add(instance)
                db.flush()
                for args in action_indices:
                    create_index(db, instance.id, instance.created_at, args)
        except SQLAlchemyError:
            _publish_new_action(user_id, remote_addr, action)
            raise AuditLogLostError()
        date = instance.created_at.date()
        for index_args in action_indices:
            flush_index_cache(date, index_args)
        _publish_new_action(user_id, remote_addr, action)
        return instance
def create ( cls , user_id , remote_addr , action , rollback_to = None ) : if rollback_to is not None and cls . get ( rollback_to ) is None : raise ValueError ( 'rollback_to is not a valid id' ) action_type , action_data , action_indices = action trace_all_application_events ( action_type , action_data ) action_data = json . dumps ( action_data , sort_keys = True , ensure_ascii = False ) if len ( action_data ) >= cls . MAX_AUDIT_LENGTH : _publish_new_action ( user_id , remote_addr , action ) raise AuditLogTooLongError ( 'The audit log is too long.' ) instance = cls ( user_id = user_id , remote_addr = remote_addr , action_type = action_type , action_data = action_data , rollback_id = rollback_to ) try : with DBSession ( ) . close_on_exit ( False ) as db : db . add ( instance ) db . flush ( ) for args in action_indices : create_index ( db , instance . id , instance . created_at , args ) except SQLAlchemyError : _publish_new_action ( user_id , remote_addr , action ) raise AuditLogLostError ( ) date = instance . created_at . date ( ) for index_args in action_indices : flush_index_cache ( date , index_args ) _publish_new_action ( user_id , remote_addr , action ) return instance
Creates a new audit log.
Creates a new audit log .
"""Creates a new audit log.

        :param int user_id: The id of operator.
        :param str remote_addr: The IP address of operator.
        :param tuple action: Use :meth:`action_creator.make_action` to create
                             this tuple.
        :param int rollback_to: Optional. Default is :obj:`None`. If this is
                                a rollback operation, pass id of the audit log
                                want to rollback.
        :returns: The created instance.
        """
The created instance.
The created instance .
cls
user_id
The id of operator.
The id of operator .
remote_addr
The IP address of operator.
The IP address of operator .
action
Use :meth:`action_creator.make_action` to create
this tuple.
Use : meth : ` action_creator . make_action ` to create this tuple .
rollback_to
Optional. Default is :obj:`None`. If this is
a rollback operation, pass id of the audit log
want to rollback.
Optional . Default is : obj : ` None ` . If this is a rollback operation pass id of the audit log want to rollback .