Added basic collection functionality
This commit is contained in:
committed by
Joar Wandborg
parent
09e528acbb
commit
be5be1154f
@@ -41,3 +41,13 @@ class SubmitStartForm(wtforms.Form):
|
||||
_('License'),
|
||||
[wtforms.validators.Optional(),],
|
||||
choices=licenses_as_choices())
|
||||
|
||||
class AddCollectionForm(wtforms.Form):
|
||||
title = wtforms.TextField(
|
||||
_('Title'),
|
||||
[wtforms.validators.Length(min=0, max=500), wtforms.validators.Required()])
|
||||
description = wtforms.TextAreaField(
|
||||
_('Description of this collection'),
|
||||
description=_("""You can use
|
||||
<a href="http://daringfireball.net/projects/markdown/basics">
|
||||
Markdown</a> for formatting."""))
|
||||
|
||||
@@ -18,4 +18,7 @@ from routes.route import Route
|
||||
|
||||
submit_routes = [
|
||||
Route('mediagoblin.submit.start', '/',
|
||||
controller='mediagoblin.submit.views:submit_start')]
|
||||
controller='mediagoblin.submit.views:submit_start'),
|
||||
Route('mediagoblin.submit.collection', '/collection',
|
||||
controller='mediagoblin.submit.views:add_collection'),
|
||||
]
|
||||
|
||||
@@ -14,6 +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 import messages
|
||||
import mediagoblin.mg_globals as mg_globals
|
||||
import uuid
|
||||
from os.path import splitext
|
||||
@@ -181,3 +182,46 @@ def submit_start(request):
|
||||
'mediagoblin/submit/start.html',
|
||||
{'submit_form': submit_form,
|
||||
'app_config': mg_globals.app_config})
|
||||
|
||||
@require_active_login
|
||||
def add_collection(request, media=None):
|
||||
"""
|
||||
View to create a new collection
|
||||
"""
|
||||
submit_form = submit_forms.AddCollectionForm(request.POST)
|
||||
|
||||
if request.method == 'POST' and submit_form.validate():
|
||||
try:
|
||||
collection = request.db.Collection()
|
||||
collection.id = ObjectId()
|
||||
|
||||
collection.title = unicode(request.POST['title'])
|
||||
|
||||
collection.description = unicode(request.POST.get('description'))
|
||||
collection.creator = request.user._id
|
||||
collection.generate_slug()
|
||||
|
||||
# Make sure this user isn't duplicating an existing collection
|
||||
existing_collection = request.db.Collection.find_one({
|
||||
'creator': request.user._id,
|
||||
'title':collection.title})
|
||||
|
||||
if existing_collection:
|
||||
messages.add_message(
|
||||
request, messages.ERROR, _('You already have a collection called "%s"!' % collection.title))
|
||||
else:
|
||||
collection.save(validate=True)
|
||||
|
||||
add_message(request, SUCCESS, _('Collection "%s" added!' % collection.title))
|
||||
|
||||
return redirect(request, "mediagoblin.user_pages.user_home",
|
||||
user=request.user.username)
|
||||
|
||||
except Exception as e:
|
||||
raise
|
||||
|
||||
return render_to_response(
|
||||
request,
|
||||
'mediagoblin/submit/collection.html',
|
||||
{'submit_form': submit_form,
|
||||
'app_config': mg_globals.app_config})
|
||||
|
||||
Reference in New Issue
Block a user