Audit Logs Package

Submodules

Models

class seed.audit_logs.models.AuditLog(*args, **kwargs)

Bases: django_extensions.db.models.TimeStampedModel

An audit log of events and notes. Inherits created and modified from TimeStampedModel

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

content_object

Provide a generic many-to-one relation through the content_type and object_id fields.

This class also doubles as an accessor to the related object (similar to ForwardManyToOneDescriptor) by adding itself as a model attribute.

content_type

Accessor to the related object on the forward side of a many-to-one or one-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

child.parent is a ForwardManyToOneDescriptor instance.

get_audit_type_display(*moreargs, **morekwargs)
get_next_by_created(*moreargs, **morekwargs)
get_next_by_modified(*moreargs, **morekwargs)
get_previous_by_created(*moreargs, **morekwargs)
get_previous_by_modified(*moreargs, **morekwargs)
objects = <seed.audit_logs.models.AuditLogManager object>
organization

Accessor to the related object on the forward side of a many-to-one or one-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

child.parent is a ForwardManyToOneDescriptor instance.

save(*args, **kwargs)

Ensure that only notes are saved

to_dict()

serializes an audit_log

user

Accessor to the related object on the forward side of a many-to-one or one-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

child.parent is a ForwardManyToOneDescriptor instance.

class seed.audit_logs.models.AuditLogManager

Bases: django.db.models.manager.Manager

ExpressionManager with update preventing the update of non-notes

get_queryset()
log_action(request, conent_object, organization_id, action_note=None, audit_type=0)
class seed.audit_logs.models.AuditLogQuerySet(model=None, query=None, using=None, hints=None)

Bases: django.db.models.query.QuerySet

update(*args, **kwargs)

only notes should be updated, so filter out non-notes

Tests

class seed.audit_logs.tests.AuditLogModelTests(methodName=’runTest’)

Bases: django.test.testcases.TestCase

setUp()
test_audit()

tests audit save

test_audit_save()

audit_log LOG should not be able to save/update

test_audit_update()

audit_log LOG should not be able to save/update

test_generic_relation()

test CanonicalBuilding.audit_logs

test_get_all_audit_logs_for_an_org()

gets all audit logs for an org

test_model___unicode__()

tests the AuditLog inst. str or unicode

test_note()

tests note save

test_note_save()

notes should be able to save/update

class seed.audit_logs.tests.AuditLogViewTests(methodName=’runTest’)

Bases: django.test.testcases.TestCase

setUp()
test_create_note()

tests create_note

test_get_building_logs()

test the django view get_building_logs

test_update_note()

tests update_note

URLs

Views

seed.audit_logs.views.create_note(request, *args, **kwargs)

Retrieves logs for a building.

POST:Expects the CanonicalBuildings’s id in the JSON payload as building_id. Expects an organization_id (to which project belongs) in the query string. Expects the action_note to be in the JSON payload as action_note

Returns:

'audit_log' : {
    'user': {
        'first_name': user's firstname,
        'last_name': user's last_name,
        'id': user's id,
        'email': user's email address
    },
    'id': audit log's id,
    'audit_type': 'Note',
    'created': DateTime,
    'modified': DateTime,
    'action': method triggering log entry,
    'action_response': response of action,
    'action_note': the note body
    'organization': {
        'name': name of org,
        'id': id of org
},
'status': 'success'
seed.audit_logs.views.get_building_logs(request, *args, **kwargs)

Retrieves logs for a building.

GET:Expects the CanonicalBuildings’s id in the query string as building_id. Expects an organization_id (to which project belongs) in the query string.

Returns:

'audit_logs' : [
    {
        'user': {
            'first_name': user's firstname,
            'last_name': user's last_name,
            'id': user's id,
            'email': user's email address
        },
        'id': audit log's id,
        'audit_type': 'Log' or 'Note',
        'created': DateTime,
        'modified': DateTime,
        'action': method triggering log entry,
        'action_response': response of action,
        'action_note': the note body if Note or further description
        'organization': {
            'name': name of org,
            'id': id of org
        }
    }, ...
],
'status': 'success'
seed.audit_logs.views.update_note(request, *args, **kwargs)

Retrieves logs for a building.

PUT:Expects the CanonicalBuildings’s id in the JSON payload as building_id. Expects an organization_id (to which project belongs) in the query string. Expects the action_note to be in the JSON payload as action_note Expects the audit_log_id to be in the JSON payload as audit_log_id

Returns:

'audit_log' : {
    'user': {
        'first_name': user's firstname,
        'last_name': user's last_name,
        'id': user's id,
        'email': user's email address
    },
    'id': audit log's id,
    'audit_type': 'Note',
    'created': DateTime,
    'modified': DateTime,
    'action': method triggering log entry,
    'action_response': response of action,
    'action_note': the note body
    'organization': {
        'name': name of org,
        'id': id of org
},
'status': 'success'