From de91730336951f27cb83c3e60ac2d071bb3d4cef Mon Sep 17 00:00:00 2001 From: Elrond Date: Wed, 4 Jan 2012 22:00:44 +0100 Subject: 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. --- mediagoblin/db/sql/base.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'mediagoblin/db/sql/base.py') 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)) -- cgit v1.2.3