Style fixes

This commit is contained in:
Joar Wandborg 2012-09-18 18:19:26 +02:00
parent c9ac6841c4
commit 6d1e55b262
2 changed files with 34 additions and 21 deletions

View File

@ -188,6 +188,7 @@ class CollectionMixin(object):
collection=self.slug_or_id, collection=self.slug_or_id,
**extra_args) **extra_args)
class CollectionItemMixin(object): class CollectionItemMixin(object):
@property @property
def note_html(self): def note_html(self):

View File

@ -34,7 +34,6 @@ from mediagoblin.decorators import (uses_pagination, get_user_media_entry,
from werkzeug.contrib.atom import AtomFeed from werkzeug.contrib.atom import AtomFeed
from mediagoblin.media_types import get_media_manager from mediagoblin.media_types import get_media_manager
from sqlalchemy.exc import IntegrityError
_log = logging.getLogger(__name__) _log = logging.getLogger(__name__)
_log.setLevel(logging.DEBUG) _log.setLevel(logging.DEBUG)
@ -129,7 +128,8 @@ def media_home(request, media, page, **kwargs):
comment_form = user_forms.MediaCommentForm(request.POST) comment_form = user_forms.MediaCommentForm(request.POST)
media_template_name = get_media_manager(media.media_type)['display_template'] media_template_name = get_media_manager(
media.media_type)['display_template']
return render_to_response( return render_to_response(
request, request,
@ -182,7 +182,8 @@ def media_collect(request, media):
form = user_forms.MediaCollectForm(request.POST) form = user_forms.MediaCollectForm(request.POST)
filt = (request.db.Collection.creator == request.user.id) filt = (request.db.Collection.creator == request.user.id)
form.collection.query = request.db.Collection.query.filter(filt).order_by(request.db.Collection.title) form.collection.query = request.db.Collection.query.filter(
filt).order_by(request.db.Collection.title)
if request.method == 'POST': if request.method == 'POST':
if form.validate(): if form.validate():
@ -196,21 +197,23 @@ def media_collect(request, media):
collection.id = ObjectId() collection.id = ObjectId()
collection.title = ( collection.title = (
unicode(request.POST['collection_title']) unicode(request.POST['collection_title']))
or unicode(splitext(filename)[0]))
collection.description = unicode(request.POST.get('collection_description')) collection.description = unicode(
request.POST.get('collection_description'))
collection.creator = request.user._id collection.creator = request.user._id
collection.generate_slug() collection.generate_slug()
# Make sure this user isn't duplicating an existing collection # Make sure this user isn't duplicating an existing collection
existing_collection = request.db.Collection.find_one({ existing_collection = request.db.Collection.find_one({
'creator': request.user._id, 'creator': request.user._id,
'title':collection.title}) 'title': collection.title})
if existing_collection: if existing_collection:
messages.add_message( messages.add_message(
request, messages.ERROR, _('You already have a collection called "%s"!' % collection.title)) request, messages.ERROR,
_('You already have a collection called "%s"!'
% collection.title))
return redirect(request, "mediagoblin.user_pages.media_home", return redirect(request, "mediagoblin.user_pages.media_home",
user=request.user.username, user=request.user.username,
@ -221,17 +224,23 @@ def media_collect(request, media):
collection_item.collection = collection.id collection_item.collection = collection.id
# Otherwise, use the collection selected from the drop-down # Otherwise, use the collection selected from the drop-down
else: else:
collection = request.db.Collection.find_one({'_id': request.POST.get('collection')}) collection = request.db.Collection.find_one({
'_id': request.POST.get('collection')})
collection_item.collection = collection.id collection_item.collection = collection.id
# Make sure the user actually selected a collection # Make sure the user actually selected a collection
if not collection: if not collection:
messages.add_message( messages.add_message(
request, messages.ERROR, _('You have to select or add a collection')) request, messages.ERROR,
_('You have to select or add a collection'))
# Check whether media already exists in collection # Check whether media already exists in collection
elif request.db.CollectionItem.find_one({'media_entry': media.id, 'collection': collection_item.collection}): elif request.db.CollectionItem.find_one({
'media_entry': media.id,
'collection': collection_item.collection}):
messages.add_message( messages.add_message(
request, messages.ERROR, _('"%s" already in collection "%s"' % (media.title, collection.title))) request, messages.ERROR,
_('"%s" already in collection "%s"'
% (media.title, collection.title)))
else: else:
collection_item.media_entry = media.id collection_item.media_entry = media.id
collection_item.author = request.user.id collection_item.author = request.user.id
@ -245,14 +254,16 @@ def media_collect(request, media):
media.save() media.save()
messages.add_message( messages.add_message(
request, messages.SUCCESS, _('"%s" added to collection "%s"' % (media.title, collection.title))) request, messages.SUCCESS, _('"%s" added to collection "%s"'
% (media.title, collection.title)))
return redirect(request, "mediagoblin.user_pages.media_home", return redirect(request, "mediagoblin.user_pages.media_home",
user=media.get_uploader.username, user=media.get_uploader.username,
media=media.id) media=media.id)
else: else:
messages.add_message( messages.add_message(
request, messages.ERROR, _('Please check your entries and try again.')) request, messages.ERROR,
_('Please check your entries and try again.'))
return render_to_response( return render_to_response(
request, request,
@ -323,10 +334,10 @@ def user_collection(request, page):
return render_404(request) return render_404(request)
collection = request.db.Collection.find_one( collection = request.db.Collection.find_one(
{'slug': request.matchdict['collection'] }) {'slug': request.matchdict['collection']})
cursor = request.db.CollectionItem.find( cursor = request.db.CollectionItem.find(
{'collection': collection.id }) {'collection': collection.id})
pagination = Pagination(page, cursor) pagination = Pagination(page, cursor)
collection_items = pagination() collection_items = pagination()
@ -361,7 +372,7 @@ def collection_item_confirm_remove(request, collection_item):
entry.save() entry.save()
collection_item.delete() collection_item.delete()
collection.items = collection.items - 1; collection.items = collection.items - 1
collection.save() collection.save()
messages.add_message( messages.add_message(
@ -505,6 +516,7 @@ def atom_feed(request):
return feed.get_response() return feed.get_response()
def collection_atom_feed(request): def collection_atom_feed(request):
""" """
generates the atom feed with the newest images from a collection generates the atom feed with the newest images from a collection