Exemplo n.º 1
0
def community_advprofile_edit_save_form(sender, instance, signal, request, **kwargs):
    data = instance.cleaned_data
    user = instance.user
    try:
        profile = CommunityUserProfile.objects.get( user = user, )
    except CommunityUserProfile.DoesNotExist:
        profile = CommunityUserProfile( user = user, )

    if profile.avatar and data['community_advprofile_avatar_remove']:
        # TODO: delete avatar file from disk.
        profile.avatar = None

    if data['community_advprofile_avatar']:
        f = getattr(data['community_advprofile_avatar'], 'tmpfile', None)
        if f is None:
            f = data['community_advprofile_avatar']

        #try to avoid limit of 100 characters to filename
        fname = data['community_advprofile_avatar'].name
        avt_name = force_unicode(fname)
        directory_name_len = len(force_unicode(profile.avatar.field.get_directory_name()))

        if len(avt_name) + directory_name_len > 100:
            name, ext = avt_name.split('.', 1)
            name = name[:96 - len(ext) - directory_name_len]  # 96 because django will append _x if filename already exists, and one for dot
            fname = '%s.%s' % (name, ext)

        profile.avatar.save( fname, f )
    #profile.avat = data['public_emailaddress']
    profile.save()
Exemplo n.º 2
0
def community_advprofile_edit_save_form(sender, instance, signal, request,
                                        **kwargs):
    data = instance.cleaned_data
    user = instance.user
    try:
        profile = CommunityUserProfile.objects.get(user=user, )
    except CommunityUserProfile.DoesNotExist:
        profile = CommunityUserProfile(user=user, )

    if profile.avatar and data['community_advprofile_avatar_remove']:
        # TODO: delete avatar file from disk.
        profile.avatar = None

    if data['community_advprofile_avatar']:
        f = getattr(data['community_advprofile_avatar'], 'tmpfile', None)
        if f is None:
            f = data['community_advprofile_avatar']

        # try to avoid limit of 100 characters to filename
        fname = data['community_advprofile_avatar'].name
        avt_name = fname
        directory_name_len = len(profile.avatar.field.get_directory_name())

        if len(avt_name) + directory_name_len > 100:
            name, ext = avt_name.split('.', 1)
            name = name[:96 - len(
                ext
            ) - directory_name_len]  # 96 because django will append _x if filename already exists, and one for dot
            fname = '%s.%s' % (name, ext)

        profile.avatar.save(fname, f)
    # profile.avat = data['public_emailaddress']
    profile.save()
Exemplo n.º 3
0
def community_advprofile_edit_save_form(sender, instance, signal, request, **kwargs):
    data = instance.cleaned_data
    user = instance.user
    try:
        profile = CommunityUserProfile.objects.get(user=user)
    except CommunityUserProfile.DoesNotExist:
        profile = CommunityUserProfile(user=user)

    if profile.avatar and data["community_advprofile_avatar_remove"]:
        # TODO: delete avatar file from disk.
        profile.avatar = None

    if data["community_advprofile_avatar"]:
        profile.avatar.save(data["community_advprofile_avatar"].name, data["community_advprofile_avatar"])
    # profile.avat = data['public_emailaddress']
    profile.save()
Exemplo n.º 4
0
def community_advprofile_edit_save_form(sender, instance, signal, request, **kwargs):
    data = instance.cleaned_data
    user = instance.user
    try:
        profile = CommunityUserProfile.objects.get( user = user, )
    except CommunityUserProfile.DoesNotExist:
        profile = CommunityUserProfile( user = user, )

    if profile.avatar and data['community_advprofile_avatar_remove']:
        # TODO: delete avatar file from disk.
        profile.avatar = None

    if data['community_advprofile_avatar']:
	#if data['community_advprofile_avatar'].size >=8117:
	#	pass
	#	return 
	#else:
	profile.avatar.save( data['community_advprofile_avatar'].name, data['community_advprofile_avatar'] )
    #profile.avat = data['public_emailaddress']
    profile.save()