本文整理汇总了Python中helpers.mytba_helper.MyTBAHelper类的典型用法代码示例。如果您正苦于以下问题:Python MyTBAHelper类的具体用法?Python MyTBAHelper怎么用?Python MyTBAHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MyTBAHelper类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self, event_key):
self._require_login()
self._require_registration()
current_user_id = self.user_bundle.account.key.id()
event = Event.get_by_id(event_key)
subscribed_matches = set(self.request.get_all('subscribed_matches'))
for match in event.matches:
if not match.has_been_played:
match_key = match.key.id()
if match.key.id() in subscribed_matches:
sub = Subscription(
parent=ndb.Key(Account, current_user_id),
user_id=current_user_id,
model_type=ModelType.MATCH,
model_key=match_key,
notification_types=[NotificationType.UPCOMING_MATCH]
)
MyTBAHelper.add_subscription(sub)
else:
MyTBAHelper.remove_subscription(current_user_id, match_key, ModelType.MATCH)
self.redirect('/account/mytba?status=match_updated#my-matches'.format(event_key))
示例2: post
def post(self):
if not self.user_bundle.user:
self.response.set_status(401)
return
model_key = self.request.get("model_key")
user_id = self.user_bundle.user.user_id()
MyTBAHelper.remove_favorite(user_id, model_key)
示例3: post
def post(self):
if not self.user_bundle.user:
self.response.set_status(401)
return
model_type = int(self.request.get("model_type"))
model_key = self.request.get("model_key")
user_id = self.user_bundle.user.user_id()
fav = Favorite(parent=ndb.Key(Account, user_id), user_id=user_id, model_key=model_key, model_type=model_type)
MyTBAHelper.add_favorite(fav)
示例4: post
def post(self, event_key):
self._require_registration()
current_user_id = self.user_bundle.account.key.id()
if self.request.get("favorite"):
favorite = Favorite(
parent=ndb.Key(Account, current_user_id),
user_id=current_user_id,
model_type=ModelType.EVENT,
model_key=event_key,
)
MyTBAHelper.add_favorite(favorite)
else:
MyTBAHelper.remove_favorite(current_user_id, event_key, ModelType.EVENT)
subs = self.request.get_all("notification_types")
if subs:
subscription = Subscription(
parent=ndb.Key(Account, current_user_id),
user_id=current_user_id,
model_type=ModelType.EVENT,
model_key=event_key,
notification_types=[int(s) for s in subs],
)
MyTBAHelper.add_subscription(subscription)
else:
MyTBAHelper.remove_subscription(current_user_id, event_key, ModelType.EVENT)
self.redirect("/account/mytba?status=event_updated#my-events")
示例5: update_model_preferences
def update_model_preferences(self, request):
current_user = endpoints.get_current_user()
if current_user is None:
return BaseResponse(code=401, message="Unauthorized to update model preferences")
user_id = PushHelper.user_email_to_id(current_user.email())
model_key = request.model_key
output = {}
code = 0
if request.favorite:
fav = Favorite(
parent=ndb.Key(Account, user_id),
user_id=user_id,
model_key=model_key,
model_type=request.model_type
)
result = MyTBAHelper.add_favorite(fav, request.device_key)
if result == 200:
output['favorite'] = {"code": 200,
"message": "Favorite added"}
code += 100
elif result == 304:
output['favorite'] = {"code": 304,
"message": "Favorite already exists"}
code += 304
else:
output['favorite'] = {"code": 500,
"message": "Unknown error adding favorite"}
code += 500
else:
result = MyTBAHelper.remove_favorite(user_id, model_key, request.device_key)
if result == 200:
output['favorite'] = {"code": 200,
"message": "Favorite deleted"}
code += 100
elif result == 404:
output['favorite'] = {"code": 404,
"message": "Favorite not found"}
code += 404
else:
output['favorite'] = {"code": 500,
"message": "Unknown error removing favorite"}
code += 500
if request.notifications:
sub = Subscription(
parent=ndb.Key(Account, user_id),
user_id=user_id,
model_key=model_key,
model_type=request.model_type,
notification_types=PushHelper.notification_enums_from_string(request.notifications)
)
result = MyTBAHelper.add_subscription(sub, request.device_key)
if result == 200:
output['subscription'] = {"code": 200,
"message": "Subscription updated"}
code += 100
elif result == 304:
output['subscription'] = {"code": 304,
"message": "Subscription already exists"}
code += 304
else:
output['subscription'] = {"code": 500,
"message": "Unknown error adding favorite"}
code += 500
else:
result = MyTBAHelper.remove_subscription(user_id, model_key, request.device_key)
if result == 200:
output['subscription'] = {"code": 200,
"message": "Subscription removed"}
code += 100
elif result == 404:
output['subscription'] = {"code": 404,
"message": "Subscription not found"}
code += 404
else:
output['subscription'] = {"code": 500,
"message": "Unknown error removing subscription"}
code += 500
return BaseResponse(code=code, message=json.dumps(output))
示例6: post
def post(self):
self._require_login('/account/register')
self._require_registration('/account/register')
current_user_id = self.user_bundle.account.key.id()
target_account_id = self.request.get('account_id')
if current_user_id == target_account_id:
action = self.request.get('action')
# if action == "favorite_add":
# model = self.request.get('model_key')
# if not ValidationHelper.is_valid_model_key(model):
# self.redirect('/account/mytba?error=invalid_model')
# return
# favorite = Favorite(parent = ndb.Key(Account, current_user_id), model_key = model, user_id = current_user_id)
# MyTBAHelper.add_favorite(favorite)
# self.redirect('/account/mytba')
# return
if action == "favorite_delete":
model_key = self.request.get('model_key')
result = MyTBAHelper.remove_favorite(current_user_id, model_key)
if result == 404:
self.redirect('/account/mytba?error=fav_not_found')
return
self.redirect('/account/mytba')
return
# elif action == "subscription_add":
# model = self.request.get('model_key')
# if not ValidationHelper.is_valid_model_key(model):
# self.redirect('/account/mytba?error=invalid_model')
# return
# subs = self.request.get_all('notification_types')
# if not subs:
# # No notification types specified. Don't add
# self.redirect('/account/mytba?error=no_sub_types')
# return
# subscription = Subscription(parent = ndb.Key(Account, current_user_id), user_id = current_user_id, model_key = model, notification_types = [int(s) for s in subs])
# MyTBAHelper.add_subscription(subscription)
# self.redirect('/account/mytba')
# return
elif action == "subscription_year_add":
now = datetime.datetime.now()
year = self.request.get('year')
if not "{}".format(now.year) == year:
# Can only subscribe to the current year's firehose
self.redirect('/account/mytba?error=invalid_year')
return
key = "{}*".format(year)
subs = self.request.get_all('notification_types')
if not subs:
# No notification types specified. Don't add
self.redirect('/account/mytba?error=no_sub_types')
return
subscription = Subscription(parent = ndb.Key(Account, current_user_id), user_id = current_user_id, model_key = key, model_type = ModelType.EVENT, notification_types = [int(s) for s in subs])
logging.info("{}".format(self.request.get('webhooks_only')))
MyTBAHelper.add_subscription(subscription)
self.redirect('/account/mytba')
return
elif action == "subscription_delete":
model_key = self.request.get('model_key')
result = MyTBAHelper.remove_subscription(current_user_id, model_key)
if result == 404:
self.redirect('/account/mytba?error=sub_not_found')
return
self.redirect('/account/mytba')
return
self.redirect('/account/mytba?error=invalid_account')