def execute(macro, args): request = macro.request content = [] page_name = macro.formatter.page.page_name # get args include_page_name = '' if args is not None: (include_page_name, _, hdf_text) = args.partition(',') include_page_name = wikiutil.AbsPageName(page_name, include_page_name) include_page = Page(request, include_page_name) if include_page is None: return '' if not request.user.may.read(include_page_name): return '' cstemplate = include_page.getPageText() pagename = macro.formatter.page.page_name hdf = neo_util.HDF() hdf.readString(hdf_text) hdf.setValue("Config.WhiteSpaceStrip ", "0") cs = neo_cs.CS(hdf) cs.parseStr(cstemplate) body = cs.render() body = wikiutil.renderText(request, WikiParser, body) return body
def testBasicPackageThings(self): become_superuser(self.request) myPackage = DebugPackage(self.request, 'test') myPackage.installPackage() assert myPackage.msg == u'foo\nFooPage added \n' testseite2 = Page(self.request, 'TestSeite2') assert testseite2.getPageText() == "Hello world, I am the file testdatei" assert testseite2.isUnderlayPage()
def testBasicPackageThings(self): myPackage = DebugPackage(self.request, 'test') myPackage.installPackage() self.assertEqual(myPackage.msg, "foo\n") testseite2 = Page(self.request, 'TestSeite2') self.assertEqual(testseite2.getPageText(), "Hello world, I am the file testdatei") self.assert_(testseite2.isUnderlayPage()) self.assert_(not Page(self.request, 'FooPage').exists())
def testBasicPackageThings(self): become_superuser(self.request) myPackage = DebugPackage(self.request, 'test') myPackage.installPackage() assert myPackage.msg == u'foo\nFooPage added \n' testseite2 = Page(self.request, 'TestSeite2') assert testseite2.getPageText( ) == "Hello world, I am the file testdatei" assert testseite2.isUnderlayPage()
def execute(macro, args): request = macro.request content = [] page_name = macro.formatter.page.page_name # get args include_page_name = '' if args is not None: include_page_name = args include_page_name = wikiutil.AbsPageName(page_name, include_page_name) include_page = Page(request, include_page_name) if include_page is None: return '' if not request.user.may.read(include_page_name): return '' cstemplate = include_page.getPageText() pagename = macro.formatter.page.page_name kv_page = Page(request, pagename) kv_body = kv_page.get_body() hdf = neo_util.HDF() for line in kv_body.split("\n"): if line.startswith("##"): line = line[2:].strip() parts = line.split("=", 1) if len(parts) == 2: val = parts[1].strip() #val = parts[1].strip().encode('utf-8') # swh hdf.setValue(parts[0].strip(), val) hdf.setValue("Config.WhiteSpaceStrip ", "0") cs = neo_cs.CS(hdf) cs.parseStr(cstemplate) body = cs.render() body = wikiutil.renderText(request, WikiParser, body) open("/tmp/out.html", "w").write(body) return body
def execute(self): reload(sys) sys.setdefaultencoding('utf-8') path = os.path.split(os.path.realpath(__file__))[0] path = path + os.sep + 'NGOWIKI_NEWPAGE.html' html = [] with open(path) as f: for line in f: html.append(line) content = self.formatter.rawHTML(u'\n'.join(html)) copyrightPage = Page(self.request, 'copyright') copyrightText = copyrightPage.getPageText() copyrightText = copyrightText[:].strip() content = content.replace('{copyright}', copyrightText) return content
def execute(macro, args): request = macro.request content = [] page_name = macro.formatter.page.page_name # get args include_page_name = '' if args is not None: include_page_name = args include_page_name = wikiutil.AbsPageName(page_name, include_page_name) include_page = Page(request, include_page_name) if include_page is None: return '' if not request.user.may.read(include_page_name): return '' else: return wikiutil.renderText(request, WikiParser, include_page.getPageText())
def newday (Wiki, ParentPage, TemplatePage, NewPage, Editor, UidName, GidName): from os import seteuid,setegid from pwd import getpwnam from grp import getgrnam uid = getpwnam(UidName).pw_uid gid = getgrnam(GidName).gr_gid setegid(gid) seteuid(uid) from MoinMoin.PageEditor import PageEditor from MoinMoin.Page import Page from MoinMoin.user import getUserId, User from MoinMoin.web.contexts import ScriptContext PageName = "%s/%s" % (ParentPage,NewPage) RequestPage = ScriptContext(Wiki, PageName) UserId = getUserId(RequestPage, Editor) RequestPage.user = User(RequestPage, UserId) Editor = PageEditor(RequestPage, PageName) Dummy, Revision, Exists = Editor.get_rev() if not Exists: RequestTemplate = ScriptContext(Wiki, TemplatePage) Viewer = Page(RequestTemplate, TemplatePage) Text = Viewer.getPageText().replace("@PAGE@", NewPage) Header = Viewer.getPageHeader() Text=Header+Text return Editor.saveText(Text, Revision)
def execute(self): if FrontpageMacro.lastupdated == None or long(time.time()) - FrontpageMacro.lastupdated > 3600L: ngowikiutil = NgoWikiUtil(self.request) try: ngowikiutil.open_database() FrontpageMacro.totalcount_activities = ngowikiutil.count_pages_by_tag([u'服务产品类']) + ngowikiutil.count_pages_by_tag([u'视听产品类']) + ngowikiutil.count_pages_by_tag([u'实体产品类']) FrontpageMacro.totalcount_ngos = ngowikiutil.count_pages_by_tag([u'公益机构类']) FrontpageMacro.totalcount_enterprises = ngowikiutil.count_pages_by_tag([u'企业志愿组织类']) FrontpageMacro.featured_activities = ngowikiutil.select_pages_with_one_of_tags([u'服务产品类', u'视听产品类', u'实体产品类'], 'featured', 'DESC', 0, 20) for record in FrontpageMacro.featured_activities[0:2]: record["summary"] = record["summary"].replace("'''", "") record["summary"] = filter_summary(record["summary"], 50); pagename = record["path"] page = Page(self.request, pagename) record["link"] = page.url(self.request) if len(record["logo"]) > 0 and exists(self.request, record["path"], record["logo"]): record["logo_link"] = getAttachUrl(record["path"], record["logo"], self.request) else: findLogo = False text = page.getPageText() match = re.search('\\{\\{attachment:([^\\|]+)\\|\\|.*}}', text) if match != None: logo = match.group(1) if exists(self.request, record["path"], logo): record["logo_link"] = getAttachUrl(record["path"], logo, self.request) findLogo = True if not findLogo: record["logo_link"] = self.request.cfg.url_prefix_static + "/ngowiki/img/no-logo.png" FrontpageMacro.featured_ngos = ngowikiutil.select_pages_by_tag([u'公益机构类'], 'featured', 'DESC', 0, 2) for record in FrontpageMacro.featured_ngos: pagename = record["path"] record["summary"] = filter_summary(record["summary"], 50) page = Page(self.request, pagename) record["link"] = page.url(self.request) if len(record["logo"]) > 0 and exists(self.request, record["path"], record["logo"]): record["logo_link"] = getAttachUrl(record["path"], record["logo"], self.request) else: record["logo_link"] = self.request.cfg.url_prefix_static + "/ngowiki/img/no-logo.png" FrontpageMacro.recently_added = ngowikiutil.select_latest_created_pages([u'服务产品类', u'视听产品类', u'实体产品类', u'公益机构类', u'企业志愿组织类'], 0, 5) for record in FrontpageMacro.recently_added: pagename = record["path"] page = Page(self.request, pagename) record["link"] = page.url(self.request) if len(record["logo"]) > 0 and exists(self.request, record["path"], record["logo"]): record["logo_link"] = getAttachUrl(record["path"], record["logo"], self.request) else: record["logo_link"] = self.request.cfg.url_prefix_static + "/ngowiki/img/no-logo.png" if u'服务产品类' in ngowikiutil.parse_page(page)["categories"] or u'视听产品类' in ngowikiutil.parse_page(page)["categories"] or u'实体产品类' in ngowikiutil.parse_page(page)["categories"]: record["recently_added_type"] = "activity" elif u'公益机构类' in ngowikiutil.parse_page(page)["categories"]: record["recently_added_type"] = "ngo" else: record["recently_added_type"] = "enterprise" FrontpageMacro.news_items = ngowikiutil.select_pages_by_tag([u'新闻动态类'], 'featured', 'DESC', 0, 100) for record in FrontpageMacro.news_items: pagename = record["path"] page = Page(self.request, pagename) record["link"] = page.url(self.request) if len(record["logo"]) > 0 and exists(self.request, record["path"], record["logo"]): record["logo_link"] = getAttachUrl(record["path"], record["logo"], self.request) else: record["logo_link"] = self.request.cfg.url_prefix_static + "/ngowiki/img/no-logo.png" finally: ngowikiutil.close_database(True) FrontpageMacro.lastupdated = long(time.time()) context = { 'totalcount_activities': FrontpageMacro.totalcount_activities, 'totalcount_ngos': FrontpageMacro.totalcount_ngos, 'totalcount_enterprises': FrontpageMacro.totalcount_enterprises, 'featured_activities': FrontpageMacro.featured_activities, 'featured_ngos': FrontpageMacro.featured_ngos, 'recently_added': FrontpageMacro.recently_added, 'news_items': FrontpageMacro.news_items, 'logo_url': self.request.cfg.url_prefix_static + "/ngowiki/img/sitelogo.png", 'slogan_url': self.request.cfg.url_prefix_static + "/ngowiki/img/slogan2.png" } engine = tenjin.Engine(path=[os.path.dirname(__file__) + '/views']) html = engine.render('Frontpage.pyhtml', context) return self.formatter.rawHTML(html)