1. python_mirrors
  2. tracker/rietveld

Commits

Martin von Löwis  committed 305bf05 Draft

Apply gae2django patches.

  • Participants
  • Parent commits 58001c0
  • Branches bugs.python.org

Comments (0)

Files changed (5)

File codereview/urls.py

View file
     (r'^_ah/mail/(.*)', 'incoming_mail'),
     (r'^xsrf_token$', 'xsrf_token'),
     # patching upload.py on the fly
-    (r'^static/upload.py$', 'customized_upload_py'),
+    (r'^dynamic/upload.py$', 'customized_upload_py'),
     (r'^search$', 'search'),
     (r'^tasks/calculate_delta$', 'calculate_delta'),
     )

File rietveld_helper

View file
+../django-gae2django/examples/rietveld/rietveld_helper

File templates/base.html

View file
 <a class="novisit" href="{%url codereview.views.settings%}">Settings</a>
 |
 {%endif%}
-{%if is_dev%}
+{%if is_dev or user.is_superuser%}
 <a class="novisit" target="_blank" href="/_ah/admin">Admin</a>
 |
 {%endif%}
+{%if user%}
+<a class="novisit" target="_blank" href="/admin/password_change">Change password</a>
+|
+{%endif%}
 <a class="novisit" target="_blank"
    href="http://code.google.com/p/rietveld/wiki/CodeReviewHelp">Help</a>
 |

File templates/issue_base.html

View file
     <a class="novisit" href="{%url codereview.views.all%}">All Issues</a>
     |
     <a class="novisit" href="{{sign_in}}">Sign in</a>
-    with your <a href="https://www.google.com/accounts/NewAccount">Google
-    Account</a> to create issues and add comments
+    to create issues and add comments
   {%endif%}
 {%endblock%}
 

File upload.py

View file
                               response.headers, response.fp)
     self.authenticated = True
 
-  def _Authenticate(self):
+  def _Authenticate(self, err):
     """Authenticates the user.
 
     The authentication process works as follows:
     """
     # TODO: Don't require authentication.  Let the server say
     # whether it is necessary.
-    if not self.authenticated:
-      self._Authenticate()
+    # Skip this check for Django, we need a 401 to get the login
+    # URL (could be anywhere...).
+    #if not self.authenticated:
+    #  self._Authenticate()
 
     old_timeout = socket.getdefaulttimeout()
     socket.setdefaulttimeout(timeout)
 class HttpRpcServer(AbstractRpcServer):
   """Provides a simplified RPC-style interface for HTTP requests."""
 
-  def _Authenticate(self):
+  def _Authenticate(self, login_url="/accounts/login/"):
     """Save the cookie jar after authentication."""
-    super(HttpRpcServer, self)._Authenticate()
+    login_url = "%s%s" % (self.host, login_url)
+    print "Login URL: %r" % login_url
+    username = raw_input("Username: ")
+    password = getpass.getpass("Password: ")
+    fields = (("user_name", username), ("password", password))
+    req = self._CreateRequest(
+        url=login_url,
+        data=urllib.urlencode({
+            "username": username,
+            "password": password,
+        })
+    )
+    try:
+      response = self.opener.open(req)
+      #response_body = response.read()
+      #response_dict = dict(x.split("=")
+      #                     for x in response_body.split("\n") if x)
+      ErrorExit("Login failed.")
+      #return response_dict["Auth"]
+    except urllib2.HTTPError, e:
+      if e.code == 302:
+        self.cookie_jar.extract_cookies(e, req)
+        if self.save_cookies:
+          self.cookie_jar.save()
+        self.authenticated = True
+        return
+      elif e.code == 403:
+        body = e.read()
+        response_dict = dict(x.split("=", 1) for x in body.split("\n") if x)
+        raise ClientLoginError(req.get_full_url(), e.code, e.msg,
+                               e.headers, response_dict)
+      else:
+        raise
+
     if self.save_cookies:
       StatusUpdate("Saving authentication cookies to %s" % self.cookie_file)
       self.cookie_jar.save()
 
   rpc_server_class = HttpRpcServer
 
-  # If this is the dev_appserver, use fake authentication.
   host = (host_override or server).lower()
-  if re.match(r'(http://)?localhost([:/]|$)', host):
-    if email is None:
-      email = "test@example.com"
-      logging.info("Using debug user %s.  Override with --email" % email)
-    server = rpc_server_class(
-        server,
-        lambda: (email, "password"),
-        host_override=host_override,
-        extra_headers={"Cookie":
-                       'dev_appserver_login="%s:False"' % email},
-        save_cookies=save_cookies,
-        account_type=account_type)
-    # Don't try to talk to ClientLogin.
-    server.authenticated = True
-    return server
 
   def GetUserCredentials():
     """Prompts the user for a username and password."""