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


Python DeleteAvatarForm.is_valid方法代码示例

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


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

示例1: delete

# 需要导入模块: from avatar.forms import DeleteAvatarForm [as 别名]
# 或者: from avatar.forms.DeleteAvatarForm import is_valid [as 别名]
def delete(request, extra_context={}, next_override=None):
    avatars = Avatar.objects.filter(user=request.user).order_by('-primary')
    if avatars.count() > 0:
        avatar = avatars[0]
    else:
        avatar = None
    delete_avatar_form = DeleteAvatarForm(request.POST or None, user=request.user)
    if request.method == 'POST':
        if delete_avatar_form.is_valid():
            ids = delete_avatar_form.cleaned_data['choices']
            if unicode(avatar.id) in ids and avatars.count() > len(ids):
                for a in avatars:
                    if unicode(a.id) not in ids:
                        a.primary = True
                        a.save()
                        notification.send([request.user], "avatar_updated", {"user": request.user, "avatar": a})
                        if friends:
                          notification.send((x['friend'] for x in Friendship.objects.friends_for_user(request.user)), "avatar_friend_updated", {"user": request.user, "avatar": a})
                        break
            Avatar.objects.filter(id__in=ids).delete()
            request.user.message_set.create(
                message=_("Successfully deleted the requested avatars."))
            return HttpResponseRedirect(next_override or _get_next(request))
    return render_to_response(
        'avatar/confirm_delete.html',
        extra_context,
        context_instance = RequestContext(
            request,
            { 'avatar': avatar, 
              'avatars': avatars,
              'delete_avatar_form': delete_avatar_form,
              'next': next_override or _get_next(request), }
        )
    )
开发者ID:dwscz1,项目名称:django-avatar,代码行数:36,代码来源:views.py

示例2: delete

# 需要导入模块: from avatar.forms import DeleteAvatarForm [as 别名]
# 或者: from avatar.forms.DeleteAvatarForm import is_valid [as 别名]
def delete(request, extra_context=None, next_override=None, *args, **kwargs):
    if extra_context is None:
        extra_context = {}
    avatar, avatars = _get_avatars(request.user)
    delete_avatar_form = DeleteAvatarForm(request.POST or None,
        user=request.user, avatars=avatars)
    if request.method == 'POST':
        if delete_avatar_form.is_valid():
            ids = delete_avatar_form.cleaned_data['choices']
            if unicode(avatar.id) in ids and avatars.count() > len(ids):
                # Find the next best avatar, and set it as the new primary
                for a in avatars:
                    if unicode(a.id) not in ids:
                        a.primary = True
                        a.save()
                        avatar_updated.send(sender=Avatar, user=request.user, avatar=avatar)
                        break
            Avatar.objects.filter(id__in=ids).delete()
            request.user.message_set.create(
                message=_("Successfully deleted the requested avatars."))
            return HttpResponseRedirect(next_override or _get_next(request))
    return render_to_response(
        'avatar/confirm_delete.html',
        extra_context,
        context_instance = RequestContext(
            request,
            { 'avatar': avatar, 
              'avatars': avatars,
              'delete_avatar_form': delete_avatar_form,
              'next': next_override or _get_next(request), }
        )
    )
开发者ID:ASKBOT,项目名称:django-avatar,代码行数:34,代码来源:views.py

示例3: delete

# 需要导入模块: from avatar.forms import DeleteAvatarForm [as 别名]
# 或者: from avatar.forms.DeleteAvatarForm import is_valid [as 别名]
def delete(request, extra_context=None, next_override=None, *args, **kwargs):
    if extra_context is None:
        extra_context = {}
    avatar, avatars = _get_avatars(request.user)
    delete_avatar_form = DeleteAvatarForm(request.POST or None, user=request.user, avatars=avatars)
    if request.method == "POST":
        if delete_avatar_form.is_valid():
            ids = delete_avatar_form.cleaned_data["choices"]
            if unicode(avatar.id) in ids and avatars.count() > len(ids):
                # Find the next best avatar, and set it as the new primary
                for a in avatars:
                    if unicode(a.id) not in ids:
                        a.primary = True
                        a.save()
                        avatar_updated.send(sender=Avatar, user=request.user, avatar=avatar)
                        break
            Avatar.objects.filter(id__in=ids).delete()
            messages.add_message(request, messages.INFO, _("Successfully deleted the requested avatars"))
            return HttpResponseRedirect(next_override or _get_next(request))
    return render_to_response(
        "avatar/confirm_delete.html",
        extra_context,
        context_instance=RequestContext(
            request,
            {
                "avatar": avatar,
                "avatars": avatars,
                "delete_avatar_form": delete_avatar_form,
                "next": next_override or _get_next(request),
            },
        ),
    )
开发者ID:saebyn,项目名称:django-avatar,代码行数:34,代码来源:views.py

示例4: delete

# 需要导入模块: from avatar.forms import DeleteAvatarForm [as 别名]
# 或者: from avatar.forms.DeleteAvatarForm import is_valid [as 别名]
def delete(request, extra_context=None, next_override=None, *args, **kwargs):
    if extra_context is None:
        extra_context = {}
    avatar, avatars = _get_avatars(request.user)
    delete_avatar_form = DeleteAvatarForm(request.POST or None,
        user=request.user, avatars=avatars)
    if request.method == 'POST':
        if delete_avatar_form.is_valid():
            ids = delete_avatar_form.cleaned_data['choices']
            if unicode(avatar.id) in ids and avatars.count() > len(ids):
                # Find the next best avatar, and set it as the new primary
                for a in avatars:
                    if unicode(a.id) not in ids:
                        a.primary = True
                        a.save()
                        if notification:
                            _notification_updated(request, a)
                        break
            Avatar.objects.filter(id__in=ids).delete()
            request.user.message_set.create(
                message=_("Successfully deleted the requested avatars."))
            return HttpResponseRedirect(next_override or _get_next(request))
    data = {
        'avatar': avatar, 
        'avatars': avatars,
        'delete_avatar_form': delete_avatar_form,
        'next': next_override or _get_next(request),
        'view_user': request.user,
        'page_class': 'avatar-page',
    }
    if extra_context:
        data.update(extra_context)

    return render_into_skin('avatar/confirm_delete.html', data, request)
开发者ID:Arpaso,项目名称:askbot-devel,代码行数:36,代码来源:avatar_views.py

示例5: delete_avatar_for_user

# 需要导入模块: from avatar.forms import DeleteAvatarForm [as 别名]
# 或者: from avatar.forms.DeleteAvatarForm import is_valid [as 别名]
def delete_avatar_for_user(request, for_user=None, extra_context=None,
        next_override=None, *args, **kwargs):
    target_user = get_object_or_404(User, username=for_user, is_active=True)
    if not AVATAR_ADMIN_TEST(request, target_user):
        raise PermissionDenied
    if extra_context is None:
        extra_context = {}
    avatar, avatars = _get_avatars(target_user)
    delete_avatar_form = DeleteAvatarForm(request.POST or None,
        user=target_user, avatars=avatars)
    if request.method == 'POST':
        if delete_avatar_form.is_valid():
            ids = delete_avatar_form.cleaned_data['choices']
            if unicode(avatar.id) in ids and avatars.count() > len(ids):
                # Find the next best avatar, and set it as the new primary
                for a in avatars:
                    if unicode(a.id) not in ids:
                        a.primary = True
                        a.save()
                        avatar_updated.send(sender=Avatar, user=target_user, avatar=avatar)
                        break
            Avatar.objects.filter(id__in=ids).delete()
            messages.add_message(request, messages.INFO, _("Successfully deleted the requested avatars"))
            return redirect(next_override or _get_next(request))
    context = {
        'avatar': avatar,
        'avatars': avatars,
        'target_user': target_user,
        'upload_avatar_form': upload_avatar_form,
        'next': next_override or _get_next(request),
    }
    context.update(extra_context)
    return render(request, 'avatar/add_for_user.html', context)
开发者ID:numegil,项目名称:django-avatar,代码行数:35,代码来源:views.py

示例6: delete

# 需要导入模块: from avatar.forms import DeleteAvatarForm [as 别名]
# 或者: from avatar.forms.DeleteAvatarForm import is_valid [as 别名]
def delete(request, extra_context=None, next_override=None, *args, **kwargs):
    if extra_context is None:
        extra_context = {}
    avatar, avatars = _get_avatars(request.user)
    delete_avatar_form = DeleteAvatarForm(request.POST or None,
                                          user=request.user,
                                          avatars=avatars)
    if request.method == 'POST':
        if delete_avatar_form.is_valid():
            ids = delete_avatar_form.cleaned_data['choices']
            if six.text_type(avatar.id) in ids and avatars.count() > len(ids):
                # Find the next best avatar, and set it as the new primary
                for a in avatars:
                    if six.text_type(a.id) not in ids:
                        a.primary = True
                        a.save()
                        avatar_updated.send(sender=Avatar, user=request.user,
                                            avatar=avatar)
                        break
            Avatar.objects.filter(id__in=ids).delete()
            messages.success(request,
                             _("Successfully deleted the requested avatars."))
            return redirect(next_override or _get_next(request))

    context = {
        'avatar': avatar,
        'avatars': avatars,
        'delete_avatar_form': delete_avatar_form,
        'next': next_override or _get_next(request),
    }
    context.update(extra_context)
    template_name = settings.AVATAR_DELETE_TEMPLATE or 'avatar/confirm_delete.html'
    return render(request, template_name, context)
开发者ID:phodal,项目名称:xunta,代码行数:35,代码来源:views.py

示例7: delete

# 需要导入模块: from avatar.forms import DeleteAvatarForm [as 别名]
# 或者: from avatar.forms.DeleteAvatarForm import is_valid [as 别名]
def delete(request, extra_context={}, next_override=None):
    avatars = Avatar.objects.filter(user=request.user).order_by('-primary')
    if avatars.count() > 0:
        avatar = avatars[0]
    else:
        avatar = None
    delete_avatar_form = DeleteAvatarForm(request.POST or None, user=request.user)
    if request.method == 'POST':
        if delete_avatar_form.is_valid():
            ids = delete_avatar_form.cleaned_data['choices']
            if unicode(avatar.id) in ids and avatars.count() > len(ids):
                for a in avatars:
                    if unicode(a.id) not in ids:
                        a.primary = True
                        a.save()
                        break
            Avatar.objects.filter(id__in=ids).delete()
            messages.success(request,
                message=_("Successfully deleted the requested avatars."))
            return HttpResponseRedirect(next_override or _get_next(request))
    context = {
        'avatar': avatar, 
        'avatars': avatars,
        'delete_avatar_form': delete_avatar_form,
        'next': next_override or _get_next(request), 
    }
    context.update(extra_context)

    return render(request, 'avatar/confirm_delete.html', context)
开发者ID:amarandon,项目名称:smeuhsocial,代码行数:31,代码来源:views.py

示例8: delete

# 需要导入模块: from avatar.forms import DeleteAvatarForm [as 别名]
# 或者: from avatar.forms.DeleteAvatarForm import is_valid [as 别名]
def delete(request, extra_context={}, next_override=None):
    avatars = Avatar.objects.filter(user=request.user).order_by('-primary')
    if avatars.count() > 0:
        avatar = avatars[0]
    else:
        avatar = None
    delete_avatar_form = DeleteAvatarForm(request.POST or None, user=request.user)
    if request.method == 'POST':
        if delete_avatar_form.is_valid():
            ids = delete_avatar_form.cleaned_data['choices']
            Avatar.objects.filter(id__in=ids).delete()
            request.user.message_set.create(
                message=_("Successfully deleted the requested avatars."))
            return HttpResponseRedirect(next_override or _get_next(request))
    return render_to_response(
        'avatar/confirm_delete.html',
        extra_context,
        context_instance = RequestContext(
            request,
            { 'avatar': avatar, 
              'avatars': avatars,
              'delete_avatar_form': delete_avatar_form,
              'next': next_override or _get_next(request), }
        )
    )
开发者ID:ericholscher,项目名称:allfeeds,代码行数:27,代码来源:views.py

示例9: delete

# 需要导入模块: from avatar.forms import DeleteAvatarForm [as 别名]
# 或者: from avatar.forms.DeleteAvatarForm import is_valid [as 别名]
def delete(request, extra_context=None, next_override=None, *args, **kwargs):
    if extra_context is None:
        extra_context = {}
    avatar, avatars = _get_avatars(request.user)
    delete_avatar_form = DeleteAvatarForm(request.POST or None,
        user=request.user, avatars=avatars)
    if request.method == 'POST':
        if delete_avatar_form.is_valid():
            ids = delete_avatar_form.cleaned_data['choices']
            if unicode(avatar.id) in ids and avatars.count() > len(ids):
                # Find the next best avatar, and set it as the new primary
                for a in avatars:
                    if unicode(a.id) not in ids:
                        a.primary = True
                        a.save()
                        if notification:
                            _notification_updated(request, a)
                        break
            Avatar.objects.filter(id__in=ids).delete()

            # Invalidate the cache to prevent wrong avatar appearing
            # when only one's left
            invalidate_cache(request.user)

            messages.success(request,
                             _("Successfully deleted the requested avatars.")
                             )
            return HttpResponseRedirect(next_override or _get_next(request))
    return render_to_response(
        'avatar/confirm_delete.html',
        extra_context,
        context_instance = RequestContext(
            request,
            { 'avatar': avatar, 
              'avatars': avatars,
              'delete_avatar_form': delete_avatar_form,
              'next': next_override or _get_next(request), }
        )
    )
开发者ID:SpreadBand,项目名称:django-avatar,代码行数:41,代码来源:views.py


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