コード例 #1
0
def gallery_route():
    options = {}
    username = '******'
    try:
        if request.method == 'POST':
            if 'op' not in request.form:
                raise RuntimeError('Did you click the button?')
            # if op is add image

            if request.form['op'] == 'delete_image':
                sheetmusic = request.form['sheetmusic']
                # Delete the image from the database.
                database.delete_image(username, sheetmusic)
            elif request.form['op'] == 'open_image':
                # image_id = request.form['image_id']
                print('halo')
                #print image_id
        elif request.method == 'GET':
            pass
        options['sheetmusics'] = database.get_sheetmusics(username)
        options['pictures'] = database.get_images(username)
        return render_template('gallery.html', **options)
    except Exception as e:
        print str(e)
        options['sheetmusics'] = database.get_sheetmusics(username)
        options['pictures'] = database.get_images(username)
        return render_template('gallery.html', **options)
コード例 #2
0
def script_route():
    options = {}
    username = '******'
    try:
        if request.method == 'POST':
            if 'op' not in request.form:
                raise RuntimeError('Did you click the button?')
            # if op is add image
            if request.form['op'] == 'add_image':
                upload = request.files['file']
                if upload.filename == '':
                    raise RuntimeError('Empty file is not allowed')
                label = request.form['label']
                check_image_extension(upload)
                image_data = upload.read()
                image_id = hashlib.md5(
                    username + str(datetime.datetime.now())).hexdigest()
                upload.close()
                database.add_image(username, image_data, label, image_id)
            elif request.form['op'] == 'delete_image':
                image_id = request.form['image_id']
                # Delete the image from the database.
                database.delete_image(username, image_id)
        elif request.method == 'GET':
            pass
        options['pictures'] = database.get_images(username)
        return render_template('script.html', **options)
    except Exception as e:
        return str(e)
コード例 #3
0
ファイル: display.py プロジェクト: mdbaum/AMajorFlip
def display_route():
    options = {}
    username = '******'
    try:
        cur_picid = request.args.get('picid')
        pictures_list = database.get_images(username)
        cursheet = ''
        for pictures in pictures_list:
            if pictures['image_id'] == cur_picid:
                cursheet = pictures['sheetmusic']
                break
        curlist = []
        for pictures in pictures_list:
            if pictures['sheetmusic'] == cursheet:
                curlist.append(pictures)
        newlist = sorted(curlist, key=lambda k: k['page'])
        options['pictures'] = newlist
        options['picid'] = cur_picid
        totalpage = len(newlist)
        for i in range(totalpage):
            if newlist[i]['image_id'] == cur_picid:
                if newlist[i]['page'] > 1:
                    options['before'] = newlist[i - 1]['image_id']
                if newlist[i]['page'] != totalpage - 1:
                    options['next'] = newlist[i + 1]['image_id']
        print options['picid']
        return render_template('display.html', **options)
    except Exception as e:
        return str(e)
コード例 #4
0
def main_route():
    options = {}
    username = '******'
    options['sheetmusics'] = database.get_sheetmusics(username)
    options['pictures'] = database.get_images(username)
    return render_template('main.html', **options)
コード例 #5
0
def upload_route():
    options = {}
    username = '******'
    try:
        if request.method == 'POST':
            if 'op' not in request.form:
                raise RuntimeError('Did you click the button?')
            # if op is add image
            if request.form['op'] == 'add_image':
                upload = request.files['file']
                filename = str(upload.filename)
                upload.save('./' + filename)
                if filename == '':
                    raise RuntimeError('Empty file is not allowed')
                sheetid = request.form['label1']
                upload.close()
                if database.check_sheetmusic(username, sheetid) > 0:
                    raise RuntimeError('Duplicate sheetmusic uploaded')
                image_pdf = Image(filename=filename, resolution=300)
                image_jpeg = image_pdf.convert('png')
                req_image = []
                for img in image_jpeg.sequence:
                    img_page = Image(image=img)
                    req_image.append(img_page.make_blob('png'))
                i = 1
                database.add_sheetmusic(username, sheetid)
                isCoverPage = 1
                for img in req_image:
                    ff = open(str(i) + '.png', 'wb')
                    ff.write(img)
                    ff.close()
                    image_data = file(str(i) + '.png').read()
                    image_id = hashlib.md5(
                        username + str(datetime.datetime.now())).hexdigest()
                    if (isCoverPage == 1):
                        database.add_image(username, image_data, sheetid, 0,
                                           image_id)
                        isCoverPage = 0
                    src = str(i) + '.png'
                    rowlist = analyzeSheetMusic(src)
                    splitimage(src, rowlist, '')
                    j = 0
                    for imgi in range(len(rowlist) - 1):
                        image_data = file(str(i) + '_' + str(imgi) +
                                          '.png').read()
                        image_id = hashlib.md5(
                            username +
                            str(datetime.datetime.now())).hexdigest()
                        database.add_image(username, image_data, sheetid,
                                           i + j, image_id)
                        j += 1
                        os.remove(str(i) + '_' + str(imgi) + '.png')
                    os.remove(str(i) + '.png')
                    i = i + j
                os.remove(filename)
            elif request.form['op'] == 'delete_image':
                sheetmusic = request.form['sheetmusic']
                # Delete the image from the database.
                database.delete_image(username, sheetmusic)
            elif request.form['op'] == 'open_image':
                # image_id = request.form['image_id']
                print('halo')
                #print image_id
        elif request.method == 'GET':
            pass
        options['sheetmusics'] = database.get_sheetmusics(username)
        options['pictures'] = database.get_images(username)
        return render_template('upload.html', **options)
    except Exception as e:
        print str(e)
        options['sheetmusics'] = database.get_sheetmusics(username)
        options['pictures'] = database.get_images(username)
        return render_template('upload.html', **options)