import tornado.escape
import tornado.web
from tinydb import TinyDB,Query,where
+from tinydb.storages import MemoryStorage
from tinydb.operations import delete
from datetime import datetime
if start < 0:
start = 0
rec = sorted(table.all(),key=lambda x: x['number'])[start:start+i]
+ for x in rec:
+ for y in x['comment'].splitlines(True):
+ y = '<p>'+y+'<br></p>'
if len(table) >= 10*i:
self.render('modules/full.htm',position=pos,records=rec,data=params,db=dbname)
return
if word in line:
error = error + u'タグ違反.('+word+')'
i += len(line)
- text = text+'<p>'+self.link(line)+'<br></p>'
+ text = text+self.link(line)
pw = self.get_argument('password')
if sub == '':
sub = u'タイトルなし.'
class SearchHandler(tornado.web.RequestHandler):
def post(self,dbname):
- word = self.get_argument('word1')
- radiobox = self.get_argument('filter')
- self.set_cookie('search',word)
- table = self.application.db.table(dbname)
- self.render('modules/search.htm',records=table.search(where(radiobox).matches(word)),word1=word,db=dbname)
+ self.word = tornado.escape.url_unescape(self.get_argument('word1'))
+ self.radiobox = self.get_argument('filter')
+ self.set_cookie('search',tornado.escape.url_escape(self.word))
+ table = self.application.db.table(dbname)
+ #rec = table.search(where(radiobox).search(word))
+ #rec = sorted(rec,key=lambda x: x['number'])
+ rec = self.search(dbname)
+ self.render('modules/search.htm',records=rec,word1=self.word,db=dbname)
def get(self,dbname):
+ if self.application.collection(dbname) == False:
+ raise tornado.web.HTTPError(404)
+ return
word = self.get_cookie('search')
- self.render('modules/search.htm',records={},word1=word,db=dbname)
+ self.render('modules/search.htm',records=[],word1=word,db=dbname)
+ def search(self,name):
+ table = self.application.db.table(name)
+ mem = TinyDB(storage=MemoryStorage)
+ for word in self.word.split():
+ for x in table.search(where('comment').search(word)):
+ if self.radiobox == 'comment':
+ result = ''
+ for text in x['comment'].splitlines(True):
+ if text.find(word) > -1:
+ result = result+'<p style=background-color:yellow>'+text+'</p>'
+ else:
+ result = result+'<p>'+text+'</p>'
+ if mem.get(where('number') == x['number']) == None:
+ i = mem.insert(x)
+ mem.update({'comment':result},eids=[i])
+ else:
+ rec = table.search(where('name').search(word))
+ return sorted(rec,key=lambda x: x['number'])
+ rec = sorted(mem.all(),key=lambda x: x['number'])
+ mem.close()
+ return rec
+
class FooterModule(tornado.web.UIModule):
def render(self,number,url,link):
return self.render_string('modules/footer.htm',index=number,url=url,link=link)
'ui_modules':{'Footer':FooterModule},
'cookie_secret':'bZJc2sWbQLKos6GkHn/VB9oXwQt8SOROkRvJ5/xJ89E=',
'xsrf_cookies':True,
- #'debug':True,
+ 'debug':True,
'login_url':'/login'
}
tornado.web.Application.__init__(self,handlers,**settings)
<p>検索ワード</p>
<input name=word1 type=search value={{word1}}>
<p><label><input type="radio" name="filter" value="name">名前から検索 </label>
- <label><input type="radio" checked="true" name="filter" value="com">本文から検索</label>
+ <label><input type="radio" checked="true" name="filter" value="comment">本文から検索</label>
</p>
<p>
<input type="submit" value="検索"></p>
-{"bbs": {"1": {"name": "None", "title": "\u3053\u306eBBS\u306f\u3059\u3054\u3044\u3067\u3059\u3002\u3002\u3002\uff20\uff20\uff1b", "password": "", "date": "2016/11/18/16:17", "number": 1, "comment": "<p>\u3053\u306e\u63b2\u793a\u677f\u306f\u3059\u3054\u3044\u3067\u3059\u3002\u4f55\u304c\u3059\u3054\u3044\u306e\u304b\u5229\u7528\u8005\u306b\u306f\u308f\u304b\u3089\u306a\u3044\u3067\u3057\u3087\u3046\u3051\u308c\u3069\u3001\u7ba1\u7406\u8005\u306f\u7ba1\u7406\u304c\u3057\u3084\u3059\u3044\u3067\u3059\u3002\u7c21\u5358\u306b\u904b\u7528\u3067\u304d\u307e\u3059\u3002heroku\u3067git\u3059\u308c\u3070\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u30af\u30ea\u30a2\u3057\u3066\u3059\u3050\u4f7f\u3048\u308b\u72b6\u614b\u306b\u306a\u308a\u307e\u3059\u3002\u6c17\u306b\u3057\u306a\u3044\u4eba\u306f\u305d\u306e\u307e\u307e\u4f7f\u3048\u307e\u3059\u3002\r\n<p>\u3000tornado\u3092\u4f7f\u7528\u3057\u3066\u66f8\u304b\u308c\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u304c\u5927\u5909\u7c21\u7d20\u3067\u3059\u3002\u306a\u304a\u304b\u3064\u30d6\u30ed\u30b0\u30b7\u30b9\u30c6\u30e0\u306b\u30a2\u30c3\u30d7\u304c\u30b0\u30ec\u30fc\u30c9\u3055\u305b\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002\r\n<p>\u3000\u63b2\u793a\u677f\u306e\u7ba1\u7406\u306b\u5fc5\u8981\u306a\u62e1\u5f35\u3067\u3059\u304c\u30c1\u30e3\u30f3\u30cd\u30eb\u306e\u8ffd\u52a0\u306f\u7ba1\u7406\u8005\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u8ffd\u52a0\u3057\u305f\u3044URL\u3092\u6253\u3061\u8fbc\u3080\u3060\u3051\u3002\u305d\u3046\u3059\u308c\u3070\u81ea\u52d5\u3067\u4f5c\u6210\u3055\u308c\u305f\u65b0\u3057\u3044\u30c1\u30e3\u30f3\u30cd\u30eb\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u304f\u308c\u307e\u3059\u3002\r\n<p>\u3000\u3055\u3042\u4f7f\u3044\u305f\u304f\u306a\u308a\u307e\u3057\u305f\u304b\u3002"}}, "bbs1": {}, "bbs2": {}, "bbs3": {}, "_default": {"1": {"title2": "<h1 style=color:gray;text-align:center>pybbs</h1>", "kinds": "conf", "out_words": ["\u6b7b\u306d", "\u963f\u5446", "\u30a2\u30db", "\u99ac\u9e7f", "\u30d0\u30ab"], "title": "pybbs", "password": "admin", "bad_words": ["<style", "<link", "<script", "<img"], "mentenance": false, "count": 30}}}
\ No newline at end of file
+{"bb1": {}, "bbs2": {}, "bbs": {"1": {"date": "2016/11/18/16:17", "title": "\u3053\u306eBBS\u306f\u3059\u3054\u3044\u3067\u3059\u3002\u3002\u3002\uff20\uff20\uff1b", "number": 1, "comment": "<p>\u3053\u306e\u63b2\u793a\u677f\u306f\u3059\u3054\u3044\u3067\u3059\u3002\u4f55\u304c\u3059\u3054\u3044\u306e\u304b\u5229\u7528\u8005\u306b\u306f\u308f\u304b\u3089\u306a\u3044\u3067\u3057\u3087\u3046\u3051\u308c\u3069\u3001\u7ba1\u7406\u8005\u306f\u7ba1\u7406\u304c\u3057\u3084\u3059\u3044\u3067\u3059\u3002\u7c21\u5358\u306b\u904b\u7528\u3067\u304d\u307e\u3059\u3002heroku\u3067git\u3059\u308c\u3070\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u30af\u30ea\u30a2\u3057\u3066\u3059\u3050\u4f7f\u3048\u308b\u72b6\u614b\u306b\u306a\u308a\u307e\u3059\u3002\u6c17\u306b\u3057\u306a\u3044\u4eba\u306f\u305d\u306e\u307e\u307e\u4f7f\u3048\u307e\u3059\u3002\r\n<p>\u3000tornado\u3092\u4f7f\u7528\u3057\u3066\u66f8\u304b\u308c\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u304c\u5927\u5909\u7c21\u7d20\u3067\u3059\u3002\u306a\u304a\u304b\u3064\u30d6\u30ed\u30b0\u30b7\u30b9\u30c6\u30e0\u306b\u30a2\u30c3\u30d7\u304c\u30b0\u30ec\u30fc\u30c9\u3055\u305b\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002\r\n<p>\u3000\u63b2\u793a\u677f\u306e\u7ba1\u7406\u306b\u5fc5\u8981\u306a\u62e1\u5f35\u3067\u3059\u304c\u30c1\u30e3\u30f3\u30cd\u30eb\u306e\u8ffd\u52a0\u306f\u7ba1\u7406\u8005\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u8ffd\u52a0\u3057\u305f\u3044URL\u3092\u6253\u3061\u8fbc\u3080\u3060\u3051\u3002\u305d\u3046\u3059\u308c\u3070\u81ea\u52d5\u3067\u4f5c\u6210\u3055\u308c\u305f\u65b0\u3057\u3044\u30c1\u30e3\u30f3\u30cd\u30eb\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u304f\u308c\u307e\u3059\u3002\r\n<p>\u3000\u3055\u3042\u4f7f\u3044\u305f\u304f\u306a\u308a\u307e\u3057\u305f\u304b\u3002", "name": "None", "password": ""}}, "bbd1": {}, "bbs3": {}, "_default": {"1": {"kinds": "conf", "title": "pybbs", "mentenance": false, "title2": "<h1 style=color:gray;text-align:center>pybbs</h1>", "bad_words": ["<style", "<link", "<script", "<img"], "password": "admin", "count": 30, "out_words": ["\u6b7b\u306d", "\u963f\u5446", "\u30a2\u30db", "\u99ac\u9e7f", "\u30d0\u30ab"]}}, "bbs1": {"1": {"date": "2016/11/21 19:24", "title": "bbs1", "number": 1, "comment": "<p>1<br></p>", "name": "\u8ab0\u304b\u3055\u3093", "password": "admin"}, "2": {"date": "2016/11/21 19:24", "title": "bbs1", "number": 2, "comment": "<p>2<br></p>", "name": "\u8ab0\u304b\u3055\u3093", "password": "admin"}, "3": {"date": "2016/11/21 19:24", "title": "bbs1", "number": 3, "comment": "<p>3<br></p>", "name": "\u8ab0\u304b\u3055\u3093", "password": "admin"}, "4": {"date": "2016/11/21 19:24", "title": "bbs1", "number": 4, "comment": "<p>4<br></p>", "name": "\u8ab0\u304b\u3055\u3093", "password": "admin"}, "5": {"date": "2016/11/21 19:24", "title": "bbs1", "number": 5, "comment": "<p>5<br></p>", "name": "\u8ab0\u304b\u3055\u3093", "password": "admin"}, "6": {"date": "2016/11/21 19:24", "title": "bbs1", "number": 6, "comment": "<p>6<br></p>", "name": "\u8ab0\u304b\u3055\u3093", "password": "admin"}, "7": {"date": "2016/11/21 19:24", "title": "bbs1", "number": 7, "comment": "<p>7<br></p>", "name": "\u8ab0\u304b\u3055\u3093", "password": "admin"}, "8": {"date": "2016/11/21 19:24", "title": "bbs1", "number": 8, "comment": "<p>8<br></p>", "name": "\u8ab0\u304b\u3055\u3093", "password": "admin"}, "9": {"date": "2016/11/21 19:25", "title": "bbs1", "number": 9, "comment": "<p>9<br></p>", "name": "\u8ab0\u304b\u3055\u3093", "password": "admin"}, "10": {"date": "2016/11/21 19:25", "title": "bbs1", "number": 10, "comment": "<p>10<br></p>", "name": "\u8ab0\u304b\u3055\u3093", "password": "admin"}, "11": {"date": "2016/11/21 19:38", "title": "bbs1", "number": 11, "comment": "<p>test<br></p>", "name": "\u8ab0\u304b\u3055\u3093", "password": "admin"}, "12": {"date": "2016/11/21 19:41", "title": "bbs1", "number": 12, "comment": "<p>1<br></p>", "name": "1", "password": "admin"}, "13": {"date": "2016/11/22 17:02", "title": "bbs1", "number": 13, "comment": "test \r\n\r\nit \r\n\r\nsi not same", "name": "1", "password": "admin"}, "14": {"date": "2016/11/22 18:26", "title": "bbs1", "number": 14, "comment": "test", "name": "1", "password": "admin"}, "15": {"date": "2016/11/22 18:32", "title": "bbs1", "number": 15, "comment": "t s t", "name": "1", "password": "admin"}}}
\ No newline at end of file