Album ID is not optional for picture upload.

Upload date is now stored and the last edit date is set to the upload date if not supplied.
This commit is contained in:
tanshu 2015-06-30 15:21:05 +05:30
parent e3ded59e53
commit d4ca3fffa0
2 changed files with 18 additions and 8 deletions

View File

@ -42,7 +42,7 @@
var file = files[i];
Upload.upload({
url: '/v1/upload',
fields: {'album': info.id, name: file.name, lastModifiedDate: file.lastModifiedDate},
fields: {'album_id': info.id, name: file.name, lastModifiedDate: file.lastModifiedDate},
file: file
}).progress(function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);

View File

@ -1,3 +1,4 @@
import datetime
import hashlib
import os
import shutil
@ -29,14 +30,19 @@ def html(request):
def upload(request):
input_file = request.POST['file'].file
name = request.POST['name']
last_modified_date = request.POST['lastModifiedDate']
album_id = uuid.UUID(request.POST['album'])
upload_file(input_file, name, last_modified_date, album_id, uuid.UUID(authenticated_userid(request)))
return {'Status': 'OK'}
last_modified_date = request.POST.get('lastModifiedDate', None)
if 'album_id' in request.POST:
album = Album.by_id(request.POST['album_id'])
elif 'album' in request.POST:
album = Album.by_name(request.POST['album'])
else:
album = None
return upload_file(input_file, name, last_modified_date, album, uuid.UUID(authenticated_userid(request)))
def upload_file(file, name, last_modified_date, album_id, user_id):
def upload_file(file, name, last_modified_date, album, user_id):
last_modified_date_prop = Property.by_name('last_modified_date')
upload_date_prop = Property.by_name('upload_date')
file_id = uuid.uuid4()
file_path = pkg_resources.resource_filename('soter', 'upload/o/' + str(file_id) + '.jpg')
temp_file_path = file_path + '~'
@ -45,8 +51,12 @@ def upload_file(file, name, last_modified_date, album_id, user_id):
shutil.copyfileobj(file, output_file)
pic_hash = get_hash(temp_file_path)
pic = Picture(name, pic_hash, user_id, True, file_id)
pic.albums.append(Album.by_id(album_id))
pic.properties.append(PictureProperty(property= last_modified_date_prop, data = last_modified_date))
if album is not None:
pic.albums.append(album)
if last_modified_date is None:
last_modified_date = datetime.datetime.utcnow()
pic.properties.append(PictureProperty(property=last_modified_date_prop, data=last_modified_date))
pic.properties.append(PictureProperty(property=upload_date_prop, data=datetime.datetime.utcnow()))
DBSession.add(pic)
try:
transaction.commit()