Yuvipanda has submitted this change and it was merged.

Change subject: Make table columns dicts instead of lists
......................................................................


Make table columns dicts instead of lists

Makes it easier to find a column by name.

Change-Id: I5c6527d0c756ee931f2a058aa9f80d4abdceb98c
---
M auditor/models.py
1 file changed, 5 insertions(+), 5 deletions(-)

Approvals:
  Yuvipanda: Verified; Looks good to me, approved
  Legoktm: Looks good to me, but someone else must approve



diff --git a/auditor/models.py b/auditor/models.py
index cd467c5..8db7b31 100644
--- a/auditor/models.py
+++ b/auditor/models.py
@@ -43,14 +43,14 @@
 
 
 class Table(object):
-    def __init__(self, name, columns=[], where=None, table_name=None):
+    def __init__(self, name, columns={}, where=None, table_name=None):
         self.name = name
         self.columns = columns
         self.where = where
         self.table_name = table_name if table_name else name
 
     def add_column(self, column):
-        self.columns.append(column)
+        self.columns[column.name] = column
         column.table = self
 
     def to_dict(self):
@@ -60,12 +60,12 @@
         tabledict = {}
         if self.where:
             tabledict['where'] = self.where
-        if all([c.whitelisted for c in self.columns]):
+        if all([c.whitelisted for c in self.columns.values()]):
             # Everything is whitelisted!
             tabledict['columns'] = [c.name for c in self.columns]
         else:
             tabledict['columns'] = {}
-            for c in self.columns:
+            for c in self.columns.values():
                 columndict = {}
                 columndict['whitelisted'] = c.whitelisted
                 if c.condition:
@@ -79,7 +79,7 @@
 
     @classmethod
     def from_dict(cls, tablename, tabledata):
-        table = cls(tablename, [], tabledata.get('where', None), 
tabledata.get('table_name', None))
+        table = cls(tablename, {}, tabledata.get('where', None), 
tabledata.get('table_name', None))
         if isinstance(tabledata['columns'], list):
             # Whitelisted table
             for colname in tabledata['columns']:

-- 
To view, visit https://gerrit.wikimedia.org/r/182801
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5c6527d0c756ee931f2a058aa9f80d4abdceb98c
Gerrit-PatchSet: 3
Gerrit-Project: operations/software/labsdb-auditor
Gerrit-Branch: master
Gerrit-Owner: Yuvipanda <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Yuvipanda <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to