本文整理汇总了Python中subscription.models.Subscription.get_absolute_url方法的典型用法代码示例。如果您正苦于以下问题:Python Subscription.get_absolute_url方法的具体用法?Python Subscription.get_absolute_url怎么用?Python Subscription.get_absolute_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subscription.models.Subscription
的用法示例。
在下文中一共展示了Subscription.get_absolute_url方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: subscribe
# 需要导入模块: from subscription.models import Subscription [as 别名]
# 或者: from subscription.models.Subscription import get_absolute_url [as 别名]
def subscribe(request):
form = SubscriptionForm(request.POST)
if not form.is_valid():
return index(request, form=form)
editing = False
if form.cleaned_data["subkey"] == "":
subkey = Subscription.generate_subkey()
subscription = Subscription(last_changed=datetime.datetime.now(), subkey=subkey)
else:
editing = True
subkey = form.cleaned_data["subkey"]
subscription = form._subscription
sub_settings = {}
subscription.set_settings(sub_settings)
try:
selected_shows = Show.get_by_id(map(int, form.cleaned_data["shows"]))
except ValueError:
return index(request, form=form)
old_shows = []
if editing:
old_shows = subscription.get_shows()
subscription.reset_cache(selected_shows)
subscription.put() # stay here, need key for setting shows!
if editing:
subscription.set_shows(selected_shows, old_shows=old_shows)
else:
subscription.set_shows(selected_shows)
response = HttpResponseRedirect(subscription.get_absolute_url())
response.set_cookie("subkey", subkey, max_age=31536000)
return response