Esempio n. 1
0
def upload_image():
    """Process image upload from form"""

    user_id = session.get('userId')
    if user_id is None:
        flash('Login to upload images', 'warning')
        return redirect('/login')
    user = User.query.get(int(user_id))

    title = request.form.get('title')
    description = request.form.get('description')

    if 'image' not in request.files:
        flash('No image part', 'danger')
        return redirect('/')

    image_file = request.files['image']
    if image_file.filename == '':
        flash('No selected image', 'danger')
        return redirect('/')

    if not Image.is_allowed_file(image_file.filename):
        flash('Disallowed file type.', 'danger')
        return redirect('/')

    SourceImage.create(image_file, user, title, description)
    flash('Image uploaded successfully', 'info')

    # print '-----> /upload -> ', source_image
    return redirect('/')
Esempio n. 2
0
 def test_image_is_allowed_file(self):
     print '- test_image_is_allowed_file'
     self.assertTrue(Image.is_allowed_file('hello.jpg'))
     self.assertTrue(Image.is_allowed_file('hello.png'))
     self.assertTrue(Image.is_allowed_file('h.e.l.l.o.tif'))
     self.assertFalse(Image.is_allowed_file('hellojpg'))
     self.assertFalse(Image.is_allowed_file('hello.pdf'))
     self.assertFalse(Image.is_allowed_file('hello.zip'))
     print '+ passed'