示例#1
0
文件: forms.py 项目: kabirh/riotvine
 def save_artist_profile(self, profile, commit=True):
     """`profile` is an instance of UserProfile"""
     user = profile.user
     profile.is_artist = True
     profile.phone_number = self.cleaned_data['phone_number']
     if 'has_opted_in' in self.fields:
         profile.has_opted_in = self.cleaned_data.get('has_opted_in', False)
     if commit:
         profile.save()
     user.first_name = self.cleaned_data['first_name']
     user.last_name = self.cleaned_data['last_name']
     if commit:
         user.save()
     adr1 = self.cleaned_data.get('address1', '')
     city = self.cleaned_data.get('city', '')
     state = self.cleaned_data.get('state', '')
     postal_code = self.cleaned_data.get('postal_code', '')
     if adr1 and city and state and postal_code:
         adr = Address(user_profile=profile)
         adr.address1 = adr1
         adr.address2 = self.cleaned_data.get('address2', '')
         adr.city = city
         adr.state = state
         adr.postal_code = postal_code
         if commit:
             adr.save()
     artist_profile = ArtistProfile(user_profile=profile)
     artist_profile.name = self.cleaned_data['name']
     artist_profile.num_members = self.cleaned_data.get('num_members', 2)
     artist_profile.url = self.cleaned_data['url']
     artist_profile.website = self.cleaned_data.get('website', None)
     if commit:
         artist_profile.save()
         artist_profile.genres = list(Genre.objects.filter(id__in=self.cleaned_data['genres']))
     return artist_profile
示例#2
0
文件: forms.py 项目: kabirh/riotvine
 def save(self, commit=True):
     show_fields = self.show_fields
     if self.instance.is_sso:
         self.instance.send_reminders = False
         self.instance.send_favorites = False
     else:
         self.instance.send_reminders = self.cleaned_data.get(
             'send_reminders', False)
         self.instance.send_favorites = self.cleaned_data.get(
             'send_favorites', False)
     user_dirty = False
     if 'email' in show_fields:
         email = self.cleaned_data.get('email', '').lower()
         if email:
             self.instance.user.email = email
             self.instance.is_sso = False
             user_dirty = True
     if 'name' in show_fields:
         self.instance.user.username = self.cleaned_data['username']
         self.instance.user.first_name = self.cleaned_data['first_name']
         self.instance.user.last_name = self.cleaned_data['last_name']
         if self.cleaned_data.get('has_opted_in', None) is not None:
             self.instance.has_opted_in = self.cleaned_data.get(
                 'has_opted_in', False)
         self.instance.permission = self.cleaned_data['permission']
         user_dirty = True
     if user_dirty and commit:
         self.instance.user.save()
     if 'birth_date' in show_fields:
         self.instance.birth_date = self.cleaned_data['birth_date']
     if 'phone_number' in show_fields:
         self.instance.phone_number = self.cleaned_data['phone_number']
     if 'image' in show_fields:
         avatar_img = self.cleaned_data.get('image', None)
         if avatar_img:
             avatar_img_field = self.instance._meta.get_field(
                 'avatar_image')
             avatar_img_field.save_form_data(self.instance, avatar_img)
     if commit:
         self.instance.save()
         if 'image' in show_fields:
             self.instance._create_resized_images(raw_field=None, save=True)
     if 'address' in show_fields:
         adr = Address(user_profile=self.instance)
         adr.address1 = self.cleaned_data['address1']
         adr.address2 = self.cleaned_data.get('address2', '')
         adr.city = self.cleaned_data['city']
         adr.state = self.cleaned_data['state']
         adr.postal_code = self.cleaned_data['postal_code']
         #adr.country = self.cleaned_data['country']
         if commit:
             adr.save()
     return self.instance
示例#3
0
文件: forms.py 项目: kabirh/riotvine
 def save(self, commit=True):
     show_fields = self.show_fields
     if self.instance.is_sso:
         self.instance.send_reminders = False
         self.instance.send_favorites = False
     else:
         self.instance.send_reminders = self.cleaned_data.get('send_reminders', False)
         self.instance.send_favorites = self.cleaned_data.get('send_favorites', False)
     user_dirty = False
     if 'email' in show_fields:
         email = self.cleaned_data.get('email', '').lower()
         if email:
             self.instance.user.email = email
             self.instance.is_sso = False
             user_dirty = True
     if 'name' in show_fields:
         self.instance.user.username = self.cleaned_data['username']
         self.instance.user.first_name = self.cleaned_data['first_name']
         self.instance.user.last_name = self.cleaned_data['last_name']
         if self.cleaned_data.get('has_opted_in', None) is not None:
             self.instance.has_opted_in = self.cleaned_data.get('has_opted_in', False)
         self.instance.permission = self.cleaned_data['permission']
         user_dirty = True
     if user_dirty and commit:
         self.instance.user.save()
     if 'birth_date' in show_fields:
         self.instance.birth_date = self.cleaned_data['birth_date']
     if 'phone_number' in show_fields:
         self.instance.phone_number = self.cleaned_data['phone_number']
     if 'image' in show_fields:
         avatar_img = self.cleaned_data.get('image', None)
         if avatar_img:
             avatar_img_field = self.instance._meta.get_field('avatar_image')
             avatar_img_field.save_form_data(self.instance, avatar_img)
     if commit:
         self.instance.save()
         if 'image' in show_fields:
             self.instance._create_resized_images(raw_field=None, save=True)
     if 'address' in show_fields:
         adr = Address(user_profile=self.instance)
         adr.address1 = self.cleaned_data['address1']
         adr.address2 = self.cleaned_data.get('address2', '')
         adr.city = self.cleaned_data['city']
         adr.state = self.cleaned_data['state']
         adr.postal_code = self.cleaned_data['postal_code']
         #adr.country = self.cleaned_data['country']
         if commit:
             adr.save()
     return self.instance
示例#4
0
文件: forms.py 项目: kabirh/riotvine
 def save_artist_profile(self, profile, commit=True):
     """`profile` is an instance of UserProfile"""
     user = profile.user
     profile.is_artist = True
     profile.phone_number = self.cleaned_data['phone_number']
     if 'has_opted_in' in self.fields:
         profile.has_opted_in = self.cleaned_data.get('has_opted_in', False)
     if commit:
         profile.save()
     user.first_name = self.cleaned_data['first_name']
     user.last_name = self.cleaned_data['last_name']
     if commit:
         user.save()
     adr1 = self.cleaned_data.get('address1', '')
     city = self.cleaned_data.get('city', '')
     state = self.cleaned_data.get('state', '')
     postal_code = self.cleaned_data.get('postal_code', '')
     if adr1 and city and state and postal_code:
         adr = Address(user_profile=profile)
         adr.address1 = adr1
         adr.address2 = self.cleaned_data.get('address2', '')
         adr.city = city
         adr.state = state
         adr.postal_code = postal_code
         if commit:
             adr.save()
     artist_profile = ArtistProfile(user_profile=profile)
     artist_profile.name = self.cleaned_data['name']
     artist_profile.num_members = self.cleaned_data.get('num_members', 2)
     artist_profile.url = self.cleaned_data['url']
     artist_profile.website = self.cleaned_data.get('website', None)
     if commit:
         artist_profile.save()
         artist_profile.genres = list(
             Genre.objects.filter(id__in=self.cleaned_data['genres']))
     return artist_profile