Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(8370)

Issue 70870043: Quick outline of simplified rietveld2 framework based on jinja2

Can't Edit
Can't Publish+Mail
Start Review
Created:
8 years, 9 months ago by jrobbins (chromium)
Modified:
1 week, 5 days ago
Visibility:
Public.

Description

Quick outline of simplified rietveld2 framework based on jinja2

Patch Set 1 #

Total comments: 5

Patch Set 2 : Revised handler registration, more example handlers, more common processing in servlet. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+621 lines, -33 lines) Patch
M app.yaml View 2 chunks +6 lines, -0 lines 0 comments Download
M codereview/models.py View 1 1 chunk +32 lines, -0 lines 0 comments Download
M codereview/views.py View 1 3 chunks +2 lines, -33 lines 0 comments Download
M index.yaml View 1 1 chunk +1 line, -1 line 0 comments Download
A v2/__init__.py View 0 chunks +-1 lines, --1 lines 0 comments Download
A v2/api.py View 1 1 chunk +186 lines, -0 lines 0 comments Download
A v2/servlet.py View 1 1 chunk +263 lines, -0 lines 0 comments Download
A v2/templates/echo.html View 1 chunk +47 lines, -0 lines 0 comments Download
A v2/urls.py View 1 1 chunk +69 lines, -0 lines 0 comments Download
A v2_main.py View 1 1 chunk +16 lines, -0 lines 0 comments Download

Messages

Total messages: 5
jrobbins (chromium)
Robbie, here's what I think that the request handler part of your framework can be ...
8 years, 9 months ago (2014-03-03 20:19:02 UTC) #1
iannucci
Neat :) webapp2 is much cleaner than django :) few comments... apologies if they're just ...
8 years, 9 months ago (2014-03-04 11:33:52 UTC) #2
jrobbins (corp)
> > https://codereview.appspot.com/70870043/diff/1/v2/ > framework/servlet.py#newcode67 > v2/framework/servlet.py:67: json_data = super(JSONServlet, > self).dispatch() > How does ...
8 years, 9 months ago (2014-03-04 19:45:07 UTC) #3
iannucci
On Tue, Mar 4, 2014 at 11:45 AM, Jason Robbins <jrobbins@google.com> wrote: > https://codereview.appspot.com/70870043/diff/1/v2/ >> ...
8 years, 9 months ago (2014-03-04 20:38:09 UTC) #4
jrobbins (corp)
8 years, 8 months ago (2014-04-01 22:34:25 UTC) #5
OK, I finally got back to hacking on v2 and made some progress.

The number of lines of code for handler registration is dramatically reduced and
moved to urls.py.  It is short enough now that I kind of feel like moving it
back to v2_main.py, but I won't yet.   

The key insight came when I tried to use webapp2's specification of
handler_method and specific HTTP methods and found that I cannot have to Route
objects that match the same path and differ only by HTTP method.  So, my new
approach is to go with the flow of webapp2: register handlers solely by path,
let webapp2 map the HTTP methods to get(), post(), put(), and delete(), but then
use 1-line trampoline methods to get to handlers with more meaningful names
(because I really don't want to be searching for callers of get() when
maintaining this code later).  Since the collections and the individual entities
live at different URL specs, they are handled by a pair of classes, e.g.,
IssueJSON and IssueCollectionJSON.

Also, I outlined more of the API handler code.  What you are seeing there is the
skeleton/boilerplate with very little implementation.  It's a certain number of
lines, but not too bad, and there is absolutely nothing tricky going on.  I
sketched out create_issue() and get_issue().  I'm pretty happy with how simple
they came out to be so far.

The individual handlers can be simple because I put some common request handling
steps in Servlet's dispatch() method: parsing the request, validating and
converting string inputs to typed values, retrieving the main objects needed for
the request, and basic permission checking.  I moved servlet.py out of the
framework/ directory and deleted that directory.  The reason is that servlet.py
is not intended to be reusable code that is independent of application.  Instead
it is just a base class for handlers in this application, and as such, it is OK
to have some knowledge of the app's structure there.  E.g., issue_id string is
converted to an int and that is used to retrieve an Issue entity.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b