[英]Cache a Google Apps Provisioning API login object with Django
I have a Django site that pulls up email groups from Google Apps using the provisioning API. 我有一个Django网站,该网站使用配置API从Google Apps提取电子邮件组。 I have something like: 我有类似的东西:
import gdata.apps.groups.client
client = gdata.apps.groups.client.GroupsProvisioningClient(domain="example.com")
client.ClientLogin('email', 'password', source='apps')
The login takes a while, so I asynched the retrievals with ajax calls. 登录需要一段时间,所以我用ajax调用使检索同步。 It is the login call that takes up most of the time and it needs to be done for multiple views. 登录调用占用了大多数时间,并且需要完成多个视图的操作。 Eg: one view renders the list of available groups and another view renders members of a selected group. 例如:一个视图呈现可用组的列表,另一个视图呈现选定组的成员。
I'm wondering if there's a way in Django to kinda persist such a client object so that it would be available in multiple views? 我想知道Django中是否有一种方法可以持久保留这样的客户端对象,以便可以在多个视图中使用?
If you made the GroupsProvisioningClient instance a module level global, and have utility function to get it, like: 如果您将GroupsProvisioningClient实例设置为全局模块级别,并且具有实用程序功能来获取它,例如:
CLIENT = GroupsProvisioningClient(domain="example.com")
def get_gapps_client():
if not CLIENT.is_authenticated() # made up function!
CLIENT = CLIENT.ClientLogin('email', 'password', source='apps')
return CLIENT
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.