示例#1
0
def uploadImage():
    if request.method == "POST":
        f = request.files['file']
        user = session.get('username')
        filename = {f.filename}
        key = user + "-" + str({f.filename})
        s3.put_object("eli.samek.image-gallery", key, f)
        db.add_image(user, key)
        return render_template('main.html')
示例#2
0
def lets_ingest():
    if request.method != 'POST':
        s = 'Submit a <b>POST request</b> to ingest image metadata.<br/>'
        s += 'Example:<code>curl ...</code>'

        return s

    try:
        metadata_dict = json.loads(request.data)
    except:
        return json.dumps(error_tpl(message='POSTed data does not look like JSON'))

    try:
        img_metadata = ImageMetadata.from_dict(metadata_dict)
    except:
        return json.dumps(error_tpl(message='A key is missing'))

    db.add_image(img_metadata)
    return json.dumps(success_tpl(message='Image %s ingested!' % (img_metadata.image_url)))
示例#3
0
def lets_ingest():
    if request.method != 'POST':
        s = 'Submit a <b>POST request</b> to ingest image metadata.<br/>'
        s += 'Example:<code>curl ...</code>'

        return s

    try:
        metadata_dict = json.loads(request.data)
    except:
        return json.dumps(
            error_tpl(message='POSTed data does not look like JSON'))

    try:
        img_metadata = ImageMetadata.from_dict(metadata_dict)
    except:
        return json.dumps(error_tpl(message='A key is missing'))

    db.add_image(img_metadata)
    return json.dumps(
        success_tpl(message='Image %s ingested!' % (img_metadata.image_url)))
示例#4
0
def admin_news():
    """
    GET: render the admin page where the admin can add news.
    POST: read and parse news requests made on this page.
    """
    if request.method == 'GET':
        return render_template('admin_news.html',
                               news=get_news(0, 10),
                               templates=["news.html", "news_scroll.html"])
    if request.method == 'POST':
        date = request.form['date']
        text = json.loads(request.form['text'])
        text = process_editorjs_text(text)
        if not (date and text):
            return jsonify(success=False)
        news_id = add_news(date, text)
        if request.files:
            for image in request.files.values():
                if image.content_type.startswith('image/'):
                    add_image(image.filename.lower(), f'news/{news_id}',
                              image.read())
        return jsonify(success=True)
示例#5
0
def new():
    form = NewForm()
    if form.validate_on_submit():
        url_list = form.url_list.data.replace('\r', '').split('\n')
        # Strip \r and the last empty item. Terrible coding here.
        # url_list = [url[:-1] for url in url_list[:-1]]
        result_list = []
        for url in url_list:
            try:
                metadata = get_remote_metadata(url)
            except requests.exceptions.MissingSchema:
                # Malformed URL given
                continue
            if metadata is None:
                # No valid metadata found in the file
                continue
            add_image(metadata)
            result_list.append(metadata)
        return 'Successfully found this data:<br/>' + '<br/>'.join(
            ['RA: {} Dec: {} url: {}'.format(
                meta.ra_center, meta.dec_center, meta.image_url)
             for meta in result_list])
        # return redirect('/index')
    return render_template('new.html', title='Add new data', form=form)