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


Python Avatar.primary方法代码示例

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


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

示例1: change_avatar

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import primary [as 别名]
def change_avatar(request, id, extra_context={}, next_override=None):
    user_edit = get_object_or_404(User, pk=id)
    try:
        profile = Profile.objects.get(user=user_edit)
    except Profile.DoesNotExist:
        profile = Profile.objects.create_profile(user=user_edit)
        
    #if not has_perm(request.user,'profiles.change_profile',profile): raise Http403
    if not profile.allow_edit_by(request.user): raise Http403
    
    avatars = Avatar.objects.filter(user=user_edit).order_by('-primary')
    if avatars.count() > 0:
        avatar = avatars[0]
        kwargs = {'initial': {'choice': avatar.id}}
    else:
        avatar = None
        kwargs = {}
    primary_avatar_form = PrimaryAvatarForm(request.POST or None, user=user_edit, **kwargs)
    if request.method == "POST":
        updated = False
        if 'avatar' in request.FILES:
            path = avatar_file_path(user=user_edit, 
                filename=request.FILES['avatar'].name)
            avatar = Avatar(
                user = user_edit,
                primary = True,
                avatar = path,
            )
            new_file = avatar.avatar.storage.save(path, request.FILES['avatar'])
            avatar.save()
            updated = True
            request.user.message_set.create(
                message=_("Successfully uploaded a new avatar."))
        if 'choice' in request.POST and primary_avatar_form.is_valid():
            avatar = Avatar.objects.get(id=
                primary_avatar_form.cleaned_data['choice'])
            avatar.primary = True
            avatar.save()
            updated = True
            request.user.message_set.create(
                message=_("Successfully updated your avatar."))
        if updated and notification:
            notification.send([request.user], "avatar_updated", {"user": user_edit, "avatar": avatar})
            #if friends:
            #    notification.send((x['friend'] for x in Friendship.objects.friends_for_user(user_edit)), "avatar_friend_updated", {"user": user_edit, "avatar": avatar})
        return HttpResponseRedirect(reverse('profile', args=[user_edit.username]))
        #return HttpResponseRedirect(next_override or _get_next(request))
    return render_to_response(
        'profiles/change_avatar.html',
        extra_context,
        context_instance = RequestContext(
            request,
            {'user_this': user_edit,
              'avatar': avatar, 
              'avatars': avatars,
              'primary_avatar_form': primary_avatar_form,
              'next': next_override or _get_next(request), }
        )
    )
开发者ID:BakethemPie,项目名称:tendenci,代码行数:61,代码来源:views.py

示例2: copy_avatar

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import primary [as 别名]
def copy_avatar(request, user, account):
    url = account.get_avatar_url()
    if url:
        ava = Avatar(user=user)
        ava.primary = Avatar.objects.filter(user=user).count() == 0
        try:
            content = urllib2.urlopen(url).read()
            name = name_from_url(url)
            ava.avatar.save(name, ContentFile(content))
        except IOError:
            # Let's nog make a big deal out of this...
            pass
开发者ID:maximzxc,项目名称:django-allauth-multiple,代码行数:14,代码来源:userpic.py

示例3: change_avatar

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import primary [as 别名]
def change_avatar(request, target_obj, target_type, from_name, extra_context={}, 
                  next_override=None, current_app='plus_groups',namespace='groups',**kwargs):

    # XXX some of this should probably be refactored into the model layer 
    target = target_obj.get_ref()
    avatars = Avatar.objects.filter(target=target).order_by('-primary')
    if avatars.count() > 0:
        avatar = avatars[0]
        kwargs = {'initial': {'choice': avatar.id}}
    else:
        avatar = None
        kwargs = {}

    primary_avatar_form = PrimaryAvatarForm(request.POST or None, target=target, **kwargs)
    if request.method == "POST":
        if 'avatar' in request.FILES:
            path = avatar_file_path(target=target, 
                filename=request.FILES['avatar'].name)
            avatar = Avatar(
                target = target,
                primary = True,
                avatar = path,
            )
            new_file = avatar.avatar.storage.save(path, request.FILES['avatar'])
            avatar.save()
            request.user.message_set.create(
                message=_("Successfully uploaded a new avatar."))
        if 'choice' in request.POST and primary_avatar_form.is_valid():
            avatar = Avatar.objects.get(id=
                primary_avatar_form.cleaned_data['choice'])
            avatar.primary = True 
            avatar.save()
            
            request.user.message_set.create(
                message=_("Successfully updated your avatar."))
        return HttpResponseRedirect(next_override or _get_next(request))

    return render_to_response(
        'avatar/change.html',
        extra_context,
        context_instance = RequestContext(
            request,
            { 'avatar': avatar, 
              'avatars': avatars,
              'primary_avatar_form': primary_avatar_form,
              'next': next_override or _get_next(request),
              'target' : target_obj,
              'target_type' : target_type,
              'from_name' : from_name,
              }
        )
    )
开发者ID:GunioRobot,项目名称:hubplus,代码行数:54,代码来源:views.py

示例4: change

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import primary [as 别名]
def change(request, extra_context={}, next_override=None):
    avatars = Avatar.objects.filter(user=request.user).order_by('-primary')
    if avatars.count() > 0:
        avatar = avatars[0]
        kwargs = {'initial': {'choice': avatar.id}}
    else:
        avatar = None
        kwargs = {}
    primary_avatar_form = PrimaryAvatarForm(
        request.POST or None, user=request.user, **kwargs)
    if request.method == "POST":
        updated = False
        if 'avatar' in request.FILES:
            path = avatar_file_path(user=request.user,
                                    filename=request.FILES['avatar'].name)
            avatar = Avatar(
                user=request.user,
                primary=True,
                avatar=path,
            )
            new_file = avatar.avatar.storage.save(
                path, request.FILES['avatar'])
            avatar.save()
            updated = True
            messages.info(request,
                _("Successfully uploaded a new avatar."))
        if 'choice' in request.POST and primary_avatar_form.is_valid():
            avatar = Avatar.objects.get(id=
                                        primary_avatar_form.cleaned_data['choice'])
            avatar.primary = True
            avatar.save()
            updated = True
            messages.info(request,
                _("Successfully updated your avatar."))
        if updated and notification:
            notification.send([request.user], "avatar_updated", {
                              "user": request.user, "avatar": avatar})
            if friends:
                notification.send((x['friend'] for x in Friendship.objects.friends_for_user(
                    request.user)), "avatar_friend_updated", {"user": request.user, "avatar": avatar})
        return HttpResponseRedirect(next_override or _get_next(request))
    return render_to_response(
        'avatar/change.html',
        extra_context,
        context_instance=RequestContext(
            request,
            {'avatar': avatar,
             'avatars': avatars,
             'primary_avatar_form': primary_avatar_form,
             'next': next_override or _get_next(request), }
        )
    )
开发者ID:mberingen,项目名称:ScrumDo,代码行数:54,代码来源:views.py

示例5: _copy_avatar

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import primary [as 别名]
def _copy_avatar(request, user, account):
    import urllib2
    from django.core.files.base import ContentFile
    from avatar.models import Avatar
    url = account.get_avatar_url()
    if url:
        ava = Avatar(user=user)
        ava.primary = Avatar.objects.filter(user=user).count() == 0
        try:
            content = urllib2.urlopen(url).read()
            name = _name_from_url(url)
            ava.avatar.save(name, ContentFile(content))
        except IOError:
            # Let's nog make a big deal out of this...
            pass
开发者ID:AntonOfTheWoods,项目名称:django-allauth,代码行数:17,代码来源:helpers.py

示例6: change

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import primary [as 别名]
def change(request, extra_context={}, next_override=None):
    avatars = Avatar.objects.filter(user=request.user).order_by("-primary")
    if avatars.count() > 0:
        avatar = avatars[0]
        kwargs = {"initial": {"choice": avatar.id}}
    else:
        avatar = None
        kwargs = {}
    primary_avatar_form = PrimaryAvatarForm(request.POST or None, user=request.user, **kwargs)
    if request.method == "POST":
        updated = False
        if "avatar" in request.FILES:
            path = avatar_file_path(user=request.user, filename=request.FILES["avatar"].name)
            avatar = Avatar(user=request.user, primary=True, avatar=path)
            new_file = avatar.avatar.storage.save(path, request.FILES["avatar"])
            avatar.save()
            updated = True
            # request.user.message_set.create(
            #    message=_("Successfully uploaded a new avatar."))
        if "choice" in request.POST and primary_avatar_form.is_valid():
            avatar = Avatar.objects.get(id=primary_avatar_form.cleaned_data["choice"])
            avatar.primary = True
            avatar.save()
            updated = True
            # request.user.message_set.create(
            #    message=_("Successfully updated your avatar."))
        if updated and notification:
            notification.send([request.user], "avatar_updated", {"user": request.user, "avatar": avatar})
            if friends:
                notification.send(
                    (x["friend"] for x in Friendship.objects.friends_for_user(request.user)),
                    "avatar_friend_updated",
                    {"user": request.user, "avatar": avatar},
                )
        return HttpResponseRedirect(next_override or _get_next(request))
    return render_to_response(
        "avatar/change.html",
        extra_context,
        context_instance=RequestContext(
            request,
            {
                "avatar": avatar,
                "avatars": avatars,
                "primary_avatar_form": primary_avatar_form,
                "next": next_override or _get_next(request),
            },
        ),
    )
开发者ID:danielfranca,项目名称:Tintz,代码行数:50,代码来源:views.py

示例7: change

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import primary [as 别名]
def change(request, extra_context={}, next_override=None):
    avatars = Avatar.objects.filter(user=request.user).order_by('-primary')
    if avatars.count() > 0:
        avatar = avatars[0]
        kwargs = {'initial': {'choice': avatar.id}}
    else:
        avatar = None
        kwargs = {}
    primary_avatar_form = PrimaryAvatarForm(request.POST or None, user=request.user, **kwargs)
    if request.method == "POST":
        if 'avatar' in request.FILES:
            path = avatar_file_path(user=request.user, 
                filename=request.FILES['avatar'].name)
            avatar = Avatar(
                user = request.user,
                primary = True,
                avatar = path,
            )
            new_file = avatar.avatar.storage.save(path, request.FILES['avatar'])
            avatar.save()
            request.user.message_set.create(
                message=_("Successfully uploaded a new avatar."))
        if 'choice' in request.POST and primary_avatar_form.is_valid():
            avatar = Avatar.objects.get(id=
                primary_avatar_form.cleaned_data['choice'])
            avatar.primary = True
            avatar.save()
            request.user.message_set.create(
                message=_("Successfully updated your avatar."))
        return HttpResponseRedirect(next_override or _get_next(request))
    return render_to_response(
        'avatar/change.html',
        extra_context,
        context_instance = RequestContext(
            request,
            { 'avatar': avatar, 
              'avatars': avatars,
              'primary_avatar_form': primary_avatar_form,
              'next': next_override or _get_next(request), }
        )
    )
开发者ID:ericholscher,项目名称:allfeeds,代码行数:43,代码来源:views.py

示例8: change

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import primary [as 别名]
def change(request, extra_context={}, next_override=None):
    avatars = Avatar.objects.filter(user=request.user).order_by('-primary')
    if avatars.count() > 0:
        avatar = avatars[0]
        kwargs = {'initial': {'choice': avatar.id}}
    else:
        avatar = None
        kwargs = {}
    primary_avatar_form = PrimaryAvatarForm(request.POST or None, user=request.user, **kwargs)
    if request.method == "POST":
        if 'avatar' in request.FILES:
            path = avatar_file_path(user=request.user, 
                filename=request.FILES['avatar'].name)
            try:
                os.makedirs(os.path.join(
                    settings.MEDIA_ROOT, "/".join(path.split('/')[:-1])))
            except OSError, e:
                pass # The dirs already exist.
            new_file = default_storage.open(path, 'wb')
            for i, chunk in enumerate(request.FILES['avatar'].chunks()):
                if i * 16 == MAX_MEGABYTES:
                    raise Http404 # TODO: Is this the right thing to do?
                                  # Validation error maybe, instead?
                new_file.write(chunk)
            avatar = Avatar(
                user = request.user,
                primary = True,
                avatar = path,
            )
            avatar.save()
            new_file.close()
            request.user.message_set.create(
                message=_("Successfully uploaded a new avatar."))
        if 'choice' in request.POST and primary_avatar_form.is_valid():
            avatar = Avatar.objects.get(id=
                primary_avatar_form.cleaned_data['choice'])
            avatar.primary = True
            avatar.save()
            request.user.message_set.create(
                message=_("Successfully updated your avatar."))
        return HttpResponseRedirect(next_override or _get_next(request))
开发者ID:ryanmcgreevy,项目名称:Science2.0,代码行数:43,代码来源:views.py

示例9: create_photo

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import primary [as 别名]
def create_photo(request):
    
    error_message=''
    user_name=''
    form=FotosForm(request.POST, request.FILES)
    
    if not form.is_valid():
        context = RequestContext(request, {'form': form, 'mensagem_erro': error_message})
        return render_to_response('cadastro/ppassos/new_photos.html',context)
    
    try:
        user_name=request.user.username
        member=User.objects.get(pk=request.user.id)
        
        if 'foto_perfil' in request.FILES:
            photo_profile=Avatar()
            photo_profile.avatar=request.FILES['foto_perfil']
            photo_profile.user=member
            photo_profile.primary=True
            photo_profile.save()
        
        if 'foto_divulgacao01' in request.FILES:
            photo=Image()
            photo.title=u'Foto de divulgação 01'
            photo.image=request.FILES['foto_divulgacao01']
            photo.member=member
            photo.save()
        
        if 'foto_divulgacao02' in request.FILES:
            photo=Image()
            photo.title=u'Foto de divulgação 02'
            photo.image=request.FILES['foto_divulgacao02']
            photo.member=member
            photo.save()
    except Exception,e:
        error_message=u'<p style="color:#f00 !important;">Desculpe %s, mas houve um erro interno. Por favor entre em contato com [email protected]<br>%s</p>' % (user_name,e)
        context = RequestContext(request, {'form': form, 'mensagem_erro': error_message})
        return render_to_response('cadastro/ppassos/new_photos.html',context)
开发者ID:morenopc,项目名称:music-social-network,代码行数:40,代码来源:views.py

示例10: ContentFile

# 需要导入模块: from avatar.models import Avatar [as 别名]
# 或者: from avatar.models.Avatar import primary [as 别名]
    from django.core.files.base import ContentFile
    contentf = ContentFile(pdata)
    _log.debug("... creating avatar...")
    #contentf.name = 'xf-vcard-auto-avatar'
    autobasename = 'xf-vcard-auto-avatar.%s'
    contentf.name = autobasename % extension
    autoav = Avatar(user=user, avatar=contentf)
    # Check if auto-avatar is already presemt, replace if it is.
    # ! It's user's problem if user uploads an avatar with such a special
    #  name :)
    old_autoav_qs = Avatar.objects.filter(user=user,
      avatar__startswith=avatar_file_path(autoav, autobasename % ''))[:1]
    if old_autoav_qs:  # Already have some. Replace it.
        # ! XXX: non-parallel-safe here.
        old_autoav = old_autoav_qs[0]
        autoav.primary = old_autoav.primary  # XXX: Not very nice.
        old_autoav.delete()
    else:  # save the new one,
        autoav.save()
    _log.debug("... av done.")


def processcmd(indata):
    """ Processes XMPP-originating data such as statuses, text commands,
    etc.  """
    src = indata.get('src')
    srcbarejid = src.split("/")[0]  # Strip the resource if any.
    dst = indata.get('dst')
    body = indata.get('body')
    _log.debug(" -+-+-+-+-+- indata: %r." % indata)
    if 'auth' in indata:  # Got subscribe/auth data. Save it.
开发者ID:HoverHell,项目名称:xmppforum,代码行数:33,代码来源:xmppface.py


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