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


Python Subscriptions.get_by_id方法代码示例

本文整理汇总了Python中h.notification.models.Subscriptions.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Subscriptions.get_by_id方法的具体用法?Python Subscriptions.get_by_id怎么用?Python Subscriptions.get_by_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在h.notification.models.Subscriptions的用法示例。


在下文中一共展示了Subscriptions.get_by_id方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _update_subscription_data

# 需要导入模块: from h.notification.models import Subscriptions [as 别名]
# 或者: from h.notification.models.Subscriptions import get_by_id [as 别名]
def _update_subscription_data(request, subscription):
    """
    Update the subscriptions in the database from form data.

    Using data from the passed subscription struct, find a subscription in the
    database, and update it (if it belongs to the current logged-in user).
    """
    sub = Subscriptions.get_by_id(subscription['id'])
    if sub is None:
        return {
            'errors': {'subscriptions': _('Subscription not found')},
        }

    # If we're trying to update a subscription for anyone other than
    # the currently logged-in user, bail fast.
    #
    # The error message is deliberately identical to the one above, so
    # as not to leak any information about who which subscription ids
    # belong to.
    if sub.uri != request.authenticated_userid:
        return {
            'errors': {'subscriptions': _('Subscription not found')},
        }

    sub.active = subscription.get('active', True)

    request.session.flash(_('Changes saved!'), 'success')
开发者ID:hylhero,项目名称:h,代码行数:29,代码来源:views.py

示例2: unsubscribe

# 需要导入模块: from h.notification.models import Subscriptions [as 别名]
# 或者: from h.notification.models.Subscriptions import get_by_id [as 别名]
 def unsubscribe(self):
     request = self.request
     subscription_id = request.GET['subscription_id']
     subscription = Subscriptions.get_by_id(subscription_id)
     if subscription:
         subscription.active = False
         return {}
     return {}
开发者ID:hylhero,项目名称:h,代码行数:10,代码来源:views.py

示例3: unsubscribe

# 需要导入模块: from h.notification.models import Subscriptions [as 别名]
# 或者: from h.notification.models.Subscriptions import get_by_id [as 别名]
 def unsubscribe(self):
     request = self.request
     subscription_id = request.GET['subscription_id']
     subscription = Subscriptions.get_by_id(subscription_id)
     if subscription:
         if request.authenticated_userid != subscription.uri:
             raise httpexceptions.HTTPUnauthorized()
         subscription.active = False
         return {}
     return {}
开发者ID:dezynetechnologies,项目名称:h,代码行数:12,代码来源:views.py

示例4: edit_profile

# 需要导入模块: from h.notification.models import Subscriptions [as 别名]
# 或者: from h.notification.models.Subscriptions import get_by_id [as 别名]
    def edit_profile(self):
        try:
            appstruct = _validate_edit_profile_request(self.request)
        except _InvalidEditProfileRequestError as err:
            return dict(errors=err.errors)

        username = appstruct['username']
        pwd = appstruct['pwd']
        subscriptions = appstruct['subscriptions']

        if subscriptions:
            # Update the subscriptions table
            subs = json.loads(subscriptions)
            if username == subs['uri']:
                s = Subscriptions.get_by_id(self.request, subs['id'])
                if s:
                    s.active = subs['active']
                    self.db.add(s)
                    return {}
                else:
                    return dict(
                        errors=[
                            {'subscriptions': _('Non existing subscription')}
                        ],
                        code=404
                    )
            else:
                return dict(
                    errors=[{'username': _('Invalid username')}], code=400
                )

        # Password check
        user = self.User.get_user(self.request, username, pwd)
        if user:
            self.request.context = user
            response = super(ProfileController, self).edit_profile()

            # Add the user's email into the model dict that eventually gets
            # returned to the browser. This is needed so that the edit profile
            # forms can show the value of the user's current email.
            if self.request.authenticated_userid:
                user = h.accounts.models.User.get_by_id(
                    self.request, self.request.authenticated_userid)
                response.json = {"model": {"email": user.email}}

            return response
        else:
            return dict(errors=[{'pwd': _('Invalid password')}], code=401)
开发者ID:klrkdekira,项目名称:h,代码行数:50,代码来源:views.py

示例5: edit_profile

# 需要导入模块: from h.notification.models import Subscriptions [as 别名]
# 或者: from h.notification.models.Subscriptions import get_by_id [as 别名]
    def edit_profile(self):
        request = self.request
        schema = schemas.EditProfileSchema().bind(request=request)
        form = deform.Form(schema)

        try:
            appstruct = form.validate(request.POST.items())
        except deform.ValidationFailure as e:
            return dict(errors=e.error.children)

        username = appstruct['username']
        pwd = appstruct['pwd']
        subscriptions = appstruct['subscriptions']

        if subscriptions:
            # Update the subscriptions table
            subs = json.loads(subscriptions)
            if username == subs['uri']:
                s = Subscriptions.get_by_id(request, subs['id'])
                if s:
                    s.active = subs['active']
                    self.db.add(s)
                    return {}
                else:
                    return dict(
                        errors=[
                            {'subscriptions': _('Non existing subscription')}
                        ],
                        code=404
                    )
            else:
                return dict(
                    errors=[{'username': _('Invalid username')}], code=400
                )

        # Password check
        user = self.User.get_user(request, username, pwd)
        if user:
            request.context = user
            return super(ProfileController, self).edit_profile()
        else:
            return dict(errors=[{'pwd': _('Invalid password')}], code=401)
开发者ID:bradparks,项目名称:h,代码行数:44,代码来源:views.py


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