# HG changeset patch # User Steve Losh # Date 1276305768 14400 # Node ID 93e7fb8a132380b30a1644810007bb8cd1e6738b # Parent b45d0345f93661420ea5d2688e1697c98b7e9c01 Holy sweet god it works. diff -r b45d0345f936 -r 93e7fb8a1323 review/web_ui.py --- a/review/web_ui.py Fri Jun 11 20:59:24 2010 -0400 +++ b/review/web_ui.py Fri Jun 11 21:22:48 2010 -0400 @@ -5,8 +5,8 @@ import sys, os from hashlib import md5 -from mercurial import commands, cmdutil, hg, templatefilters -from mercurial.node import short, hex +from mercurial import commands, templatefilters +from mercurial.node import short from mercurial.util import email import api @@ -29,7 +29,8 @@ unbundle() -from flask import Flask, render_template +from flask import Flask +from flask import abort, redirect, render_template, request app = Flask(__name__) LOG_PAGE_LEN = 1000000 @@ -67,31 +68,42 @@ return _render('index.html', title='', rcsets=rcsets) -@app.route('/changeset//') +def _handle_signoff(revhash): + signoff = request.form.get('signoff', None) + + if signoff not in ['yes', 'no', 'neutral']: + abort(400) + + if signoff == 'neutral': + signoff = '' + + body = request.form.get('new-signoff-body', '') + rcset = datastore[revhash] + rcset.add_signoff(body, signoff, force=True) + + return redirect("/changeset/%s/" % revhash) + +def _handle_comment(revhash): + filename = request.form.get('filename', '') + lines = str(request.form.get('lines', '')) + if lines: + lines = lines.split(',') + body = request.form['new-comment-body'] + + if body: + rcset = datastore[revhash] + rcset.add_comment(body, filename, lines) + + return redirect("/changeset/%s/" % revhash) + +@app.route('/changeset//', methods=['GET', 'POST']) def changeset(revhash): - #if kwargs and not self.read_only: - #signoff = kwargs.get('signoff', None) - #if signoff: - #if signoff not in ['yes', 'no', 'neutral']: - #return 'Invalid signoff type.' - #if signoff == 'neutral': - #signoff = '' - #body = kwargs.get('new-signoff-body', '') - #rcset = self.datastore[rev_id] - #rcset.add_signoff(body, signoff, force=True) - #raise cherrypy.HTTPRedirect("/changeset/%s/" % rev_id) - - #filename = kwargs.get('filename', '') - #lines = str(kwargs['lines']) if 'lines' in kwargs else '' - #if lines: - #lines = lines.split(',') - #body = kwargs['new-comment-body'] - - #if body: - #rcset = self.datastore[rev_id] - #rcset.add_comment(body, filename, lines) - - #raise cherrypy.HTTPRedirect("/changeset/%s/" % rev_id) + if request.method == 'POST' and not site_read_only: + signoff = request.form.get('signoff', None) + if signoff: + return _handle_signoff(revhash) + else: + return _handle_comment(revhash) rcset = datastore[revhash] rev = rcset.target[revhash] @@ -104,33 +116,20 @@ rcset=rcset, rev=rev, cu_signoff=cu_signoff ) -#class ReviewWebUI(object): - #@cherrypy.expose - #def pull(self, **kwargs): - #if not self.read_only: - #if 'path' not in kwargs: - #return 'OH GOD HOW DID THIS GET HERE I AM NOT GOOD WITH LINKS' - #path = kwargs['path'] - - #commands.pull( - #self.datastore.repo.ui, self.datastore.repo, path, **{ - #'update': True - #} - #) - - #raise cherrypy.HTTPRedirect("/") - #@cherrypy.expose - #def push(self, **kwargs): - #if not self.read_only: - #if 'path' not in kwargs: - #return 'OH GOD HOW DID THIS GET HERE I AM NOT GOOD WITH LINKS' - #path = kwargs['path'] - - #commands.push( - #self.datastore.repo.ui,self.datastore.repo, path, **{} - #) - - #raise cherrypy.HTTPRedirect("/") + +@app.route('/pull/', methods=['POST']) +def pull(): + if not site_read_only: + path = request.form['path'] + commands.pull(datastore.repo.ui, datastore.repo, path, update=True) + return redirect('/') + +@app.route('/push/', methods=['POST']) +def push(): + if not site_read_only: + path = request.form['path'] + commands.push(datastore.repo.ui, datastore.repo, path) + return redirect('/') def load_interface(ui, repo, read_only=False, open=False, address='127.0.0.1', port=8080):