diff options
author | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2012-01-04 22:00:44 +0100 |
---|---|---|
committer | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2012-01-28 19:32:43 +0100 |
commit | de91730336951f27cb83c3e60ac2d071bb3d4cef (patch) | |
tree | 8c0a93e9518c4b130855e15eedd0ecad1c39e950 /mediagoblin/db/sql/base.py | |
parent | ebc0e382398fbc665e6b133bd3925c5352d3d51d (diff) | |
download | mediagoblin-de91730336951f27cb83c3e60ac2d071bb3d4cef.tar.lz mediagoblin-de91730336951f27cb83c3e60ac2d071bb3d4cef.tar.xz mediagoblin-de91730336951f27cb83c3e60ac2d071bb3d4cef.zip |
Nearly complete support for Tags
These changes allow all of the rest of the code to use tags
in sql as they were used on mongo. It's not efficient at
all, as changing tags usually means to remove all old tags
and adding all new.
The only problem here is: Old slugs for tags are not
removed, because they're shared across all MediaTags and
dropping orphans is not always easy.
Diffstat (limited to 'mediagoblin/db/sql/base.py')
-rw-r--r-- | mediagoblin/db/sql/base.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/mediagoblin/db/sql/base.py b/mediagoblin/db/sql/base.py index 1db53c56..f1affc83 100644 --- a/mediagoblin/db/sql/base.py +++ b/mediagoblin/db/sql/base.py @@ -77,3 +77,19 @@ class GMGTableBase(object): Base = declarative_base(cls=GMGTableBase) + + +class DictReadAttrProxy(object): + """ + Maps read accesses to obj['key'] to obj.key + and hides all the rest of the obj + """ + def __init__(self, proxied_obj): + self.proxied_obj = proxied_obj + + def __getitem__(self, key): + try: + return getattr(self.proxied_obj, key) + except AttributeError: + raise KeyError("%r is not an attribute on %r" + % (key, self.proxied_obj)) |