538a3dada709 webpy-sucks

Make the index page work with CherryPy.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Tue, 02 Mar 2010 21:58:58 -0500
parents 8e18e2c40a06
children c3a0ea6aa1df
branches/tags webpy-sucks
files review/api.py review/web_templates/base.html review/web_templates/index.html review/web_ui.py

Changes

--- a/review/api.py	Tue Mar 02 20:36:17 2010 -0500
+++ b/review/api.py	Tue Mar 02 21:58:58 2010 -0500
@@ -250,7 +250,7 @@
     
     def __getitem__(self, rev):
         """Return a ReviewChangeset for the given revision."""
-        node = hex(self.target[rev].node())
+        node = hex(self.target[str(rev)].node())
         return ReviewChangeset(self.ui, self.repo, self.target, node)
     
 
--- a/review/web_templates/base.html	Tue Mar 02 20:36:17 2010 -0500
+++ b/review/web_templates/base.html	Tue Mar 02 21:58:58 2010 -0500
@@ -3,7 +3,7 @@
 
 <html>
     <head>
-        <title>Reviewing {{ utils["basename"](datastore.target.root) }} with hg-review</title>
+        <title>Reviewing {{ utils["basename"](datastore.target.root) }}</title>
         <link rel="stylesheet" href="/media/aal.css" type="text/css" media="screen" />
         <link rel="stylesheet" href="/media/style.css" type="text/css" media="screen" />
         
@@ -14,29 +14,37 @@
     
     <body>
         <div id="head-wrap">
-            <h1><a href="/">{{ utils["basename"](datastore.target.root) }}</a> {{ title }}</a></h1>
+            <h1>
+                Reviewing:
+                <a href="/">
+                    {{ utils["basename"](datastore.target.root) }}
+                </a>
+                {% block title %}{% endblock %}
+            </h1>
         </div>
         <div id="content-wrap">
             <div id="remote-wrap">
                 <span id="remote-push" class="remote-section">
                     <h3>Push comments to:</h3>
-                    $for name, path in rd.repo.ui.configitems("paths"):
+                    {% for name, path in datastore.repo.ui.configitems("paths") %}
                         <form action="/push/" method="get">
-                        <input type="hidden" name="path" value="${ name }" />
-                        <input type="submit" value="${ name }" />
+                            <input type="hidden" name="path" value="${ name }" />
+                            <input type="submit" value="{{ name }}" />
                         </form>
+                    {% endfor %}
                 </span>
                 <span id="remote-pull" class="remote-section">
                     <h3>Pull comments from:</h3>
-                    $for name, path in rd.repo.ui.configitems("paths"):
+                    {% for name, path in datastore.repo.ui.configitems("paths") %}
                         <form action="/pull/" method="get">
-                        <input type="hidden" name="path" value="${ name }" />
-                        <input type="submit" value="${ name }" />
+                            <input type="hidden" name="path" value="${ name }" />
+                            <input type="submit" value="{{ name }}" />
                         </form>
+                    {% endfor %}
                 </span>
             </div>
             <div id="main-wrap">
-                {{ content }}
+                {% block content %}{% endblock %}
             </div>
         </div>
         <div id="footer">
--- a/review/web_templates/index.html	Tue Mar 02 20:36:17 2010 -0500
+++ b/review/web_templates/index.html	Tue Mar 02 21:58:58 2010 -0500
@@ -1,18 +1,30 @@
 {% extends "base.html" %}
 
-<h2>Changesets</h2>
-<table>
-    $for ctx in revs:
-        $ ctx_node = ctx.node()
-        $ ctx_node_short = node_short(ctx_node)
-        $ ctx_comments = rd[ctx_node].comments
-        $ ctx_signoffs = rd[ctx_node].signoffs
-        <tr class="${ loop.parity }">
-            <td>${ ctx.rev() }:${ ctx_node_short }</td>
-            <td>
-                <a href="/review/${ ctx_node_short }/">${ ctx.description() }</a>
-            </td>
-            <td class="last">${ len(ctx_comments) } comments,
-                ${ len(ctx_signoffs) } signoffs</td>
-        </tr>
-</table>
\ No newline at end of file
+{% block title %}{% endblock %}
+
+{% block content %}
+    <h2>Changesets</h2>
+    <table>
+        {% for rcset in rcsets %}
+            {% set rev = rcset.target[rcset.node] %}
+            {% set node_short = utils['node_short'](rev.node()) %}
+            <tr class="${ loop.parity }">
+                <td>{{ rev.rev() }}:{{ node_short }}</td>
+                <td>
+                    <a href="/review/{{ node_short }}/">{{  rev.description().splitlines()[0] }}</a>
+                </td>
+                <td class="last">
+                    {{ utils['len'](rcset.comments) }} comments,
+                    {{ utils['len'](ctx_signoffs) }} signoffs
+                </td>
+            </tr>
+        {% endfor %}
+    </table>
+{% endblock %}
+
+
+
+<!-- $ ctx_node = ctx.node()
+$ ctx_node_short = node_short(ctx_node)
+$ ctx_comments = rd[ctx_node].comments
+$ ctx_signoffs = rd[ctx_node].signoffs -->
--- a/review/web_ui.py	Tue Mar 02 20:36:17 2010 -0500
+++ b/review/web_ui.py	Tue Mar 02 21:58:58 2010 -0500
@@ -5,7 +5,7 @@
 from hashlib import md5
 
 from mercurial import cmdutil, hg, templatefilters
-from mercurial.node import short
+from mercurial.node import short, hex
 from mercurial.util import email
 
 import api
@@ -28,12 +28,15 @@
 TEMPLATE_DIR = os.path.join(package_path, 'web_templates')
 jinja_env = Environment(loader=FileSystemLoader(TEMPLATE_DIR))
 
+LOG_PAGE_LEN = 40
+
 utils = {
     'node_short': short,
     'basename': os.path.basename,
     'md5': md5,
     'email': email,
     'templatefilters': templatefilters,
+    'len': len,
 }
 
 class ReviewWebUI(object):
@@ -43,9 +46,13 @@
     
     @cherrypy.expose
     def index(self):
+        rev_max = self.datastore.target['tip'].rev()
+        rev_min = rev_max - LOG_PAGE_LEN if rev_max >= LOG_PAGE_LEN else 0
+        rcsets = [self.datastore[r] for r in xrange(rev_max, rev_min, -1)]
+        
         return jinja_env.get_template('index.html').render(
-            utils=utils, datastore=self.datastore,
-            title='',
+            utils=utils, datastore=self.datastore, title='',
+            rcsets=rcsets,
         )