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()
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()
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()
def community_advprofile_edit_init_form(sender, instance, signal, *args, **kwargs): user = instance.user try: profile = CommunityUserProfile.objects.get(user=user, ) except CommunityUserProfile.DoesNotExist: profile = CommunityUserProfile(user=user, ) if profile.avatar: instance.fields[ 'community_advprofile_avatar_remove'] = djangoforms.BooleanField( label=_(u'Delete avatar'), required=False) max_width = get_sph_setting('community_avatar_max_width') max_height = get_sph_setting('community_avatar_max_height') instance.fields['community_advprofile_avatar'] = djangoforms.ImageField( label=_(u'Avatar'), help_text=_( u'Avatar with maximum size of %(max_width)sx%(max_height)s' % { 'max_width': max_width, 'max_height': max_height }), required=False, ) instance.clean_community_advprofile_avatar = lambda: clean_community_advprofile_avatar( instance)
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()
def community_advprofile_edit_init_form(sender, instance, signal, *args, **kwargs): user = instance.user try: profile = CommunityUserProfile.objects.get( user = user, ) except CommunityUserProfile.DoesNotExist: profile = CommunityUserProfile( user = user, ) if profile.avatar: instance.fields['community_advprofile_avatar_remove'] = djangoforms.BooleanField( label = _(u'Delete photo'), required = False ) instance.fields['community_advprofile_avatar'] = djangoforms.ImageField( label = _(u'Photo'), required = False, ) instance.clean_community_advprofile_avatar = lambda : clean_community_advprofile_avatar(instance)