In this commit, I'm deleting the ArchivedReports object, at paroneyea's recom-
[mediagoblin.git] / mediagoblin / db / extratypes.py
CommitLineData
fbad3a9f 1# GNU MediaGoblin -- federated, autonomous media hosting
7f4ebeed 2# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
fbad3a9f
E
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
1e3a0e0c 18from sqlalchemy.types import TypeDecorator, Unicode, TEXT
cf27accc 19import json
02db7e0a
E
20
21
22class PathTupleWithSlashes(TypeDecorator):
23 "Represents a Tuple of strings as a slash separated string."
24
25 impl = Unicode
26
27 def process_bind_param(self, value, dialect):
28 if value is not None:
51fba991
E
29 if len(value) == 0:
30 value = None
31 else:
32 value = '/'.join(value)
02db7e0a
E
33 return value
34
35 def process_result_value(self, value, dialect):
36 if value is not None:
37 value = tuple(value.split('/'))
38 return value
cf27accc
E
39
40
41# The following class and only this one class is in very
42# large parts based on example code from sqlalchemy.
43#
44# The original copyright notice and license follows:
45# Copyright (C) 2005-2011 the SQLAlchemy authors and contributors <see AUTHORS file>
46#
47# This module is part of SQLAlchemy and is released under
48# the MIT License: http://www.opensource.org/licenses/mit-license.php
49#
50class JSONEncoded(TypeDecorator):
51 "Represents an immutable structure as a json-encoded string."
52
1e3a0e0c 53 impl = TEXT
cf27accc
E
54
55 def process_bind_param(self, value, dialect):
56 if value is not None:
57 value = json.dumps(value)
58 return value
59
60 def process_result_value(self, value, dialect):
61 if value is not None:
62 value = json.loads(value)
63 return value