def __init__(self, request, social_login, new_user, dob, social_id, social_service): """Initializes the profile form object after setting a profile picture, date of birth, and the User object it is associated with. Args: request: The HTTP request object, as passed by django. social_login: Boolean of whether or not social login was used. new_user: User object that was just created. dob: Date of birth date/timestamp. """ # If date of birth has been set, set up the user profile object. if dob: profile_pic = self.default_profile_pic() # If social login has been used, get the profile picture URL from # the Http request. if social_login: profile_pic_url = request.get('profile_pic') if profile_pic_url: profile_pic = self.generate_profile_pic( profile_pic_url, new_user.id) # Make a deep copy of the user request. newRequest = request.copy() newRequest.__setitem__('dob', dob) newRequest.__setitem__('user', new_user.id) newRequest.__setitem__('location', request.get('location').strip()) newRequest.__setitem__('gender', request.get('gender') == '1') newRequest.__setitem__( 'social_id', social_id if social_login else None) newRequest.__setitem__( 'social_service', social_service if social_login else None) newRequest.__setitem__('onboarding', '{"signup": {"status": true, "version": "0.1"}}') newRequest.__setitem__('digests', '{"newsletter": true}') # Set profile picture default position. from media.models import ImagePosition new_user_image_position = ImagePosition(top=50, left=50) new_user_image_position.save() newRequest.__setitem__('profile_pic_position', new_user_image_position.id) self.profile_pic_tmp = profile_pic # Invoke the superclass with this new QueryDict object. super(ModelForm, self).__init__(newRequest)
def __init__(self, request, user): newRequest = request.copy() title = request.get('title') newRequest.__setitem__('admins', user.id) newRequest.__setitem__('description', request.get('short_description')) # Set profile picture default position. from media.models import ImagePosition new_cover_image_position = ImagePosition(top=50, left=50) new_cover_image_position.save() newRequest.__setitem__('cover_pic_position', new_cover_image_position.id) slug = self._get_fresh_slug(title) newRequest.__setitem__('slug', slug) super(ProjectForm, self).__init__(newRequest)