951013e7 |
1 | # GNU MediaGoblin -- federated, autonomous media hosting |
2 | # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. |
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 | from sqlalchemy import Column, Integer, Unicode, ForeignKey |
17 | from sqlalchemy.orm import relationship |
18 | |
19 | from mediagoblin.db.models import User |
20 | from mediagoblin.db.base import Base,MediaEntry |
21 | |
22 | class MediaSubtitleFile(Base): |
23 | __tablename__ = "core__subtitle_files" |
24 | |
25 | id = Column(Integer, primary_key=True) |
26 | media_entry = Column( |
27 | Integer, ForeignKey(MediaEntry.id), |
28 | nullable=False) |
29 | name = Column(Unicode, nullable=False) |
30 | filepath = Column(PathTupleWithSlashes) |
31 | created = Column(DateTime, nullable=False, default=datetime.datetime.utcnow) |
32 | |
33 | @property |
34 | def dict_view(self): |
35 | """A dict like view on this object""" |
36 | return DictReadAttrProxy(self) |
37 | |
38 | subtitle_files_helper = relationship("MediaSubtitleFile", |
39 | cascade="all, delete-orphan", |
40 | order_by="MediaSubtitleFile.created" |
41 | ) |
42 | subtitle_files = association_proxy("subtitle_files_helper", "dict_view", |
43 | creator=lambda v: MediaSubtitleFile( |
44 | name=v["name"], filepath=v["filepath"]) |
45 | ) |
46 | |
47 | MODELS = [ |
48 | MediaSubtitleFile |
49 | ] |