Exemplo n.º 1
0
def find_screenshot_from_post(postId):
    # check for screenshot
    ssUrl = None
    ssTitle = None
    ss = Screenshot.query.filter(Screenshot.postId == postId).first() 
    if ss:
        ssUrl = screenshots.url(ss.filename)
        ssTitle = ss.filename
    return (ssUrl, ssTitle)
Exemplo n.º 2
0
def add_feedback():
    user = g.user
    # print user
    # print request.form
    # print request.files
    if user.is_anonymous():
        handle_request_error(401)
    if request.method == 'GET':
        return render_template('add_feedback.html')
    p = Post (title=request.form['title'], text=request.form['text'], \
        timestamp=datetime.datetime.utcnow(), points=0, userId=user.id)
    if request.form.get('test'):
        flash('Staging feedback')
        filename = None
        ssUrl = None
        if 'screenshot' in request.files:
            filename = screenshots.save(request.files['screenshot'])
            ssUrl = screenshots.url(filename)
        if 'screenshotDataUrl' in request.form:
            # May fail if multiple users post in the same microsecond
            dataUrl = request.form['screenshotDataUrl'].split(',')
            decodedScreenshot = b64decode(dataUrl[1])
            filename = '%s.png' % (int(time.time() * 1000000))
            f = open ('%s\\%s' % (UPLOADED_SCREENSHOTS_DEST, filename), 'wb')
            f.write(decodedScreenshot)
            ssUrl = screenshots.url(filename)            
            f.close()
        return render_template('show.html', post=p,
            url=ssUrl, filename=filename)
    db.session.add(p)
    db.session.commit()
    app.logger.debug('Post saved: Post id=%d, Title=%s' % (p.id, p.title))
    flash('New feedback was successfully posted')
    if 'filename' in request.form.keys():
        handle_screenshot_upload(p.id, request.form['filename'])
    # handle_screenshot_upload(p.id, request.form['filename'] if 'filename' in request.form else None)
    handle_notes_upload(p.id)
    return redirect(url_for('show_feedback'))