本文整理汇总了Python中models.Subscription.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Subscription.get_by_id方法的具体用法?Python Subscription.get_by_id怎么用?Python Subscription.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Subscription
的用法示例。
在下文中一共展示了Subscription.get_by_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: view_event_list
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import get_by_id [as 别名]
def view_event_list(request, subscription_id=None):
search_form = None
if (request.method == "GET") and len(request.GET) > 0:
search_form = AdvancedEventFilterForm(request.GET)
elif subscription_id:
if isinstance(subscription_id, int):
s = Subscription.get_by_id(subscription_id)
else:
s = Subscription.get_by_id(int(subscription_id, 10))
if s:
if s.country:
country_id = s.country.key().name()
else:
country_id = None
if s.region:
region_id = s.region.key().name()
else:
region_id = None
typelist = []
# See if subscription is generalised, so that we can use forwho = everyone or members
if s.event_types == Event.OPEN_EVENTS_MASK:
forwho = "everyone"
elif s.event_types == Event.MEMBERS_EVENTS_MASK:
forwho = "members"
else:
forwho = "custom"
# convert bit mask into list of numbers
bit = 1
counter = 0
typelist = []
while bit < Event.MEMBERS_EVENTS_MASK:
if bit & s.event_types:
typelist.append(counter)
counter += 1
bit = bit << 1
search_form = AdvancedEventFilterForm(
initial={
"country": country_id,
"region": region_id,
"forwho": forwho,
"forfree": s.free,
"typelist": typelist,
}
)
if not search_form:
search_form = AdvancedEventFilterForm(initial={"country": "GB", "forwho": "members", "forfree": False})
subscription_list = None
if request.user.is_authenticated():
subscription_list = request.user.subscription_set
r = RequestContext(
request,
{
"search_form": search_form,
"OPEN_EVENTS_MASK": Event.OPEN_EVENTS_MASK,
"MEMBERS_EVENTS_MASK": Event.MEMBERS_EVENTS_MASK,
"subscription_list": subscription_list,
},
)
return render_to_response("event_list.html", r)
示例2: view_delete_subscription
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import get_by_id [as 别名]
def view_delete_subscription(request, key_id):
s = Subscription.get_by_id(int(key_id, 10))
if s and (s.user == request.user or request.user.is_superuser):
s.delete()
return HttpResponseRedirect(reverse("events.views.view_event_subscribed"))