Exemplo n.º 1
0
from sight.views import api
from sight.models import Event

# init the restless api
api.create_api( Event, [ 'GET', 'DELETE', 'PATCH' ])
Exemplo n.º 2
0
from werkzeug import secure_filename

import os
import Image

def _accept_file( fh ):
	""" Checks if a file is acceptable (for upload).
		
		@return {bool}
	"""
	ext = fh.filename.rsplit( '.', 1 )[1].lower()
	
	return ext in config.UPLOAD_EXTENSIONS

# init the restless api
api.create_api( Photo, [ 'GET', 'DELETE', 'PATCH' ])

@app.route( '/api/photo/upload', methods=[ 'POST' ], defaults={ 'path': None })
@app.route( '/api/photo/upload/<path:path>', methods=[ 'GET' ])
def photo_upload( path ):
	if request.method == "POST":
		fh = request.files.get( 'file' )

		# verify a photo is being uploaded
		# and that the file is acceptable
		if fh and _accept_file( fh ):
			# get the event name
			event = request.form.get( 'event' ) or 'misc'

			# put the photo in the library
			# and add it to the database