

@app.route('/shred/<string:cluster_id>', methods=['GET', 'POST'])
@login.login_required
def shred(cluster_id):
    cluster = Cluster.objects.get(id=cluster_id)
    if (not cluster):
        abort(404)
    if (request.method == 'POST'):
        tags = set(map(unicode.lower, request.form.getlist('tags')))
        user_tags = cluster.get_user_tags(g.user)
        if (not user_tags):
            abort(404)
        user_tags.tags = list(tags)
        user_tags.recognizable_chars = request.form.get('recognizable_chars', '')
        user_tags.angle = int(request.form.get('angle', 0))
        cluster.save()
        User.objects(pk=g.user.id).update_one(add_to_set__tags=list(tags))
        for tag in tags:
            Tags.objects(pk=tag).update_one(set_on_insert__is_base=False, set_on_insert__created_by=g.user.id, set_on_insert__created_at=Tags().created_at, inc__usages=1, add_to_set__shreds=request.form['_id'], upsert=True)
        return render_template('_shred_snippet.html', cluster=cluster)
    else:
        return render_template('_shred.html', cluster=cluster, auto_tags=cluster.auto_tags, all_tags=get_tags(), user_data=cluster.get_user_tags(g.user), edit=True)

dataset/ETHPy150Open dchaplinsky/unshred-tag/app.py shred/original