<commit_before>import flask
from ..models import User, Organization, Repository
from ..helpers import ViewTab

core = flask.Blueprint('core', __name__, url_prefix='')


@core.route('/')
def index():
    return flask.render_template('core/index.html')


@core.route('/search')
@core.route('/search/<query>')
def search(query=None):
    # TODO: do query in DB and send results to view
    return flask.render_template('core/search.html')


@core.route('/user/<login>')
def user_detail(login):
    user = User.query.filter_by(login=login).first()
    if user is None:
        is_org = Organization.query.filter(
            Organization.login == login
        ).exists()
        if is_org:
            # TODO: implement 410 (user deleted/archived)
            # TODO: user renaming
            flask.abort(404)
        flask.flash('Oy! You wanted to access user, but it\'s an organization.'
                    'We redirected you but be careful next time!', 'notice')
        return flask.redirect(flask.url_for('core.org', login=login))

    # TODO: gather & prepare tabs & pass to template
    tabs = [
        ViewTab(
            'details', 'Details', 0,
            flask.render_template('core/user/details_tab.html', user=user)
        ),
        ViewTab(
            'repositories', 'Repositories', 1,
            flask.render_template('core/user/repositories_tab.html', user=user)
        ),
    ]

    return flask.render_template(
        'core/user.html', user=user, tabs=tabs,
        active_tab=flask.request.args.get('tab', 'details')
    )


@core.route('/org/<login>')
def org_detail(login):
    org = User.query.filter_by(login=login).first()
    if org is None:
        is_user = User.query.filter_by(login=login).exists()
        if is_user:
            # TODO: implement 410 (org deleted/archived)
            # TODO: org renaming
            flask.abort(404)
        flask.flash('Oy! You wanted to access organization, but it\'s  auser.'
                    'We redirected you but be careful next time!', 'notice')

    # TODO: gather & prepare tabs & pass to template
    tabs = [
        ViewTab(
            'details', 'Details', 0,
            flask.render_template('core/org/details_tab.html', org=org)
        ),
        ViewTab(
            'repositories', 'Repositories', 1,
            flask.render_template('core/org/repositories_tab.html', org=org)
        ),
    ]

    return flask.render_template(
        'core/org.html', org=org, tabs=tabs,
        active_tab=flask.request.args.get('tab', 'details')
    )


@core.route('/repo/<login>')
def repo_redir(login):
    flask.flash('Seriously?! You forget to specify repository name, didn\'t '
                'you? We redirected you but be careful next time!', 'notice')
    return flask.redirect(flask.url_for('user', login=login))


@core.route('/repo/<login>/<reponame>')
def repo_detail(login, reponame):
    repo = Repository.query.filter_by(
        full_name='{}/{}'.format(login, reponame),
    ).first()
    if not repo.is_public():
        # TODO: 404 or 410 (if were public in the past)?
        flask.abort(404)
    if repo is None:
        # TODO: implement 410 (repo deleted/archived)
        # TODO: repository renaming
        flask.abort(404)

    # TODO: gather & prepare tabs
    tabs = [
        ViewTab(
            'details', 'Details', 0,
            flask.render_template('core/repo/details_tab.html', repo=repo)
        ),
        ViewTab(
            'releases', 'Releases', 1,
            flask.render_template('core/repo/releases_tab.html', repo=repo)
        ),
        ViewTab(
            'updates', 'Updates', 2,
            flask.render_template('core/repo/updates_tab.html', repo=repo)
        ),
    ]

    return flask.render_template(
        'core/repo.html', repo=repo, tabs=tabs,
        active_tab=flask.request.args.get('tab', 'details')
    )<commit_msg>Fixing repo detail(s) controllers<commit_after>import flask
import flask_login
from ..models import User, Organization, Repository
from ..helpers import ViewTab

core = flask.Blueprint('core', __name__, url_prefix='')


@core.route('/')
def index():
    return flask.render_template('core/index.html')


@core.route('/search')
@core.route('/search/<query>')
def search(query=None):
    # TODO: do query in DB and send results to view
    return flask.render_template('core/search.html')


@core.route('/user/<login>')
def user_detail(login):
    user = User.query.filter_by(login=login).first()
    if user is None:
        is_org = Organization.query.filter(
            Organization.login == login
        ).exists()
        if is_org:
            # TODO: implement 410 (user deleted/archived)
            # TODO: user renaming
            flask.abort(404)
        flask.flash('Oy! You wanted to access user, but it\'s an organization.'
                    'We redirected you but be careful next time!', 'notice')
        return flask.redirect(flask.url_for('core.org', login=login))

    # TODO: gather & prepare tabs & pass to template
    tabs = [
        ViewTab(
            'details', 'Details', 0,
            flask.render_template('core/user/details_tab.html', user=user)
        ),
        ViewTab(
            'repositories', 'Repositories', 1,
            flask.render_template('core/user/repositories_tab.html', user=user)
        ),
    ]

    return flask.render_template(
        'core/user.html', user=user, tabs=tabs,
        active_tab=flask.request.args.get('tab', 'details')
    )


@core.route('/org/<login>')
def org_detail(login):
    org = User.query.filter_by(login=login).first()
    if org is None:
        is_user = User.query.filter_by(login=login).exists()
        if is_user:
            # TODO: implement 410 (org deleted/archived)
            # TODO: org renaming
            flask.abort(404)
        flask.flash('Oy! You wanted to access organization, but it\'s  auser.'
                    'We redirected you but be careful next time!', 'notice')

    # TODO: gather & prepare tabs & pass to template
    tabs = [
        ViewTab(
            'details', 'Details', 0,
            flask.render_template('core/org/details_tab.html', org=org)
        ),
        ViewTab(
            'repositories', 'Repositories', 1,
            flask.render_template('core/org/repositories_tab.html', org=org)
        ),
    ]

    return flask.render_template(
        'core/org.html', org=org, tabs=tabs,
        active_tab=flask.request.args.get('tab', 'details')
    )


@core.route('/repo/<login>')
def repo_redir(login):
    flask.flash('Seriously?! You forget to specify repository name, didn\'t '
                'you? We redirected you but be careful next time!', 'notice')
    return flask.redirect(flask.url_for('user', login=login))


@core.route('/repo/<login>/<reponame>')
def repo_detail(login, reponame):
    repo = Repository.query.filter_by(
        full_name='{}/{}'.format(login, reponame),
    ).first()
    if repo is None:
        # TODO: implement 410 (repo deleted/archived)
        # TODO: repository renaming
        flask.abort(404)
    if not repo.is_public() and repo.user != flask_login.current_user:
        # TODO: 404 or 410 (if were public in the past)?
        flask.abort(404)

    # TODO: gather & prepare tabs
    tabs = [
        ViewTab(
            'details', 'Details', 0,
            flask.render_template('core/repo/details_tab.html', repo=repo)
        ),
        ViewTab(
            'releases', 'Releases', 1,
            flask.render_template('core/repo/releases_tab.html', repo=repo)
        ),
        ViewTab(
            'updates', 'Updates', 2,
            flask.render_template('core/repo/updates_tab.html', repo=repo)
        ),
    ]

    return flask.render_template(
        'core/repo.html', repo=repo, tabs=tabs,
        active_tab=flask.request.args.get('tab', 'details')
    )


# TODO: DRY (similar to repo_detail)
@core.route('/hidden-repo/<secret>')
def repo_detail_hidden(secret):
    repo = Repository.query.filter_by(secret=secret).first()
    if repo is None:
        # TODO: implement 410 (repo deleted/archived)
        # TODO: repository renaming
        flask.abort(404)
    if not repo.is_hidden():
        # TODO: 404 or 410 (if were hidden in the past)?
        flask.abort(404)

    # TODO: gather & prepare tabs
    tabs = [
        ViewTab(
            'details', 'Details', 0,
            flask.render_template('core/repo/details_tab.html', repo=repo)
        ),
        ViewTab(
            'releases', 'Releases', 1,
            flask.render_template('core/repo/releases_tab.html', repo=repo)
        ),
        ViewTab(
            'updates', 'Updates', 2,
            flask.render_template('core/repo/updates_tab.html', repo=repo)
        ),
    ]

    return flask.render_template(
        'core/repo.html', repo=repo, tabs=tabs,
        active_tab=flask.request.args.get('tab', 'details')
    )
{'fraction_non_alphanumeric': 0.13529345499605722, 'fraction_numerical': 0.009687957643347978, 'mean_word_length': 2.4015325670498084, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '5280158', 'n_tokens_mistral': 2868, 'n_tokens_neox': 2717, 'n_words': 611}