Ejemplo n.º 1
0
def add_photo():
    uploaded_file = request.files.get('photo_file')
    if not uploaded_file:
        return jsonify({
            'error': 'Must send an `photo_file`'
        }), 400

    if not allowed_file(uploaded_file.filename):
        return jsonify({
            'error': 'Invalid file extension'
        }), 400

    if valid_secret():
        return jsonify({
            'error': 'Invalid request'
        }), 400

    batch_id = request.form.get('batch_id', '')
    is_last = request.form.get('is_last', False)
    tags = request.form.get('tags', '')
    tags = {slugify(t) for t in tags.split(',')}
    skip = request.form.get('skip', '')
    skip = {slugify(t) for t in skip.split(',')}
    tags = [t for t in tags if t]  # Strip empty
    filename = _add_photo(settings, queue, uploaded_file,
                          uploaded_file.filename, tags, skip, batch_id, is_last)
    log.info('Queued file: %s' % filename)
    return '', 201
Ejemplo n.º 2
0
def tag_picture(key):
    picture = db.pictures.by_key(key)
    if request.method == 'GET':
        tags = db.tags.for_picture(picture['id'])
        return render_template('edit_tags.html', **{
            'picture': picture,
            'tags': tags,
            'current_tags': ', '.join(tags)
        })
    else:
        tags = request.form['tags']
        new_tags = {base.slugify(t) for t in tags.split(',')}
        db.tags.change_for_picture(picture['id'], new_tags)
        return redirect(url_for('picture_detail', key=key))
Ejemplo n.º 3
0
def mass_tag():
    if request.method == 'GET':
        return render_template('mass_tag.html')
    else:
        keys = [get_key(k) for k in request.form['keys'].split()]
        tags = request.form['tags']
        new_tags = {base.slugify(t) for t in tags.split(',') if t.strip()}
        if new_tags and keys:
            queue.append({
                'type': 'mass-tag',
                'key': uuid.uuid4().hex,
                'keys': keys,
                'tags': new_tags,
                'attempt': 0
            })
        return redirect('/')
Ejemplo n.º 4
0
def tag_day(year, month, day):
    month = '%02d' % month
    day = '%02d' % day
    year = str(year)
    params = {
        'year': year,
        'month': month,
        'day': day
    }
    total = db.pictures.count(params)
    if request.method == 'GET':
        return render_template('edit_day_tags.html', **{
            'total': total,
            'year': year,
            'month': month,
            'day': day
        })
    else:
        tags = request.form['tags']
        new_tags = {base.slugify(t) for t in tags.split(',') if t.strip()}
        if new_tags:
            tag_day_job(year, month, day, new_tags)
        return redirect(url_for('view_day', year=int(year), month=int(month),
            day=int(day)))