<commit_before>#! usr/bin/python3
# -*- coding: utf-8 -*-
#
# Flicket - copyright <NAME>: <EMAIL>

import datetime

from flask import render_template, redirect, url_for, g, request, flash
from flask_login import login_required
from flask_babel import gettext

from . import flicket_bp
from application import app, db
from application.flicket.forms.flicket_forms import ReplyForm, SubscribeUser
from application.flicket.models.flicket_models import FlicketTicket
from application.flicket.models.flicket_models import FlicketStatus
from application.flicket.models.flicket_models import FlicketPriority
from application.flicket.models.flicket_models import FlicketPost
from application.flicket.models.flicket_models import FlicketSubscription
from application.flicket.models.flicket_user import FlicketUser
from application.flicket.scripts.flicket_functions import add_action
from application.flicket.scripts.flicket_functions import block_quoter
from application.flicket.scripts.flicket_upload import UploadAttachment
from application.flicket.scripts.email import FlicketMail
from application.flicket.scripts.subscriptions import subscribe_user


# view ticket details
@flicket_bp.route(app.config['FLICKET'] + 'ticket_view/<ticket_id>/', methods=['GET', 'POST'])
@flicket_bp.route(app.config['FLICKET'] + 'ticket_view/<ticket_id>/<int:page>/', methods=['GET', 'POST'])
@login_required
def ticket_view(ticket_id, page=1):
    # todo: make sure underscores aren't allowed in usernames as it breaks markdown?

    # is ticket number legitimate
    ticket = FlicketTicket.query.filter_by(id=ticket_id).first()

    if not ticket:
        flash(gettext('Cannot find ticket: "%(value)s"', value=ticket_id), category='warning')
        return redirect(url_for('flicket_bp.tickets'))

    # find all replies to ticket.
    replies = FlicketPost.query.filter_by(ticket_id=ticket_id).order_by(FlicketPost.date_added.asc())

    # get reply id's
    post_rid = request.args.get('post_rid')
    ticket_rid = request.args.get('ticket_rid')

    form = ReplyForm()
    subscribers_form = SubscribeUser()

    # add subscribed user
    if subscribers_form.validate_on_submit():
        user = FlicketUser.query.filter_by(username=subscribers_form.username.data).first()
        if subscribe_user(ticket, user):
            flash(gettext('User subscribed.'), category='success')
        else:
            flash(gettext('User already subscribed.'), category="warning")

    # add reply post
    if form.validate_on_submit():
        # upload file if user has selected one and the file is in accepted list of
        files = request.files.getlist("file")
        upload_attachments = UploadAttachment(files)
        if upload_attachments.are_attachements():
            upload_attachments.upload_files()
<commit_msg>redirect after adding a user to prevent form errors from being triggered<commit_after>#! usr/bin/python3
# -*- coding: utf-8 -*-
#
# Flicket - copyright <NAME>: <EMAIL>

import datetime

from flask import render_template, redirect, url_for, g, request, flash
from flask_login import login_required
from flask_babel import gettext

from . import flicket_bp
from application import app, db
from application.flicket.forms.flicket_forms import ReplyForm, SubscribeUser
from application.flicket.models.flicket_models import FlicketTicket
from application.flicket.models.flicket_models import FlicketStatus
from application.flicket.models.flicket_models import FlicketPriority
from application.flicket.models.flicket_models import FlicketPost
from application.flicket.models.flicket_models import FlicketSubscription
from application.flicket.models.flicket_user import FlicketUser
from application.flicket.scripts.flicket_functions import add_action
from application.flicket.scripts.flicket_functions import block_quoter
from application.flicket.scripts.flicket_upload import UploadAttachment
from application.flicket.scripts.email import FlicketMail
from application.flicket.scripts.subscriptions import subscribe_user


# view ticket details
@flicket_bp.route(app.config['FLICKET'] + 'ticket_view/<ticket_id>/', methods=['GET', 'POST'])
@flicket_bp.route(app.config['FLICKET'] + 'ticket_view/<ticket_id>/<int:page>/', methods=['GET', 'POST'])
@login_required
def ticket_view(ticket_id, page=1):
    # todo: make sure underscores aren't allowed in usernames as it breaks markdown?

    # is ticket number legitimate
    ticket = FlicketTicket.query.filter_by(id=ticket_id).first()

    if not ticket:
        flash(gettext('Cannot find ticket: "%(value)s"', value=ticket_id), category='warning')
        return redirect(url_for('flicket_bp.tickets'))

    # find all replies to ticket.
    replies = FlicketPost.query.filter_by(ticket_id=ticket_id).order_by(FlicketPost.date_added.asc())

    # get reply id's
    post_rid = request.args.get('post_rid')
    ticket_rid = request.args.get('ticket_rid')

    form = ReplyForm()
    subscribers_form = SubscribeUser()

    # add subscribed user
    if subscribers_form.validate_on_submit():
        user = FlicketUser.query.filter_by(username=subscribers_form.username.data).first()
        if subscribe_user(ticket, user):
            flash(gettext('User subscribed.'), category='success')
        else:
            flash(gettext('User already subscribed.'), category="warning")
        return redirect(url_for('flicket_bp.ticket_view', ticket_id=ticket_id))


    # add reply post
    if form.validate_on_submit():
        # upload file if user has selected one and the file is in accepted list of
        files = request.files.getlist("file")
        upload_attachments = UploadAttachment(files)
        if upload_attachments.are_attachements():
            upload_attachments.upload_files()

{'fraction_non_alphanumeric': 0.09644227415416812, 'fraction_numerical': 0.0010463899546564353, 'mean_word_length': 4.8460754332313964, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '7235836', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1712, 'n_words': 396}