<commit_before>import datetime

from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
from pyramid.view import view_config
from pyramid.httpexceptions import (
    HTTPSeeOther,
    HTTPBadRequest, HTTPNotFound, HTTPUnauthorized
)
from ccvpn.models import (
    DBSession,
    GiftCode, AlreadyUsedGiftCode,
    Order,
)


def order_post_gc(request, code):
    try:
        gc = GiftCode.one(code=code)
        gc.use(request.user)

        time = gc.time.days
        request.messages.info(_('OK! Added ${time} days to your account.',
                                mapping={'time': time}))
        DBSession.flush()
    except (NoResultFound, MultipleResultsFound):
        request.messages.error(_('Unknown gift code.'))
    except AlreadyUsedGiftCode:
        request.messages.error(_('Gift code already used.'))
    return HTTPSeeOther(location=request.route_url('account'))


@view_config(route_name='order_post', permission='logged')
def order_post(request):
    _ = request.translate
    code = request.POST.get('code')
    if code:<commit_msg>fix _<commit_after>import datetime

from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
from pyramid.view import view_config
from pyramid.httpexceptions import (
    HTTPSeeOther,
    HTTPBadRequest, HTTPNotFound, HTTPUnauthorized
)
from ccvpn.models import (
    DBSession,
    GiftCode, AlreadyUsedGiftCode,
    Order,
)


def order_post_gc(request, code):
    _ = request.translate
    try:
        gc = GiftCode.one(code=code)
        gc.use(request.user)

        time = gc.time.days
        request.messages.info(_('OK! Added ${time} days to your account.',
                                mapping={'time': time}))
        DBSession.flush()
    except (NoResultFound, MultipleResultsFound):
        request.messages.error(_('Unknown gift code.'))
    except AlreadyUsedGiftCode:
        request.messages.error(_('Gift code already used.'))
    return HTTPSeeOther(location=request.route_url('account'))


@view_config(route_name='order_post', permission='logged')
def order_post(request):
    _ = request.translate
    code = request.POST.get('code')
    if code:
{'fraction_non_alphanumeric': 0.10697674418604651, 'fraction_numerical': 0.0, 'mean_word_length': 3.3719512195121952, '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': '877482', 'n_tokens_mistral': 653, 'n_tokens_neox': 626, 'n_words': 135}