Added bulk acceptance and progress bar in review org applications view.
In the list of organization applications for reviewing, if you click the button "click here" the whole first text line will fade out and the progress bar will fade in while starting to contact the server for the list of orgs to accept and then make synchronous calls for acceptance, while updating the progress bar, the name of the organization currently accepting and the number of orgs already accepted against the total.
Inside the script, what's inside the parenthesis is converted due to regexp (in this case (link_id)) and then read the json_object.applications[index].link_id. By doing this with an eval(), you can use other names as well and the script will be reading for example json_object.applications[index].attribute_name if you insert "(attribute_name)" inside the link returned by {{ bulk_accept_link }}.
Notes by Lennard:
-Put Done outside the for-loop so that it also shows when there are 0 pre-accepted organizations.
-Made some minor style fixes
Patch by: Mario Ferraro
Reviewed by: Lennard de Rijk
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Trivial implementation of the UserService."""
import os
import urllib
import urlparse
from google.appengine.api import apiproxy_stub
from google.appengine.api import user_service_pb
_DEFAULT_LOGIN_URL = 'https://www.google.com/accounts/Login?continue=%s'
_DEFAULT_LOGOUT_URL = 'https://www.google.com/accounts/Logout?continue=%s'
class UserServiceStub(apiproxy_stub.APIProxyStub):
"""Trivial implementation of the UserService."""
def __init__(self,
login_url=_DEFAULT_LOGIN_URL,
logout_url=_DEFAULT_LOGOUT_URL,
service_name='user'):
"""Initializer.
Args:
login_url: String containing the URL to use for logging in.
logout_url: String containing the URL to use for logging out.
service_name: Service name expected for all calls.
Note: Both the login_url and logout_url arguments must contain one format
parameter, which will be replaced with the continuation URL where the user
should be redirected after log-in or log-out has been completed.
"""
super(UserServiceStub, self).__init__(service_name)
self.__num_requests = 0
self._login_url = login_url
self._logout_url = logout_url
os.environ['AUTH_DOMAIN'] = 'gmail.com'
def num_requests(self):
return self.__num_requests
def _Dynamic_CreateLoginURL(self, request, response):
"""Trivial implementation of UserService.CreateLoginURL().
Args:
request: the URL to redirect to after login; a base.StringProto
response: the login URL; a base.StringProto
"""
self.__num_requests += 1
response.set_value(
self._login_url %
urllib.quote(self._AddHostToContinueURL(request.value())))
def _Dynamic_CreateLogoutURL(self, request, response):
"""Trivial implementation of UserService.CreateLogoutURL().
Args:
request: the URL to redirect to after logout; a base.StringProto
response: the logout URL; a base.StringProto
"""
self.__num_requests += 1
response.set_value(
self._logout_url %
urllib.quote(self._AddHostToContinueURL(request.value())))
def _AddHostToContinueURL(self, continue_url):
"""Adds the request host to the continue url if no host is specified.
Args:
continue_url: the URL which may or may not have a host specified
Returns:
string
"""
(protocol, host, path, parameters, query, fragment) = urlparse.urlparse(continue_url, 'http')
if host:
return continue_url
host = os.environ['SERVER_NAME']
if os.environ['SERVER_PORT'] != '80':
host = host + ":" + os.environ['SERVER_PORT']
if path == '':
path = '/'
return urlparse.urlunparse(
(protocol, host, path, parameters, query, fragment))