5 __author__ = "Oleg Broytman <phd@phdru.name>"
6 __copyright__ = "Copyright (C) 2014-2017 PhiloSoft Design"
7 __license__ = "GNU GPL"
10 from lark import ParseError
11 from html.response import redirect, response
12 from parser import parser
14 form = cgi.FieldStorage()
15 if not form.has_key('q'):
16 status = "400 Bad request"
18 body = "Required parameter is missing!"
23 tree = parser.parse(q)
25 status = "400 Bad request"
27 body = "Bad query syntax!"
29 if tree[0] == 'NAME': # Single tag - just do redirect
31 assert isinstance(tag, str)
32 from tags import tag_exists
34 redirect("/Russian/blog/tags/%s.html" % tag, status="301 Moved")
36 status = "404 Tag not found"
38 body = "Тег %s не существует!" % tag
40 from tags import find_tags
41 posts = find_tags(tree)
43 title = "Записи, найденные для выражения " + cgi.escape(q)
49 for year, month, day, suburl, _title in posts:
50 _posts.append('<li>%s-%s-%s <a href="../../../../Russian/blog/%s">%s</a></li>\n' % (year, month, day, suburl, _title))
55 body = ''.join(_posts)
57 body = "Не найдено ни одной записи."
59 response(title, body, status)