<commit_before>from pyramid.response import Response
from pyramid.view import view_config
from pyramid.httpexceptions import HTTPFound
from .form import JournalForm
from sqlalchemy.exc import DBAPIError
import transaction

from .models import (
    DBSession,
    Entry,
    )




@view_config(route_name='home', renderer='templates/list_view.jinja2', permission='view')
def list_view(request):
    """Handle the view of our home page."""
    return {'entries': DBSession.query(Entry).all()}


@view_config(route_name='detail_view', renderer='templates/detail_view.jinja2', permission='view')
def detail_view(request):
    """Handle the view of a single journaly entry."""
    this_id = request.matchdict['this_id']
    entry = DBSession.query(Entry).filter(Entry.id == this_id).first()
    return {'entry': entry}


@view_config(route_name='add_view', renderer='templates/add_view.jinja2')
def add_view(request):
    """Handle the view of our adding new entry page."""
    form = JournalForm(request.POST)
    if request.method == "POST" and form.validate():
        new_entry = Entry(title=form.title.data, text=form.text.data)
        DBSession.add(new_entry)
        DBSession.flush()
        this_id = new_entry.id
        transaction.commit()
        raise HTTPFound(location='/detail/{}'.format(this_id))
    return {'form': form}




@view_config(route_name='edit_view', renderer='templates/edit_view.jinja2')
def edit_view(request):
    """Handle the view of our edit entry page."""
    pass



conn_err_msg = """
Pyramid is having a problem using your SQL database.  The problem
might be caused by one of the following things:

1.  You may need to run the "initialize_learning_journal_db" script
    to initialize your database tables.  Check your virtual
    environment's "bin" directory for this script and try to run it.

2.  Your database server may not be running.  Check that the
    database server referred to by the "sqlalchemy.url" setting in
    your "development.ini" file is running.

After you fix the problem, please restart the Pyramid application to
try it again.
"""<commit_msg>Add permissions to edit/add views'<commit_after>from pyramid.response import Response
from pyramid.view import view_config
from pyramid.httpexceptions import HTTPFound
from .form import JournalForm
from sqlalchemy.exc import DBAPIError
import transaction

from .models import (
    DBSession,
    Entry,
    )




@view_config(route_name='home', renderer='templates/list_view.jinja2', permission='view')
def list_view(request):
    """Handle the view of our home page."""
    return {'entries': DBSession.query(Entry).all()}


@view_config(route_name='detail_view', renderer='templates/detail_view.jinja2', permission='view')
def detail_view(request):
    """Handle the view of a single journaly entry."""
    this_id = request.matchdict['this_id']
    entry = DBSession.query(Entry).filter(Entry.id == this_id).first()
    return {'entry': entry}


@view_config(route_name='add_view', renderer='templates/add_view.jinja2', permission='add')
def add_view(request):
    """Handle the view of our adding new entry page."""
    form = JournalForm(request.POST)
    if request.method == "POST" and form.validate():
        new_entry = Entry(title=form.title.data, text=form.text.data)
        DBSession.add(new_entry)
        DBSession.flush()
        this_id = new_entry.id
        transaction.commit()
        raise HTTPFound(location='/detail/{}'.format(this_id))
    return {'form': form}




@view_config(route_name='edit_view', renderer='templates/edit_view.jinja2', permission='edit')
def edit_view(request):
    """Handle the view of our edit entry page."""
    pass



conn_err_msg = """
Pyramid is having a problem using your SQL database.  The problem
might be caused by one of the following things:

1.  You may need to run the "initialize_learning_journal_db" script
    to initialize your database tables.  Check your virtual
    environment's "bin" directory for this script and try to run it.

2.  Your database server may not be running.  Check that the
    database server referred to by the "sqlalchemy.url" setting in
    your "development.ini" file is running.

After you fix the problem, please restart the Pyramid application to
try it again.
"""
{'fraction_non_alphanumeric': 0.10674157303370786, 'fraction_numerical': 0.0028089887640449437, 'mean_word_length': 4.223716381418093, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '890894', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1233, 'n_words': 400}