diff options
Diffstat (limited to 'mediagoblin')
-rw-r--r-- | mediagoblin/db/sql/convert.py | 7 | ||||
-rw-r--r-- | mediagoblin/db/sql/extratypes.py | 18 | ||||
-rw-r--r-- | mediagoblin/db/sql/models.py | 27 | ||||
-rw-r--r-- | mediagoblin/edit/forms.py | 7 | ||||
-rw-r--r-- | mediagoblin/static/css/base.css | 12 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/user_pages/media.html | 2 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/user_pages/user.html | 2 | ||||
-rw-r--r-- | mediagoblin/tools/request.py | 12 |
8 files changed, 71 insertions, 16 deletions
diff --git a/mediagoblin/db/sql/convert.py b/mediagoblin/db/sql/convert.py index 6698b767..88614fd4 100644 --- a/mediagoblin/db/sql/convert.py +++ b/mediagoblin/db/sql/convert.py @@ -2,7 +2,7 @@ from mediagoblin.init import setup_global_and_app_config, setup_database from mediagoblin.db.mongo.util import ObjectId from mediagoblin.db.sql.models import (Base, User, MediaEntry, MediaComment, - Tag, MediaTag) + Tag, MediaTag, MediaFile) from mediagoblin.db.sql.open import setup_connection_and_db_from_config as \ sql_connect from mediagoblin.db.mongo.open import setup_connection_and_db_from_config as \ @@ -70,6 +70,11 @@ def convert_media_entries(mk_db): session.flush() add_obj_ids(entry, new_entry) + for key, value in entry.media_files.iteritems(): + new_file = MediaFile(name=key, file_path=value) + new_file.media_entry = new_entry.id + Session.add(new_file) + session.commit() session.close() diff --git a/mediagoblin/db/sql/extratypes.py b/mediagoblin/db/sql/extratypes.py new file mode 100644 index 00000000..88f556d9 --- /dev/null +++ b/mediagoblin/db/sql/extratypes.py @@ -0,0 +1,18 @@ +from sqlalchemy.types import TypeDecorator, Unicode + + +class PathTupleWithSlashes(TypeDecorator): + "Represents a Tuple of strings as a slash separated string." + + impl = Unicode + + def process_bind_param(self, value, dialect): + if value is not None: + assert len(value), "Does not support empty lists" + value = '/'.join(value) + return value + + def process_result_value(self, value, dialect): + if value is not None: + value = tuple(value.split('/')) + return value diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index 95821b4f..91092f33 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -5,7 +5,10 @@ from sqlalchemy import ( Column, Integer, Unicode, UnicodeText, DateTime, Boolean, ForeignKey, UniqueConstraint) from sqlalchemy.orm import relationship +from sqlalchemy.orm.collections import attribute_mapped_collection +from sqlalchemy.ext.associationproxy import association_proxy +from mediagoblin.db.sql.extratypes import PathTupleWithSlashes from mediagoblin.db.sql.base import GMGTableBase from mediagoblin.db.mixin import UserMixin, MediaEntryMixin @@ -65,7 +68,7 @@ class MediaEntry(Base, MediaEntryMixin): fail_error = Column(Unicode) fail_metadata = Column(UnicodeText) - queued_media_file = Column(Unicode) + queued_media_file = Column(PathTupleWithSlashes) queued_task_id = Column(Unicode) @@ -75,13 +78,33 @@ class MediaEntry(Base, MediaEntryMixin): get_uploader = relationship(User) + media_files_helper = relationship("MediaFile", + collection_class=attribute_mapped_collection("name"), + cascade="all, delete-orphan" + ) + media_files = association_proxy('media_files_helper', 'file_path', + creator=lambda k,v: MediaFile(name=k, file_path=v) + ) + ## TODO - # media_files # media_data # attachment_files # fail_error +class MediaFile(Base): + __tablename__ = "mediafiles" + + media_entry = Column( + Integer, ForeignKey(MediaEntry.id), + nullable=False, primary_key=True) + name = Column(Unicode, primary_key=True) + file_path = Column(PathTupleWithSlashes) + + def __repr__(self): + return "<MediaFile %s: %r>" % (self.name, self.file_path) + + class Tag(Base): __tablename__ = "tags" diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index 09955874..5c191fba 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -45,10 +45,9 @@ class EditProfileForm(wtforms.Form): bio = wtforms.TextAreaField( _('Bio'), [wtforms.validators.Length(min=0, max=500)], - description=_( - """You can use - <a href="http://daringfireball.net/projects/markdown/basics"> - Markdown</a> for formatting.""")) + description=_("""You can use + <a href="http://daringfireball.net/projects/markdown/basics"> + Markdown</a> for formatting.""")) url = wtforms.TextField( _('Website'), [wtforms.validators.Optional(), diff --git a/mediagoblin/static/css/base.css b/mediagoblin/static/css/base.css index c2d45a1b..efd7b561 100644 --- a/mediagoblin/static/css/base.css +++ b/mediagoblin/static/css/base.css @@ -32,8 +32,7 @@ body { padding: none; margin: 0px; height: 100%; - font: 16px "HelveticaNeue-Light","Helvetica Neue Light","Helvetica Neue",Helvetica,Arial,sans-serif; - font-family:'Lato', sans-serif; + font: 16px 'Lato', 'Helvetica Neue', Arial, 'Liberation Sans', FreeSans, sans-serif; } form { @@ -43,8 +42,15 @@ form { /* text styles */ +h1,h2,h3,p { + margin-bottom: 20px; +} + +h1,h2,h3 { + font-weight: bold; +} + h1 { - margin-bottom: 15px; margin-top: 15px; color: #fff; font-size: 1.875em; diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 583e4ebd..865a94ab 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -97,7 +97,7 @@ user= media.get_uploader.username, media=media._id) }}" method="POST" id="form_comment"> <p> - {% trans %}Type your comment here. You can use <a href="http://daringfireball.net/projects/markdown/basics">Markdown</a> for formatting.{% endtrans %} + {% trans %}You can use <a href="http://daringfireball.net/projects/markdown/basics">Markdown</a> for formatting.{% endtrans %} </p> {{ wtforms_util.render_divs(comment_form) }} <div class="form_submit_buttons"> diff --git a/mediagoblin/templates/mediagoblin/user_pages/user.html b/mediagoblin/templates/mediagoblin/user_pages/user.html index 0937f97a..d3b4021d 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/user.html +++ b/mediagoblin/templates/mediagoblin/user_pages/user.html @@ -145,7 +145,7 @@ {% include "mediagoblin/utils/feed_link.html" %} </div> {% else %} - {% if request.user._id == user._id %} + {% if request.user and (request.user._id == user._id) %} <div class="profile_showcase empty_space"> <p> {% trans -%} diff --git a/mediagoblin/tools/request.py b/mediagoblin/tools/request.py index b1cbe119..7e193125 100644 --- a/mediagoblin/tools/request.py +++ b/mediagoblin/tools/request.py @@ -14,7 +14,7 @@ # 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.util import ObjectId +from mediagoblin.db.util import ObjectId, InvalidId def setup_user_in_request(request): """ @@ -25,13 +25,17 @@ def setup_user_in_request(request): request.user = None return - user = None - user = request.app.db.User.one( - {'_id': ObjectId(request.session['user_id'])}) + try: + oid = ObjectId(request.session['user_id']) + except InvalidId: + user = None + else: + user = request.db.User.one({'_id': oid}) if not user: # Something's wrong... this user doesn't exist? Invalidate # this session. + print "Killing session for %r" % request.session['user_id'] request.session.invalidate() request.user = user |