aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/submit/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/submit/views.py')
-rw-r--r--mediagoblin/submit/views.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py
index 87e57dda..213b2494 100644
--- a/mediagoblin/submit/views.py
+++ b/mediagoblin/submit/views.py
@@ -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})