Skip to content

Commit

Permalink
feature: clean up audit object by removing null values.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfermigier committed Jul 19, 2018
1 parent af27453 commit c5c959e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 258 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog for Abilian Core
==========================

0.10.19 (2018-07-19)
--------------------

- Clean up audit objects by removing null values on init

0.10.15 (2018-07-05)
--------------------

Expand Down
13 changes: 13 additions & 0 deletions abilian/services/audit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from six import binary_type, text_type
from sqlalchemy import LargeBinary
from sqlalchemy.orm import relationship
from sqlalchemy.orm.base import NEVER_SET
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.types import DateTime, Integer, String, UnicodeText

Expand Down Expand Up @@ -134,6 +135,18 @@ def get_changes(self):
else:
changes = Changes()

columns = changes.columns
clean_columns = {}
for key, value in columns.items():
if isinstance(value, tuple):
old_value, new_value = value
if old_value == NEVER_SET and new_value in (None, ""):
continue

clean_columns[key] = value

changes.columns = clean_columns

return changes

def set_changes(self, changes):
Expand Down
4 changes: 4 additions & 0 deletions abilian/web/admin/panels/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from datetime import datetime
from itertools import chain
from typing import Text

import pytz
import six
Expand Down Expand Up @@ -292,11 +293,13 @@ def model(model_name):
return db.Model._decl_class_registry.get(model_name)

def render(self):
# type: () -> Text
raise NotImplementedError


class AuditEntryPresenter(BaseEntryPresenter):
def __init__(self, entry):
# type: (AuditEntry) -> None
assert isinstance(entry, AuditEntry)
super(AuditEntryPresenter, self).__init__(entry.user, entry.happened_at)
self.entry = entry
Expand Down Expand Up @@ -348,6 +351,7 @@ def render(self):

class SecurityEntryPresenter(BaseEntryPresenter):
def __init__(self, entry):
# type: (SecurityAudit) -> None
assert isinstance(entry, SecurityAudit)
super(SecurityEntryPresenter, self).__init__(entry.manager, entry.happened_at)
self.entry = entry
Expand Down
258 changes: 0 additions & 258 deletions abilian/web/templates/macros.html

This file was deleted.

0 comments on commit c5c959e

Please sign in to comment.