本文整理汇总了Python中models.Client.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Client.get_by_id方法的具体用法?Python Client.get_by_id怎么用?Python Client.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Client
的用法示例。
在下文中一共展示了Client.get_by_id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: finish_event
# 需要导入模块: from models import Client [as 别名]
# 或者: from models.Client import get_by_id [as 别名]
def finish_event(self, request):
"""
Mark an event as finished and set the actual end time as right now.
Updates the Google Calendar event accordingly.
"""
current_user = endpoints.get_current_user()
if current_user is None:
current_user_email = request.userEmail
else:
current_user_email = current_user.email()
# TODO: Can really anyone finish an event?
logging.info('Someone [%s] just marked event ID [%s] as finished',
current_user_email, request.id)
event = ResourceEvent.get_by_id(request.id)
if not event:
raise endpoints.BadRequestException(
'Unable to find event with id %s' % request.id)
event.state = constants.STATE_FINISHED
event.actual_end_date_time = datetime.now()
event.put()
resource = event.resource_key.get()
# Create event in Google Calendar
client = Client.get_by_id(1)
if not client or not client.credentials or not client.refresh_token:
raise endpoints.BadRequestException(
'Domain calendar access is not yet configured')
try:
calendar_helper = CalendarHelper(
client.credentials, client.refresh_token
)
calendar_helper.insert_or_update_event(
calendar_id=resource.email,
start_date=event.start_date_time,
end_date=datetime.now(),
event_id=event.key.string_id()
)
except:
logging.exception('Exception while updating the GCal event')
raise endpoints.BadRequestException(
'Unable to update the Google Calendar event')
return event_db_to_rcp(event)
示例2: oauth_callback
# 需要导入模块: from models import Client [as 别名]
# 或者: from models.Client import get_by_id [as 别名]
def oauth_callback():
code = request.args.get("code", None)
if not code:
logging.error("No code, no authorization")
abort(500)
redirect_uri = helpers.url_for("oauth_callback", _external=True)
oauth_helper = OAuthDanceHelper(redirect_uri=redirect_uri)
credentials = oauth_helper.step2_exchange(code)
client = Client.get_by_id(1)
if not client:
logging.error("No client object, aborting authorization")
abort(500)
client.credentials = credentials.to_json()
if credentials.refresh_token:
client.refresh_token = credentials.refresh_token
client.put()
return redirect(helpers.url_for("settings"))
示例3: start_oauth2_dance
# 需要导入模块: from models import Client [as 别名]
# 或者: from models.Client import get_by_id [as 别名]
def start_oauth2_dance(self):
login_hint = ''
scope = ''
client = Client.get_by_id(1)
if not client:
# If client does not exist then create an empty one
client = Client(id=1)
client.installer_user = users.get_current_user().email()
client.put()
# Get the login hint from configuration
approval_prompt = 'auto' if client.refresh_token else 'force'
scope = constants.OAUTH2_SCOPE
redirect_uri = helpers.url_for('oauth.oauth_callback',
_external=True)
oauth_helper = OAuthDanceHelper(redirect_uri, approval_prompt, scope)
url = oauth_helper.step1_get_authorize_url()
#TODO: Add a random token to avoid forgery
return redirect(url)
示例4: start_oauth2_dance
# 需要导入模块: from models import Client [as 别名]
# 或者: from models.Client import get_by_id [as 别名]
def start_oauth2_dance():
login_hint = ""
scope = ""
client = Client.get_by_id(1)
if not client:
# If client does not exist then create an empty one
client = Client(id=1)
client.put()
# Get the login hint from configuration
# approval_prompt = 'auto' if client.reseller_refresh_token else 'force'
# Always force to be sure to get valid refresh token
approval_prompt = "force"
login_hint = get_setting("OAUTH2_RESELLER_DOMAIN_USER")
scope = get_setting("OAUTH2_SCOPE")
redirect_uri = helpers.url_for("oauth_callback", _external=True)
oauth_helper = OAuthDanceHelper(scope=scope, redirect_uri=redirect_uri, approval_prompt=approval_prompt)
url = oauth_helper.step1_get_authorize_url()
# TODO: Add a random token to avoid forgery
return redirect("%s&login_hint=%s" % (url, login_hint))
示例5: oauth_callback
# 需要导入模块: from models import Client [as 别名]
# 或者: from models.Client import get_by_id [as 别名]
def oauth_callback(self):
code = request.args.get('code', None)
if code:
redirect_uri = helpers.url_for('oauth.oauth_callback',
_external=True)
oauth_helper = OAuthDanceHelper(redirect_uri)
credentials = oauth_helper.step2_exchange(code)
client = Client.get_by_id(1)
if client:
client.credentials = credentials.to_json()
if credentials.refresh_token:
client.refresh_token = credentials.refresh_token
client.put()
return redirect(helpers.url_for('oauth.index'))
else:
logging.error('No client object, aborting authorization')
abort(500)
else:
logging.error('No code, no authorization')
abort(500)
示例6: book_resource
# 需要导入模块: from models import Client [as 别名]
# 或者: from models.Client import get_by_id [as 别名]
def book_resource(self, request):
"""
Let an anonymous user book a resource in the moment, create a calendar
event and checks the user in. If the resource doesn't exists throws an
exception. If there is an event happening throws an exception.
"""
logging.info('Someone is creating a quick event at [%s]',
request.id)
resource = ResourceCalendar.get_by_id(request.id)
if not resource:
raise endpoints.BadRequestException(
'Unable to find resource with id %s' % request.id)
if not resource.will_be_available(constants.QUICK_ADD_MINUTES):
raise endpoints.BadRequestException(
'There is an event happening at the resource')
now = datetime.now()
end_time = now + timedelta(minutes=constants.QUICK_ADD_MINUTES)
# Create event in Google Calendar
client = Client.get_by_id(1)
if not client or not client.credentials or not client.refresh_token:
raise endpoints.BadRequestException(
'Domain calendar access is not yet configured')
try:
calendar_helper = CalendarHelper(
client.credentials, client.refresh_token
)
calendar_event = calendar_helper.insert_or_update_event(
calendar_id=resource.email, summary=constants.QUICK_ADD_TITLE,
description=constants.QUICK_ADD_DESCRIPTION, start_date=now,
end_date=end_time,
location=resource.name
)
except:
logging.exception('Exception while creating the GCal event')
raise endpoints.BadRequestException(
'Unable to create the Google Calendar event')
# Save in datastore
user = ''
if request.userEmail:
user = request.userEmail
else:
user = client.installer_user
resource_event = ResourceEvent(
organizer=user,
original_start_date_time=now,
original_end_date_time=end_time,
actual_start_date_time=now,
resource_key=resource.key,
title=constants.QUICK_ADD_TITLE,
is_express=True,
state=constants.STATE_IN_PROGRESS,
)
resource_event.UpdateFromKey(ndb.Key(ResourceEvent, calendar_event[
'id']))
resource_event.put()
store_check_in(resource_event, user)
return event_db_to_rcp(resource_event)