@login_required
@app.route('/search/')
def search():
    try:
        page = int(request.args.get('p', 1))
    except (__HOLE__, ValueError):
        page = 1

    query = request.args.get('q')
    has_search = bool(app.config['SEARCH_ENGINE'])

    if query:
        if uuid_re.match(query):
            # Forward to message if it exists
            try:
                event = Event.objects.get(query)
            except Event.DoesNotExist:
                pass
            else:
                return redirect(event.get_absolute_url())
        elif not has_search:
            return render_template('sentry/invalid_message_id.html')
        else:
            # TODO:
            # event_list = get_search_query_set(query)
            raise NotImplementedError
    else:
        event_list = Group.objects.none()
    
    sort = request.args.get('sort')
    if sort == 'date':
        event_list = event_list.order_by('-last_seen')
    elif sort == 'new':
        event_list = event_list.order_by('-first_seen')
    else:
        sort = 'relevance'

    return render_template('sentry/search.html', **{
        'event_list': event_list,
        'query': query,
        'sort': sort,
        'request': request,
        'page': page,
    })
dataset/ETHPy150Open dcramer/sentry-old/sentry/web/views.py/search