def test_delete(self): aa = MWiki.query_all() tf = True for i in aa: if i.title == self.wiki_title: tf = False break assert tf self.add_mess() tf = False aa = MWiki.query_all() for i in aa: if i.uid == self.uid: tf = True break assert tf MWiki.delete(self.uid) aa = MWiki.query_all() tf = True for i in aa: if i.title == self.wiki_title: tf = False break self.tearDown() assert tf
def update(self, slug): ''' Update the page. :param slug: :return: ''' print("*" * 50) print(slug) if self.__could_edit(slug): pass else: return False post_data = self.get_post_data() post_data['user_name'] = self.userinfo.user_name pageinfo = MWiki.get_by_uid(slug) cnt_old = tornado.escape.xhtml_unescape(pageinfo.cnt_md).strip() cnt_new = post_data['cnt_md'].strip() if cnt_old == cnt_new: pass else: MWikiHist.create_wiki_history(MWiki.get_by_uid(slug)) MWiki.update(slug, post_data) tornado.ioloop.IOLoop.instance().add_callback(self.cele_gen_whoosh) self.redirect('/page/{0}.html'.format(post_data['slug']))
def gen_wiki_map(file_name, ext_url=''): ''' Generate the urls for wiki. :return: None ''' # for wiki. wiki_recs = MWiki.query_all(limit=10000, kind='1') with open(file_name, 'a') as fileout: for rec in wiki_recs: url = os.path.join(SITE_CFG['site_url'], 'wiki' + ('/_edit' if ext_url else ''), rec.title) fileout.write('{url}\n'.format(url=url)) # for page. page_recs = MWiki.query_all(limit=10000, kind='2') with open(file_name, 'a') as fileout: for rec in page_recs: url = os.path.join(SITE_CFG['site_url'], 'page' + ('/_edit' if ext_url else ''), rec.uid) fileout.write('{url}\n'.format(url=url))
def update(self, uid): ''' Update the post via ID. ''' if self.userinfo.role[0] > '0': pass else: return False post_data = self.get_post_data() post_data[ 'user_name'] = self.userinfo.user_name if self.userinfo else '' cur_info = MWiki.get_by_uid(uid) cnt_old = tornado.escape.xhtml_unescape(cur_info.cnt_md).strip() cnt_new = post_data['cnt_md'].strip() if cnt_old == cnt_new: pass else: MWikiHist.create_wiki_history(cur_info, self.userinfo) MWiki.update_cnt(uid, post_data) if cur_info.kind == '1': self.redirect('/wiki/{0}'.format(cur_info.title)) elif cur_info.kind == '2': self.redirect('/page/{0}.html'.format(cur_info.uid))
def update(self, uid): ''' Update the wiki. :param uid: The ID of the wiki. :return: ''' postinfo = MWiki.get_by_uid(uid) if self.check_post_role( )['EDIT'] or postinfo.user_name == self.get_current_user(): pass else: return False post_data = self.get_post_data() post_data['user_name'] = self.userinfo.user_name cnt_old = tornado.escape.xhtml_unescape(postinfo.cnt_md).strip() cnt_new = post_data['cnt_md'].strip() if cnt_old == cnt_new: pass else: MWikiHist.create_wiki_history(postinfo) MWiki.update(uid, post_data) # cele_gen_whoosh.delay() tornado.ioloop.IOLoop.instance().add_callback(self.cele_gen_whoosh) self.redirect('/wiki/{0}'.format( tornado.escape.url_escape(post_data['title'])))
def restore(self, hist_uid): ''' Restore by ID ''' if self.check_post_role()['ADMIN']: pass else: return False histinfo = MWikiHist.get_by_uid(hist_uid) if histinfo: pass else: return False postinfo = MWiki.get_by_uid(histinfo.wiki_id) cur_cnt = tornado.escape.xhtml_unescape(postinfo.cnt_md) old_cnt = tornado.escape.xhtml_unescape(histinfo.cnt_md) MWiki.update_cnt(histinfo.wiki_id, { 'cnt_md': old_cnt, 'user_name': self.userinfo.user_name }) MWikiHist.update_cnt(histinfo.uid, { 'cnt_md': cur_cnt, 'user_name': postinfo.user_name }) if postinfo.kind == '1': self.redirect('/wiki/{0}'.format(postinfo.title)) elif postinfo.kind == '2': self.redirect('/page/{0}.html'.format(postinfo.uid))
def p_list( self, kind, cur_p='', ): ''' List the post . ''' if cur_p == '': current_page_number = 1 else: current_page_number = int(cur_p) current_page_number = 1 if current_page_number < 1 else current_page_number pager_num = int(MWiki.total_number(kind) / CMS_CFG['list_num']) kwd = { 'pager': '', 'title': 'Recent pages.', 'kind': kind, 'current_page': current_page_number, 'page_count': MWiki.get_counts(), } self.render('admin/page_ajax/page_list.html', postrecs=MWiki.query_pager_by_kind( kind=kind, current_page_num=current_page_number), kwd=kwd)
def test_get_by_title(self): self.add_mess() ss = MWiki.get_by_uid(self.uid) assert ss.title == self.wiki_title tt = MWiki.get_by_title(self.wiki_title) assert tt.title == self.wiki_title self.tearDown()
def add(self, title=''): ''' Add wiki ''' post_data = self.get_post_data() if title == '': pass else: post_data['title'] = title post_data['user_name'] = self.get_current_user() if len(post_data['title'].strip()) < 2: kwd = { 'info': 'Title cannot be less than 2 characters', 'link': '/' } self.render('misc/html/404.html', userinfo=self.userinfo, kwd=kwd) if MWiki.get_by_wiki(post_data['title']): pass else: MWiki.create_wiki(post_data) tornado.ioloop.IOLoop.instance().add_callback(self.cele_gen_whoosh) # cele_gen_whoosh.delay() self.redirect('/wiki/{0}'.format( tornado.escape.url_escape(post_data['title'])))
def test_view_count_plus(self): self.add_mess() aa = MWiki.get_by_uid(self.uid) for i in range(5): MWiki.view_count_plus(self.uid) bb = MWiki.get_by_uid(self.uid) assert aa.view_count + 5 <= bb.view_count self.tearDown()
def test_update_view_count(self): self.add_mess() aa = MWiki.get_by_uid(self.uid) for i in range(5): MWiki.update_view_count(self.wiki_title) bb = MWiki.get_by_uid(self.uid) assert aa.view_count + 5 <= bb.view_count self.tearDown()
def add_wiki(self): p_d = { 'title': self.title, 'cnt_md': '## adslkfjasdf\n lasdfkjsadf', 'user_name': self.username, } MWiki.create_wiki(p_d) aa = MWiki.get_by_wiki(self.title) self.wiki_uid = aa.uid
def test_get_by_title2(self): '''Test Wiki title with SPACE''' self.add_mess() ss = MWiki.get_by_uid(self.uid) assert ss.title == self.wiki_title tt = MWiki.get_by_title(self.wiki_title) assert tt.title == self.wiki_title.strip() self.tearDown()
def test_update_cnt(self): self.add_mess() aa = MWiki.get_by_uid(self.uid) pf = {'user_name': 'ooqwer', 'cnt_md': 'qwertyuioplkjgfdsa'} MWiki.update_cnt(self.uid, pf) bb = MWiki.get_by_uid(self.uid) assert aa.user_name != bb.user_name assert bb.user_name == pf['user_name'] self.tearDown()
def test_insert(self): raw_count = MWiki.get_counts() self.add_mess() new_count = MWiki.get_counts() tt = MWiki.get_by_wiki(self.wiki_title) assert tt.title == self.wiki_title assert raw_count + 1 <= new_count self.tearDown()
def add_mess(self,**kwargs): p_d = { 'title': self.wiki_title, 'cnt_md': '## adslkfjasdf\n lasdfkjsadf', 'user_name': 'Tome', } MWiki.create_wiki(p_d) aa = MWiki.get_by_wiki(self.wiki_title) self.uid = aa.uid
def test_upate(self): self.add_mess() rec = MWiki.get_by_wiki(self.wiki_title) p_d = { 'title': 'bibibobo', 'cnt_md': 'dd25d5fd6d', } MWiki.update(self.uid,p_d) now=MWiki.get_by_wiki(p_d['title']) assert rec.uid==now.uid assert now.uid==self.uid self.tearDown()
def test_create_page(self): p_d = { 'title': self.wiki_title, 'cnt_md': '## adslkfjasdf\n lasdfkjsadf', 'user_name': 'Tome', } tf = MWiki.create_page(self.uid, p_d) assert tf aa = MWiki.get_by_uid(self.uid) assert aa.title == self.wiki_title assert aa.kind == '2' self.tearDown()
def test_get_by_uid(self): self.add_mess() tf = False aa = MWiki.query_all() for i in aa: if i.uid == self.uid: tf = True break assert tf bb = MWiki.get_by_uid(self.uid) assert bb.title == self.wiki_title self.tearDown()
def test_get_by_title2(self): '''Test Wiki title with SPACE''' post_data = { 'title': ' ' + self.wiki_title + ' ', } self.add_mess(**post_data) ss = MWiki.get_by_uid(self.uid) assert ss.title == self.wiki_title tt = MWiki.get_by_title(self.wiki_title) assert tt.title == post_data['title'].strip() self.tearDown()
def test_get_by_title(self): post_data = { 'title': self.wiki_title, 'cnt_md': '## adslkfjasdf\n lasdfkjsadf', 'user_name': 'Tome', } uu = MWiki.create_wiki(post_data) # # ss = self.uu.get_by_uid(uid) # assert ss.title == post_data['title'] tt = MWiki.get_by_title(self.wiki_title) assert tt.title == post_data['title']
def test_upate_by_view_count(self): self.add_mess() rec = MWiki.get_by_wiki(self.wiki_title) viewcount0 = rec.view_count assert viewcount0 >= 2 for x in range(100): MWiki.update_view_count_by_uid(rec.uid) viewcount1 = MWiki.get_by_wiki(self.wiki_title).view_count assert viewcount1 >= 103 self.tearDown()
def view(self, view): ''' View the wiki. ''' kwd = { 'pager': '', 'editable': self.editable(), } MWiki.update_view_count(view.uid) self.render('wiki_page/wiki_view.html', postinfo=view, kwd=kwd, userinfo=self.userinfo)
def do_for_wiki(writer, rand=True, doc_type=''): if rand: recs = MWiki.query_random(num=10, kind='1') else: recs = MWiki.query_recent(num=2, kind='1') for rec in recs: text2 = rec.title + ',' + html2text.html2text( tornado.escape.xhtml_unescape(rec.cnt_html)) writer.update_document(title=rec.title, catid='sid1', type=doc_type, link='/wiki/{0}'.format(rec.title), content=text2)
def test_get_by_title2(self): '''Test Wiki title with SPACE''' post_data = { 'title': ' ' + self.wiki_title + ' ', 'cnt_md': '## adslkfjasdf\n lasdfkjsadf', 'user_name': 'Tome', } uu = MWiki.create_wiki(post_data) # # ss = self.uu.get_by_uid(uid) # assert ss.title == self.wiki_title tt = MWiki.get_by_title(self.wiki_title) assert tt.title == post_data['title'].strip()
def test_query_pager_by_kind(self): self.add_mess() aa = MWiki.total_number('1') a = int(aa / 10) + 2 tf = False for i in range(a): x = MWiki.query_pager_by_kind('1', current_page_num=i) for y in x: if y.uid == self.uid: assert y.title == self.wiki_title tf = True break self.tearDown() assert tf
def list(self): ''' View the list of the pages. ''' kwd = { 'pager': '', 'title': '单页列表', } self.render('wiki_page/page_list.html', kwd=kwd, view=MWiki.query_recent(), view_all=MWiki.query_all(), format_date=tools.format_date, userinfo=self.userinfo, cfg=CMS_CFG)
def view(self, rec): ''' View the page. ''' kwd = { 'pager': '', } MWiki.view_count_plus(rec.uid) self.render('wiki_page/page_view.html', postinfo=rec, kwd=kwd, author=rec.user_name, format_date=tools.format_date, userinfo=self.userinfo, cfg=CMS_CFG)
def test_insert(self): raw_count = MWiki.get_counts() post_data = { 'title': self.wiki_title, 'cnt_md': '## adslkfjasdf\n lasdfkjsadf', 'user_name': 'Tome', } if MWiki.create_wiki(post_data): new_count = MWiki.get_counts() tt = MWiki.get_by_wiki(self.wiki_title) assert tt.title == post_data['title'] assert tt.cnt_md == tornado.escape.xhtml_unescape(post_data['cnt_md']) assert raw_count + 1 == new_count
def to_modify(self, uid): ''' Try to modify the page. ''' kwd = { 'pager': '', } self.render( 'wiki_page/page_edit.html', view=MWiki.get_by_uid(uid), # Deprecated postinfo=MWiki.get_by_uid(uid), kwd=kwd, cfg=CMS_CFG, userinfo=self.userinfo)