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
def edit_address(request): page_name = 'editar perfil' form = AddressForm(request.POST or None) success_message = False user = request.user address = Address.objects.filter(user=user).first() if address != None: form.fields['zip_code'].initial = address.zip_code form.fields['street'].initial = address.street form.fields['number'].initial = address.number form.fields['complement'].initial = address.complement form.fields['district'].initial = address.district form.fields['city'].initial = address.city form.fields['state'].initial = address.state if request.method == 'POST' and form.is_valid(): if address is None: address = Address() address.zip_code = form.cleaned_data['zip_code'] address.street = form.cleaned_data['street'] address.number = form.cleaned_data['number'] address.complement = form.cleaned_data['complement'] address.district = form.cleaned_data['district'] address.city = form.cleaned_data['city'] address.state = form.cleaned_data['state'] address.user = user address.save() success_message = True return render(request, 'edit-address.html', {'form': form, 'page_name': page_name, 'success_message':success_message})
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
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
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