<commit_before># -*- coding: utf-8 -*-
from flask import Blueprint, redirect, url_for, request, abort
from flask_login import current_user
from flask.ext.login import login_required
from urllib.parse import urlparse
from .models import ChartBlock


blueprint = Blueprint("content", __name__, url_prefix='/content',
                      static_folder="../static")

@blueprint.route("/<string:chart_slug>/<int:department_id>", methods=["POST"])
@login_required
def edit_chart_block(department_id, chart_slug):
    block = ChartBlock.query.filter_by(department_id=department_id, slug=chart_slug).first()

    if not block:
        abort(404)

    if not current_user.has_department(department_id) and not current_user.is_admin():
        abort(401)

    block.title = request.form["chart_title"]
    block.content = request.form["chart_content"]

    block.save()

    if 'edit' in request.referrer:
        new_path = urlparse(request.referrer.replace('/edit/', '/preview/')).path
    else:
        new_path = url_for(
            'department.department_dashboard', department_id=department_id
        )

    return redirect(new_path)<commit_msg>make sure we don't error if there's no referrer<commit_after># -*- coding: utf-8 -*-
from flask import Blueprint, redirect, url_for, request, abort
from flask_login import current_user
from flask.ext.login import login_required
from urllib.parse import urlparse
from .models import ChartBlock


blueprint = Blueprint("content", __name__, url_prefix='/content',
                      static_folder="../static")

@blueprint.route("/<string:chart_slug>/<int:department_id>", methods=["POST"])
@login_required
def edit_chart_block(department_id, chart_slug):
    block = ChartBlock.query.filter_by(department_id=department_id, slug=chart_slug).first()

    if not block:
        abort(404)

    if not current_user.has_department(department_id) and not current_user.is_admin():
        abort(401)

    block.title = request.form["chart_title"]
    block.content = request.form["chart_content"]

    block.save()

    if request.referrer and 'edit' in request.referrer:
        new_path = urlparse(request.referrer.replace('/edit/', '/preview/')).path
    else:
        new_path = url_for(
            'department.department_dashboard', department_id=department_id
        )

    return redirect(new_path)
{'fraction_non_alphanumeric': 0.11641791044776119, 'fraction_numerical': 0.005970149253731343, 'mean_word_length': 3.907949790794979, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2609158', 'n_tokens_mistral': 747, 'n_tokens_neox': 712, 'n_words': 151}