X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=search-tags.py;h=fe006bfd5b69f41d1759baa56b8905ad1da58893;hb=af6063f9b0099f34c8817cd5c63802a160bc0463;hp=9bdfc8bb5bc1e4cd6711e6f7f4caad5fe5bc464c;hpb=805b4f5ed00d30d3e39a19fc2d6d0afa65e86e92;p=phdru.name%2Fcgi-bin%2Fblog-ru%2Fsearch-tags.git diff --git a/search-tags.py b/search-tags.py index 9bdfc8b..fe006bf 100755 --- a/search-tags.py +++ b/search-tags.py @@ -1,14 +1,15 @@ #! /usr/bin/env python +# coding: koi8-r """Search tags CGI""" __author__ = "Oleg Broytman " __copyright__ = "Copyright (C) 2014 PhiloSoft Design" __license__ = "GNU GPL" -import cgi +import cgi, sys from ply.lex import LexError -from html.response import response +from html.response import redirect, response from parser.parser import parser form = cgi.FieldStorage() @@ -27,5 +28,34 @@ else: status = "400 Bad request" title = "Error!" body = "Bad query syntax!" + elif tree[0] == 'NAME': # Single tag - just do redirect + tag = tree[1] + assert isinstance(tag, str) + from tags import tag_exists + if tag_exists(tag): + redirect("/Russian/blog/tags/%s.html" % tag, status="301 Moved") + sys.exit() + status = "404 Tag not found" + title = "ïÛÉÂËÁ!" + body = "ôÅÇ %s ÎÅ ÓÕÝÅÓÔ×ÕÅÔ!" % tag + else: # Process tree + from tags import find_tags + posts = find_tags(tree) + status = None + title = "úÁÐÉÓÉ, ÎÁÊÄÅÎÎÙÅ ÄÌÑ ×ÙÒÁÖÅÎÉÑ " + q + if posts: + _posts = ["""\ +

+

+

+""") + body = ''.join(_posts) + else: + body = "îÅ ÎÁÊÄÅÎÏ ÎÉ ÏÄÎÏÊ ÚÁÐÉÓÉ." response(title, body, status)