Commits

Anonymous committed 06db1c5

hgstore: Make the RecentChanges look more traditionally

Comments (0)

Files changed (2)

         return self.Section(self.parser, key)
 
 class WikiActions(object):
-    def view_action(self, env, start, form, title):
-        start("200 OK", self.default_headers)
-        yield self.html_head(title)
+    def view_action(wiki, env, start, form, title):
+        start("200 OK", wiki.default_headers)
+        yield wiki.html_head(title)
         yield u"""<div class="content article">"""
-        for line in self.parser.parse(self.storage.load(title)):
+        for line in wiki.parser.parse(wiki.storage.load(title)):
             yield line
         yield u"""</div><div class="footer"><hr>"""
         yield u"""<a href="%s" class="edit">%s</a>""" % (
-            self.page_url(title, action="edit"), _(u"Edit this page"))
+            wiki.page_url(title, action="edit"), _(u"Edit this page"))
         yield u"""</div></body></html>"""
 
-    def save_action(self, env, start, form, title):
+    def save_action(wiki, env, start, form, title):
         text = unicode(form.getfirst("text"), "utf-8")
         name = unicode(form.getfirst("author", ""), "utf-8")
         host = env.get("REMOTE_ADDR", "")
         author = name or host
         comment = u""
         if text is not None:
-            self.storage.save(title, text)
-            self.log.edited(title, author, comment)
-        start("303 Redirect", [('Location', self.page_url(title)),])
+            wiki.storage.save(title, text)
+            wiki.log.edited(title, author, comment)
+        start("303 Redirect", [('Location', wiki.page_url(title)),])
         return
         yield None  # Make it a generator function
 
-    def edit_action(self, env, start, form, title):
-        start("200 OK", self.default_headers)
-        save_url = self.page_url(title, action="save")
-        yield self.html_head(_(u'Editing "%s"...') % title)
+    def edit_action(wiki, env, start, form, title):
+        start("200 OK", wiki.default_headers)
+        save_url = wiki.page_url(title, action="save")
+        yield wiki.html_head(_(u'Editing "%s"...') % title)
         yield u"""<div class="content edit">"""
         yield (u"""<form action="%s" """
               u"""method="POST" accept-charset="utf-8">""" % save_url)
         yield u"""<p><textarea cols="80" rows="25" name="text">"""
-        for line in self.storage.load(title):
+        for line in wiki.storage.load(title):
             yield cgi.escape(line)
         yield u"""</textarea><br>"""
         yield (u"""<label class="author">%s """
         yield u"""</p></form>"""
         yield u"""</div></body></html>"""
 
-    def empty_action(self, env, start, form, title):
-        start("404 Not found", self.default_headers)
-        yield self.html_head(title)
+    def empty_action(wiki, env, start, form, title):
+        start("404 Not found", wiki.default_headers)
+        yield wiki.html_head(title)
         yield u"""<div class="content empty">%s</div>""" % _(u"Page not found!")
         yield u"""<div class="footer"><hr>"""
         yield u"""<a href="%s" class="edit">%s</a>""" % (
-            self.page_url(title, action="edit"), _(u"Create this page"))
+            wiki.page_url(title, action="edit"), _(u"Create this page"))
         yield u"""</div></body></html>"""
 
 class Wiki(object):
         self.config = WikiConfig()
         self.config.load()
         pages_path = os.path.join(self.config["data_dir"], "pages")
-        self.actions = WikiActions.__dict__
+        self.actions = dict(WikiActions.__dict__)
         self.storage = FileStorage(pages_path)
         self.parser = WikiParser(self)
         self.log = PageLog(self)
         self.plugins = {}
         for plugin_name in self.config.parser.sections():
             self.load_plugin(plugin_name)
-        
-        self.hgweb = None
 
     def load_plugin(self, plugin_name):
         plugin = __import__("plugin.%s" % plugin_name, globals(), locals(), ["plugin"])

w/plugin/hgstore.py

         self.repo.commit(text="saved")
 
     def changes(self):
-        for node in self.repo.changelog.nodesbetween()[0]:
+        for node in reversed(self.repo.changelog.nodesbetween()[0]):
             change = self.repo.changectx(node)
             pages = [unicode(urllib.unquote(fn), "utf-8") 
                 for fn in change.files()]
             for response in self.wsgi_orig(env, start):
                 yield response
 
-def changes_action(self, env, start, form, title):
-        #self = self.wiki
-        start("200 OK", self.default_headers)
-        yield self.html_head(_(u"Recent changes"))
+def changes_action(wiki, env, start, form, title):
+        start("200 OK", wiki.default_headers)
+        yield wiki.html_head(_(u"Recent changes"))
+        old_day = ""
         yield u"<ul>"
-        for date, pages, author, comment in self.storage.changes():
+        for date, pages, author, comment in wiki.storage.changes():
+            formatted_day = date.strftime("%Y-%m-%d")
+            formatted_hour = date.strftime("%H:%M")
+            if old_day!=formatted_day:
+                yield u"</ul><h2>%s</h2><ul>" % formatted_day
+                old_day = formatted_day
             formatted_date = date.strftime("%Y-%m-%d %H:%M")
-            page_links = ", ".join(u'<a href="%s">%s</a>' % (self.page_url(t), t)
-                for t in pages)
-            yield u'<li><b>%s</b> . . . . %s -- <i>%s</i> <div>%s</div></li>' % (
-                formatted_date, page_links, author, comment)
+            page_links = ", ".join(u'<a href="%s">%s</a>' % 
+                (wiki.page_url(t), t) for t in pages)
+            yield (u'<li><b>%s</b> %s . . . . <i>%s</i> <div>%s</div></li>' %
+                (formatted_hour, page_links, author, comment))
         yield u"</ul>"
         yield u"</body></html>"
 
     wrapper = HgwebWrapper(wiki.storage.repo, wiki)
     wrapper.wsgi_orig = wiki.wsgi
     wiki.wsgi = wrapper.wiki_wsgi
-    wiki.__class__.changes_action = changes_action
+    wiki.actions["changes_action"] = changes_action