diff options
Diffstat (limited to 'mediagoblin')
-rw-r--r-- | mediagoblin/buildout_recipes.py | 50 | ||||
-rw-r--r-- | mediagoblin/db/mixin.py | 21 | ||||
-rw-r--r-- | mediagoblin/db/open.py | 13 | ||||
-rw-r--r-- | mediagoblin/db/sql/base.py | 4 | ||||
-rw-r--r-- | mediagoblin/db/sql/models.py | 8 | ||||
-rw-r--r-- | mediagoblin/db/util.py | 11 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/user_pages/media.html | 2 |
7 files changed, 36 insertions, 73 deletions
diff --git a/mediagoblin/buildout_recipes.py b/mediagoblin/buildout_recipes.py deleted file mode 100644 index f3d0362f..00000000 --- a/mediagoblin/buildout_recipes.py +++ /dev/null @@ -1,50 +0,0 @@ -# GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - - -import logging -import os - - -MAKE_SUBDIRECTORIES = ['media/queue', 'media/public', 'beaker'] - - -class MakeUserDevDirs(object): - """ - Simple recipe for making subdirectories for user buildout convenience - """ - def __init__(self, buildout, name, options): - self.buildout, self.name, self.options = buildout, name, options - - if self.options['path'].startswith('/'): - self.path = self.options['path'] - else: - self.path = os.path.join( - self.buildout['buildout']['directory'], - self.options['path']) - - def install(self): - for make_subdir in MAKE_SUBDIRECTORIES: - fulldir = os.path.join(self.path, make_subdir) - - if not os.path.exists(fulldir): - logging.getLogger(self.name).info( - 'Creating directory %s' % fulldir) - os.makedirs(fulldir) - - return () - - update = install diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py index d587ccb4..254dbcff 100644 --- a/mediagoblin/db/mixin.py +++ b/mediagoblin/db/mixin.py @@ -63,6 +63,10 @@ class MediaEntryMixin(object): def main_mediafile(self): pass + @property + def slug_or_id(self): + return (self.slug or self._id) + def url_for_self(self, urlgen, **extra_args): """ Generate an appropriate url for ourselves @@ -71,18 +75,11 @@ class MediaEntryMixin(object): """ uploader = self.get_uploader - if self.get('slug'): - return urlgen( - 'mediagoblin.user_pages.media_home', - user=uploader.username, - media=self.slug, - **extra_args) - else: - return urlgen( - 'mediagoblin.user_pages.media_home', - user=uploader.username, - media=unicode(self._id), - **extra_args) + return urlgen( + 'mediagoblin.user_pages.media_home', + user=uploader.username, + media=self.slug_or_id, + **extra_args) def get_fail_exception(self): """ diff --git a/mediagoblin/db/open.py b/mediagoblin/db/open.py index 32827fcb..6cd17869 100644 --- a/mediagoblin/db/open.py +++ b/mediagoblin/db/open.py @@ -14,5 +14,14 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -from mediagoblin.db.mongo.open import \ - setup_connection_and_db_from_config, check_db_migrations_current +try: + from mediagoblin.db.sql_switch import use_sql +except ImportError: + use_sql = False + +if use_sql: + from mediagoblin.db.sql.open import \ + setup_connection_and_db_from_config, check_db_migrations_current +else: + from mediagoblin.db.mongo.open import \ + setup_connection_and_db_from_config, check_db_migrations_current diff --git a/mediagoblin/db/sql/base.py b/mediagoblin/db/sql/base.py index 6f45b21b..1db53c56 100644 --- a/mediagoblin/db/sql/base.py +++ b/mediagoblin/db/sql/base.py @@ -15,6 +15,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. +from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import scoped_session, sessionmaker, object_session from sqlalchemy.orm.query import Query from sqlalchemy.sql.expression import desc @@ -73,3 +74,6 @@ class GMGTableBase(object): sess = Session() sess.add(self) sess.commit() + + +Base = declarative_base(cls=GMGTableBase) diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index 57444c2c..6232fff8 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -17,7 +17,6 @@ import datetime -from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import ( Column, Integer, Unicode, UnicodeText, DateTime, Boolean, ForeignKey, UniqueConstraint) @@ -27,13 +26,10 @@ from sqlalchemy.sql.expression import desc from sqlalchemy.ext.associationproxy import association_proxy from mediagoblin.db.sql.extratypes import PathTupleWithSlashes -from mediagoblin.db.sql.base import GMGTableBase +from mediagoblin.db.sql.base import Base from mediagoblin.db.mixin import UserMixin, MediaEntryMixin -Base = declarative_base(cls=GMGTableBase) - - class SimpleFieldAlias(object): """An alias for any field""" def __init__(self, fieldname): @@ -76,7 +72,7 @@ class MediaEntry(Base, MediaEntryMixin): id = Column(Integer, primary_key=True) uploader = Column(Integer, ForeignKey('users.id'), nullable=False) title = Column(Unicode, nullable=False) - slug = Column(Unicode, nullable=False) + slug = Column(Unicode) created = Column(DateTime, nullable=False, default=datetime.datetime.now) description = Column(UnicodeText) # ?? description_html = Column(UnicodeText) # ?? diff --git a/mediagoblin/db/util.py b/mediagoblin/db/util.py index 1df9494c..fff71d06 100644 --- a/mediagoblin/db/util.py +++ b/mediagoblin/db/util.py @@ -14,5 +14,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -from mediagoblin.db.mongo.util import (ObjectId, InvalidId, - DESCENDING) +try: + from mediagoblin.db.sql_switch import use_sql +except ImportError: + use_sql = False + +if use_sql: + from mediagoblin.db.sql.fake import ObjectId, InvalidId, DESCENDING +else: + from mediagoblin.db.mongo.util import ObjectId, InvalidId, DESCENDING diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 2229bbb2..dec443cd 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -139,7 +139,7 @@ <a href="{{ request.urlgen('mediagoblin.user_pages.media_home.view_comment', comment = comment._id, user = media.get_uploader.username, - media = media.slug) }}#comment"> + media = media.slug_or_id) }}#comment"> {{ comment.created.strftime("%I:%M%p %Y-%m-%d") }} </a> </div> |