本文整理汇总了Python中models.Subscription.get方法的典型用法代码示例。如果您正苦于以下问题:Python Subscription.get方法的具体用法?Python Subscription.get怎么用?Python Subscription.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Subscription
的用法示例。
在下文中一共展示了Subscription.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: subscribe
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import get [as 别名]
def subscribe(subscriber, resource):
# HACK workaround for using get_or_create / create_or_get with GFKFields.
try:
# HACK workaround for querying equality of GFKField. I'd love to do the following:
# Subscription.get(
# (Subscription.subscriber == subscriber) &
# (Subscription.resource == resource))
sub = Subscription.get(
(Subscription.subscriber_id == subscriber._get_pk_value()) &
(Subscription.subscriber_type == subscriber._meta.db_table) &
(Subscription.resource_id == resource._get_pk_value()) &
(Subscription.resource_type == resource._meta.db_table))
created = False
except Subscription.DoesNotExist:
sub = Subscription.create(
subscriber=subscriber,
resource=resource,
)
created = True
return sub, created
示例2: get_subscription
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import get [as 别名]
def get_subscription(user_id, id):
try:
user = User.get(User.id == user_id)
subscription = Subscription.get(Subscription.id == id)
return {'subscriptions': [subscription.json_dict_user(user)]}
except Subscription.DoesNotExist:
response.status = 404
except User.DoesNotExist:
response.status = 401
return {}
示例3: subscribe_subscription_topic
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import get [as 别名]
def subscribe_subscription_topic(user_id, sid):
try:
user = User.get(User.id == user_id)
subscription = Subscription.get(Subscription.id == sid)
user.unsubscribe_all(subscription)
return {'subscriptions': [subscription.json_dict_user(user)]}
except Subscription.DoesNotExist:
response.status = 404
except User.DoesNotExist:
response.status = 401
return {}
示例4: unsubscribe_subscription_topic
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import get [as 别名]
def unsubscribe_subscription_topic(user_id, sid, tid):
try:
user = User.get(User.id == user_id)
subscription = Subscription.get(Subscription.id == sid)
topic = subscription.get_topic(tid)
user.unsubscribe(subscription, topic)
return {'subscriptions': [subscription.json_dict_user(user)]}
except (Subscription.DoesNotExist, Topic.DoesNotExist):
response.status = 404
except User.DoesNotExist:
response.status = 401
return {}
示例5: get
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import get [as 别名]
def get(self, **args):
sub = Subscription.get(Key.from_path("Subscription", long(args['id'])))
if not sub or sub.deleted:
helpers.createResponse(self, 'message_not_exist.html')
return
if not helpers.checkPermissionAndRespond(self, sub=sub, edit=False): return
subItem_q = sub.subscribeditem_set.filter("deleted ==", False).order("original")
cursor = self.request.get('cursor_subItem')
if cursor:
subItem_q = subItem_q.with_cursor(cursor)
subItems = subItem_q.fetch(10)
helpers.createResponse(self, 'dashboard_subItems.html',
{'subItems': subItems,
'sub': sub,
'cursor_subItem': subItem_q.cursor()})