当前位置: 首页>>代码示例>>Python>>正文


Python Subscription.get_by_id方法代码示例

本文整理汇总了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)
开发者ID:fikander,项目名称:aolevents,代码行数:69,代码来源:views.py

示例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"))
开发者ID:fikander,项目名称:aolevents,代码行数:7,代码来源:views.py


注:本文中的models.Subscription.get_by_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。