Exemple #1
0
def signup_profile(request):
    current_user = request.user
    if request.method == 'POST':
        form = AccountsModifyProfileForm(request.POST)
        if form.is_valid():
            realname = form.cleaned_data['realname']
            birthday = form.cleaned_data['birthday']
            public_profile = current_user.public_profile
            if request.FILES:
                path = 'img/student/' + str(current_user.url_number)
                if not os.path.exists(MEDIA_ROOT + path):
                    os.makedirs(MEDIA_ROOT + path)

                img = Image.open(request.FILES['face'])
                if img.mode == 'RGB':
                    filename = 'face.jpg'
                    filename_thumbnail = 'thumbnail.jpg'
                elif img.mode == 'P':
                    filename = 'face.png'
                    filename_thumbnail = 'thumbnail.png'
                filepath = '%s/%s' % (path, filename)
                filepath_thumbnail = '%s/%s' % (path, filename_thumbnail)
                # 获得图像的宽度和高度
                width, height = img.size
                # 计算高宽
                ratio = 1.0 * height / width
                # 计算新的高度
                new_height = int(288 * ratio)
                new_size = (288, new_height)
                # 缩放图像
                if new_height >= 288:
                    thumbnail_size = (0, 0, 288, 288)
                else:
                    thumbnail_size = (0, 0, new_height, new_height)

                out = img.resize(new_size, Image.ANTIALIAS)
                thumbnail = out.crop(thumbnail_size)
                thumbnail.save(MEDIA_ROOT + filepath_thumbnail)
                public_profile.thumbnail = MEDIA_URL + filepath_thumbnail

                out.save(MEDIA_ROOT + filepath)
                public_profile.face = MEDIA_URL + filepath

            public_profile.realname = realname
            public_profile.birthday = birthday
            current_user.public_profile = public_profile
            current_user.save()
            return HttpResponseRedirect('/')

    else:
        form = AccountsModifyProfileForm()
        return render_to_response('accounts/modifyprofile.html', {
            'form': form,
            'STATIC_URL': STATIC_URL,
            'current_user': current_user
        },
                                  context_instance=RequestContext(request))
Exemple #2
0
def signup_profile(request):
    current_user = request.user
    if request.method == 'POST':
        form = AccountsModifyProfileForm(request.POST)
        if form.is_valid():
            realname = form.cleaned_data['realname']
            birthday = form.cleaned_data['birthday']
            public_profile = current_user.public_profile
            if request.FILES:
                path = 'img/student/' + str(current_user.url_number)
                if not os.path.exists(MEDIA_ROOT + path):
                    os.makedirs(MEDIA_ROOT + path)
                
                
                img = Image.open(request.FILES['face'])
                if img.mode == 'RGB':
                    filename = 'face.jpg'
                    filename_thumbnail = 'thumbnail.jpg'
                elif img.mode == 'P':
                    filename = 'face.png'
                    filename_thumbnail = 'thumbnail.png'
                filepath = '%s/%s' % (path, filename)
                filepath_thumbnail = '%s/%s' % (path, filename_thumbnail)
                # 获得图像的宽度和高度
                width, height = img.size
                # 计算高宽
                ratio = 1.0 * height / width
                # 计算新的高度
                new_height = int(288 * ratio)
                new_size = (288, new_height)
                # 缩放图像
                if new_height >= 288:
                    thumbnail_size = (0,0,288,288)
                else:
                    thumbnail_size = (0,0,new_height,new_height)
                    
                out = img.resize(new_size, Image.ANTIALIAS)
                thumbnail = out.crop(thumbnail_size)
                thumbnail.save(MEDIA_ROOT + filepath_thumbnail)
                public_profile.thumbnail = MEDIA_URL + filepath_thumbnail
                
                
                out.save(MEDIA_ROOT + filepath)
                public_profile.face = MEDIA_URL + filepath
                
                
            public_profile.realname = realname
            public_profile.birthday = birthday
            current_user.public_profile = public_profile
            current_user.save()
            return HttpResponseRedirect('/')
    
    else:
        form = AccountsModifyProfileForm()
        return render_to_response('accounts/modifyprofile.html', {'form': form, 'STATIC_URL':STATIC_URL, 'current_user':current_user}, context_instance=RequestContext(request))
Exemple #3
0
def profile(request):
    current_user = request.user
    if request.method == 'POST':
        form = AccountsModifyProfileForm(request.POST)
        if form.is_valid():
            realname = form.cleaned_data['realname']
            gender = form.cleaned_data['gender']
            school = form.cleaned_data['school']
            birthday = form.cleaned_data['birthday']
            face = form.cleaned_data['face']
            
            
    else:
        form = AccountsModifyProfileForm()
    return render_to_response('accounts/profile.html', {'form':form, 'STATIC_URL':STATIC_URL}, context_instance=RequestContext(request))
Exemple #4
0
def profile(request):
    current_user = request.user
    if request.method == 'POST':
        form = AccountsModifyProfileForm(request.POST)
        if form.is_valid():
            realname = form.cleaned_data['realname']
            gender = form.cleaned_data['gender']
            school = form.cleaned_data['school']
            birthday = form.cleaned_data['birthday']
            face = form.cleaned_data['face']

    else:
        form = AccountsModifyProfileForm()
    return render_to_response('accounts/profile.html', {
        'form': form,
        'STATIC_URL': STATIC_URL
    },
                              context_instance=RequestContext(request))