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