Feature #482 - Media attachments
This commit is contained in:
@@ -28,3 +28,6 @@ class SubmitStartForm(wtforms.Form):
|
||||
tags = wtforms.TextField(
|
||||
'Tags',
|
||||
[tag_length_validator])
|
||||
attachment = wtforms.FileField(
|
||||
'Attachment',
|
||||
[wtforms.validators.Optional()])
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
# 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/>.
|
||||
|
||||
|
||||
import mediagoblin.mg_globals as mg_globals
|
||||
from datetime import datetime
|
||||
|
||||
from os.path import splitext
|
||||
from cgi import FieldStorage
|
||||
from string import split
|
||||
@@ -72,6 +76,31 @@ def submit_start(request):
|
||||
# Generate a slug from the title
|
||||
entry.generate_slug()
|
||||
|
||||
# Add any attachements
|
||||
if (mg_globals.app_config['allow_attachments']
|
||||
and request.POST.has_key('attachment')
|
||||
and isinstance(request.POST['attachment'], FieldStorage)
|
||||
and request.POST['attachment'].file):
|
||||
|
||||
attachment_public_filepath = mg_globals.public_store.get_unique_filepath(
|
||||
['media_entries',
|
||||
unicode('attachment-%s' % entry['_id']),
|
||||
secure_filename(request.POST['attachment'].filename)])
|
||||
|
||||
attachment_public_file = mg_globals.public_store.get_file(
|
||||
attachment_public_filepath, 'wb')
|
||||
|
||||
try:
|
||||
attachment_public_file.write(request.POST['attachment'].file.read())
|
||||
finally:
|
||||
request.POST['attachment'].file.close()
|
||||
|
||||
entry['attachment_files'] = [dict(
|
||||
name=request.POST['attachment'].filename,
|
||||
filepath=attachment_public_filepath,
|
||||
created=datetime.utcnow()
|
||||
)]
|
||||
|
||||
# Now store generate the queueing related filename
|
||||
queue_filepath = request.app.queue_store.get_unique_filepath(
|
||||
['media_entries',
|
||||
@@ -100,4 +129,5 @@ def submit_start(request):
|
||||
return render_to_response(
|
||||
request,
|
||||
'mediagoblin/submit/start.html',
|
||||
{'submit_form': submit_form})
|
||||
{'submit_form': submit_form,
|
||||
'app_config': mg_globals.app_config})
|
||||
|
||||
Reference in New Issue
Block a user