Feature #482 - Media attachments

This commit is contained in:
Joar Wandborg
2011-08-05 22:08:29 +02:00
parent 4d74812dfc
commit 2c4374938f
8 changed files with 84 additions and 3 deletions

View File

@@ -30,6 +30,10 @@ class EditForm(wtforms.Form):
tags = wtforms.TextField(
'Tags',
[tag_length_validator])
attachment_name = wtforms.TextField(
'Attachment title')
attachment_delete = wtforms.BooleanField(
'Delete attachment')
class EditProfileForm(wtforms.Form):
bio = wtforms.TextAreaField('Bio',

View File

@@ -34,12 +34,21 @@ def edit_media(request, media):
if not may_edit_media(request, media):
return exc.HTTPForbidden()
form = forms.EditForm(request.POST,
defaults = dict(
title = media['title'],
slug = media['slug'],
description = media['description'],
tags = media_tags_as_string(media['tags']))
if len(media['attachment_files']):
defaults['attachment_name'] = media['attachment_files'][0]['name']
form = forms.EditForm(
request.POST,
**defaults)
if request.method == 'POST' and form.validate():
# Make sure there isn't already a MediaEntry with such a slug
# and userid.
@@ -60,6 +69,12 @@ def edit_media(request, media):
media['description_html'] = cleaned_markdown_conversion(
media['description'])
if 'attachment_name' in request.POST:
media['attachment_files'][0]['name'] = request.POST['attachment_name']
if 'attachment_delete' in request.POST and 'y' == request.POST['attachment_delete']:
del media['attachment_files'][0]
media['slug'] = request.POST['slug']
media.save()