Added basic collection functionality
This commit is contained in:
committed by
Joar Wandborg
parent
09e528acbb
commit
be5be1154f
@@ -77,3 +77,19 @@ class EditAttachmentsForm(wtforms.Form):
|
||||
'Title')
|
||||
attachment_file = wtforms.FileField(
|
||||
'File')
|
||||
|
||||
class EditCollectionForm(wtforms.Form):
|
||||
title = wtforms.TextField(
|
||||
_('Title'),
|
||||
[wtforms.validators.Length(min=0, max=500), wtforms.validators.Required(message=_("The title can't be empty"))])
|
||||
description = wtforms.TextAreaField(
|
||||
_('Description of this collection'),
|
||||
description=_("""You can use
|
||||
<a href="http://daringfireball.net/projects/markdown/basics">
|
||||
Markdown</a> for formatting."""))
|
||||
slug = wtforms.TextField(
|
||||
_('Slug'),
|
||||
[wtforms.validators.Required(message=_("The slug can't be empty"))],
|
||||
description=_(
|
||||
"The title part of this collection's address. "
|
||||
"You usually don't need to change this."))
|
||||
|
||||
@@ -22,5 +22,5 @@ edit_routes = [
|
||||
Route('mediagoblin.edit.profile', '/profile/',
|
||||
controller="mediagoblin.edit.views:edit_profile"),
|
||||
Route('mediagoblin.edit.account', '/account/',
|
||||
controller="mediagoblin.edit.views:edit_account")
|
||||
controller="mediagoblin.edit.views:edit_account"),
|
||||
]
|
||||
|
||||
@@ -25,13 +25,14 @@ from mediagoblin import mg_globals
|
||||
|
||||
from mediagoblin.auth import lib as auth_lib
|
||||
from mediagoblin.edit import forms
|
||||
from mediagoblin.edit.lib import may_edit_media
|
||||
from mediagoblin.decorators import require_active_login, get_user_media_entry
|
||||
from mediagoblin.edit.lib import may_edit_media, may_edit_collection
|
||||
from mediagoblin.decorators import require_active_login, get_user_media_entry, \
|
||||
user_may_alter_collection, get_user_collection
|
||||
from mediagoblin.tools.response import render_to_response, redirect
|
||||
from mediagoblin.tools.translate import pass_to_ugettext as _
|
||||
from mediagoblin.tools.text import (
|
||||
convert_to_tag_list_of_dicts, media_tags_as_string)
|
||||
from mediagoblin.db.util import check_media_slug_used
|
||||
from mediagoblin.db.util import check_media_slug_used, check_collection_slug_used
|
||||
|
||||
import mimetypes
|
||||
|
||||
@@ -255,3 +256,58 @@ def edit_account(request):
|
||||
'mediagoblin/edit/edit_account.html',
|
||||
{'user': user,
|
||||
'form': form})
|
||||
|
||||
|
||||
@require_active_login
|
||||
@user_may_alter_collection
|
||||
@get_user_collection
|
||||
def edit_collection(request, collection):
|
||||
defaults = dict(
|
||||
title=collection.title,
|
||||
slug=collection.slug,
|
||||
description=collection.description)
|
||||
|
||||
form = forms.EditCollectionForm(
|
||||
request.POST,
|
||||
**defaults)
|
||||
|
||||
if request.method == 'POST' and form.validate():
|
||||
# Make sure there isn't already a Collection with such a slug
|
||||
# and userid.
|
||||
slug_used = check_collection_slug_used(request.db, collection.creator,
|
||||
request.POST['slug'], collection.id)
|
||||
|
||||
# Make sure there isn't already a Collection with this title
|
||||
existing_collection = request.db.Collection.find_one({
|
||||
'creator': request.user._id,
|
||||
'title':request.POST['title']})
|
||||
|
||||
if existing_collection and existing_collection.id != collection.id:
|
||||
messages.add_message(
|
||||
request, messages.ERROR, _('You already have a collection called "%s"!' % request.POST['title']))
|
||||
elif slug_used:
|
||||
form.slug.errors.append(
|
||||
_(u'A collection with that slug already exists for this user.'))
|
||||
else:
|
||||
collection.title = unicode(request.POST['title'])
|
||||
collection.description = unicode(request.POST.get('description'))
|
||||
collection.slug = unicode(request.POST['slug'])
|
||||
|
||||
collection.save()
|
||||
|
||||
return redirect(request, "mediagoblin.user_pages.user_collection",
|
||||
user=collection.get_creator.username,
|
||||
collection=collection.slug)
|
||||
|
||||
if request.user.is_admin \
|
||||
and collection.creator != request.user._id \
|
||||
and request.method != 'POST':
|
||||
messages.add_message(
|
||||
request, messages.WARNING,
|
||||
_("You are editing another user's collection. Proceed with caution."))
|
||||
|
||||
return render_to_response(
|
||||
request,
|
||||
'mediagoblin/edit/edit_collection.html',
|
||||
{'collection': collection,
|
||||
'form': form})
|
||||
|
||||
Reference in New Issue
Block a user