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


Python models.UserNotification类代码示例

本文整理汇总了Python中users.models.UserNotification的典型用法代码示例。如果您正苦于以下问题:Python UserNotification类的具体用法?Python UserNotification怎么用?Python UserNotification使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: unsubscribe

def unsubscribe(request, hash=None, token=None, perm_setting=None):
    """
    Pulled from django contrib so that we can add user into the form
    so then we can show relevant messages about the user.
    """
    assert hash is not None and token is not None
    user = None

    try:
        email = UnsubscribeCode.parse(token, hash)
        user = UserProfile.objects.get(email=email)
    except (ValueError, UserProfile.DoesNotExist):
        pass

    perm_settings = []
    if user is not None:
        unsubscribed = True
        if not perm_setting:
            # TODO: make this work. nothing currently links to it, though.
            perm_settings = [l for l in notifications.NOTIFICATIONS
                             if not l.mandatory]
        else:
            perm_setting = notifications.NOTIFICATIONS_BY_SHORT[perm_setting]
            UserNotification.update_or_create(update={'enabled': False},
                    user=user, notification_id=perm_setting.id)
            perm_settings = [perm_setting]
    else:
        unsubscribed = False
        email = ''

    return jingo.render(request, 'users/unsubscribe.html',
            {'unsubscribed': unsubscribed, 'email': email,
             'perm_settings': perm_settings})
开发者ID:dimonov,项目名称:zamboni,代码行数:33,代码来源:views.py

示例2: save

    def save(self):
        u = super(UserEditForm, self).save(commit=False)
        data = self.cleaned_data

        photo = data['photo']
        if photo:
            u.picture_type = 'image/png'
            tmp_destination = u.picture_path + '__unconverted'

            if not os.path.exists(u.picture_dir):
                os.makedirs(u.picture_dir)

            fh = open(tmp_destination, 'w')
            for chunk in photo.chunks():
                fh.write(chunk)

            fh.close()
            resize_photo.delay(tmp_destination, u.picture_path,
                               set_modified_on=[u])

        for i, n in email.APP_NOTIFICATIONS_BY_ID.iteritems():
            enabled = n.mandatory or (str(i) in data['notifications'])
            UserNotification.update_or_create(user=u, notification_id=i,
                update={'enabled': enabled})

        log.debug(u'User (%s) updated their profile' % u)

        u.save()
        return u
开发者ID:gkoberger,项目名称:zamboni,代码行数:29,代码来源:forms.py


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