Example #1
0
    def signup(self, request, user):
        user.first_name = self.cleaned_data['first_name']
        user.last_name = self.cleaned_data['last_name']
        profile = UserProfile()
        profile.address = self.cleaned_data['address']
        profile.address_2 = self.cleaned_data['address_2']
        profile.contact = self.cleaned_data['contact']
        profile.zipcode = self.cleaned_data['zipcode']
        profile.city = self.cleaned_data['city']
        profile.country = self.cleaned_data['country']
        user.save()

        profile.user = user
        profile.save()
        
        group_customer = Group.objects.get(name='customer')
        group_customer.user_set.add(user)

        
Example #2
0
    def save(self, request):
        if self.cleaned_data['city'] or self.cleaned_data[
                'website'] or self.cleaned_data['intro'] or self.cleaned_data[
                    'qq'] or self.cleaned_data['msn'] or self.cleaned_data[
                        'avatar']:

            current_user = request.user

            try:
                profile = current_user.get_profile()
            except UserProfile.DoesNotExist:
                profile = None

            if not profile:
                profile = UserProfile()
                profile.user = current_user
                profile.song_ord_filed = 'post_datetime'

            profile.city = self.cleaned_data['city']
            profile.website = self.cleaned_data['website']
            profile.intro = self.cleaned_data['intro']
            profile.qq = self.cleaned_data['qq']
            profile.msn = self.cleaned_data['msn']
            if 'avatar' in request.FILES:

                #删除掉原头像
                import os
                if profile and profile.avatar and os.path.exists(
                        profile.avatar.path):
                    os.remove(profile.avatar.path)

                profile.avatar = self.cleaned_data[
                    'avatar']  #request.FILES["avatar"]
            profile.save()

            if self.cleaned_data['username'] != current_user.username:
                current_user.username = self.cleaned_data['username']
                current_user.save()