예제 #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 __init__(self, *args, **kwargs):
     user_profile_instance = kwargs.pop('user_profile_instance', None)
     self.user_profile_instance = user_profile_instance
     if not user_profile_instance:
         super(ArtistProfileUpdateForm, self).__init__(*args, **kwargs)
     else:
         # Gather initial values based on existing data.
         artist_profile = self.user_profile_instance.artist
         if artist_profile:
             if artist_profile:
                 initial_genres = [
                     g.id for g in artist_profile.genres.all()
                 ]
             else:
                 artist_profile = ArtistProfile()
                 initial_genres = []
         else:
             artist_profile = ArtistProfile()
             initial_genres = []
         try:
             adr = self.user_profile_instance.address
         except Address.DoesNotExist:
             adr = Address()
         # Populate initial values.
         initial = {}
         initial.update(self.user_profile_instance.user.__dict__)
         initial.update(self.user_profile_instance.__dict__)
         initial.update(adr.__dict__)
         initial.update(artist_profile.__dict__)
         initial['genres'] = initial_genres
         if artist_profile.paypal:
             initial.update(artist_profile.paypal.__dict__)
             initial.update(
                 {'paypal_email2': artist_profile.paypal.paypal_email})
         if artist_profile.google:
             initial.update(artist_profile.google.__dict__)
         initial.update(kwargs.pop('initial', {}))
         super(ArtistProfileUpdateForm, self).__init__(initial=initial,
                                                       *args,
                                                       **kwargs)
         if artist_profile.paypal:
             self.fields[
                 'paypal_email'].help_text = _PAYPAL_EMAIL_HELP_WITH_LINKS
         if artist_profile.google:
             self.fields['google_merchant_id'].help_text = get_gco_help()
예제 #5
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
예제 #6
0
파일: forms.py 프로젝트: kabirh/riotvine
    def __init__(self,
                 instance,
                 show_fields=None,
                 optional_fields=None,
                 *args,
                 **kwargs):
        self.instance = instance  # an instance of UserProfile
        if show_fields is None:
            show_fields = [
                'email', 'name', 'phone_number', 'birth_date', 'image'
            ]  # 'phone_number',
        if optional_fields is None:
            optional_fields = [
                'email', 'name', 'phone_number', 'birth_date', 'image'
            ]  # 'phone_number',
        self.show_fields = show_fields
        self.optional_fields = optional_fields
        super(UserProfileForm, self).__init__(*args, **kwargs)

        email = self.instance.user.email.lower()
        is_fb_email = email.endswith('facebook.com')
        default_username = self.instance.user.username

        if is_sso_email(email) or is_fb_email:
            default_email = u''
        else:
            default_email = email

        if self.instance.is_sso:
            default_username = self.instance.sso_username

        if True:  # default_email or is_fb_email:
            self.fields['permission'] = forms.CharField(
                label=_('Who can see my profile'),
                initial=self.instance.permission,
                widget=forms.Select(choices=UserProfile.PERMISSION_CHOICES),
            )
            self.fields['send_reminders'] = forms.BooleanField(
                initial=self.instance.send_reminders,
                label=_(
                    "Email me daily reminders of upcoming events I am in for"),
                required=False)
            self.fields['send_favorites'] = forms.BooleanField(
                initial=self.instance.send_favorites,
                label=
                _("Email me daily reminders of upcoming events my friends are in for"
                  ),
                required=False)

        if 'email' in show_fields:
            self.fields['email'] = forms.EmailField(label=_('Email'),
                                                    initial=default_email,
                                                    required='email'
                                                    not in optional_fields)
            if not self.instance.is_sso and is_fb_email and (
                    self.instance.send_reminders
                    or self.instance.send_favorites):
                self.fields[
                    'email'].help_text = u'''Event reminder emails are being sent to your Facebook account.<br/> 
                                                                       Add a different email address above or leave it empty to continue 
                                                                       using your Facebook account.'''

        if 'name' in show_fields:
            self.fields['username'] = forms.RegexField(
                label=_("Username"),
                max_length=30,
                regex=r'^\w+$',
                initial=default_username,
                error_message=
                _("This value must contain only letters, numbers and underscores."
                  ),
                min_length=4,
                help_text=
                _(u'Between 4 and 30 alphanumeric characters (letters, digits and underscores).'
                  ))

            self.fields['first_name'] = forms.CharField(
                label=_('First name'),
                max_length=30,
                initial=self.instance.user.first_name,
                required='name' not in optional_fields)
            self.fields['last_name'] = forms.CharField(
                label=_('Last name'),
                max_length=30,
                initial=self.instance.user.last_name,
                required='name' not in optional_fields)

        if 'birth_date' in show_fields:
            self.fields['birth_date'] = forms.DateField(
                label=_('Date of birth'),
                input_formats=['%m/%d/%Y'],
                error_messages={
                    'invalid':
                    _('Enter a valid date in this format: MM/DD/YYYY.')
                },
                help_text=_('In the format M/D/YYYY. For example, 8/21/1985.'),
                initial=self.instance.birth_date
                and self.instance.birth_date.strftime('%m/%d/%Y') or None,
                required='birth_date' not in optional_fields)

        if 'phone_number' in show_fields:
            self.fields['phone_number'] = us_forms.USPhoneNumberField(
                label=_('Phone number'),
                initial=self.instance.phone_number,
                help_text=_('In the format: xxx-xxx-xxxx.'),
                required='phone_number' not in optional_fields)

        if 'address' in show_fields:
            try:
                adr = self.instance.address
            except Address.DoesNotExist:
                adr = Address()
            self.fields['address1'] = forms.CharField(label=_('Address 1'),
                                                      initial=adr.address1)
            self.fields['address2'] = forms.CharField(label=_('Address 2'),
                                                      required=False,
                                                      initial=adr.address2)
            self.fields['city'] = forms.CharField(label=_('City'),
                                                  max_length=100,
                                                  initial=adr.city)
            self.fields['state'] = us_forms.USStateField(
                label=_('State'),
                initial=adr.state,
                widget=us_forms.USStateSelect())
            self.fields['postal_code'] = us_forms.USZipCodeField(
                label=_('ZIP code'),
                initial=adr.postal_code,
                help_text=_(
                    'U.S. zip code in the format XXXXX or XXXXX-XXXX.'))
            #self.fields['country'] = forms.CharField(label=_('Country'), max_length=75, initial=adr.country)
            #self.fields['country'].widget.attrs.update({'class':'textInput'})

        if 'image' in show_fields:
            self.fields['image'] = forms.ImageField(label=_("Profile image"),
                                                    required=False,
                                                    help_text=AVATAR_HELP_TEXT)
        if 'name' in show_fields:
            self.fields['has_opted_in'] = forms.BooleanField(
                initial=self.instance.has_opted_in,
                label=_('Receive e-mail with news about %s.' %
                        settings.UI_SETTINGS['UI_SITE_TITLE']),
                required=False)
def register_unapproved_stay(postdata):
    '''
    When a calendar form is submitted, give the resulting request.POST data
    to this function. This function handles stripping the data down and validating/creating
    the resulting objects in the database. If the post data is validated successfully
    and the objects are created, then the returned dictionary will have a key value
    pair of 'success': True. If the validation is not successful or the objects are not
    created, then the returned dictionary will have a key value pair of 'success': False,
    and the errors will be reported in a list key value mapping of 'error_message': ['...', '...', ..]
    containing the list of error messages.
    '''
    name = postdata['name'].strip()
    age = int(postdata['age'].strip())
    phone = postdata['phone_contact_0'] + postdata['phone_contact_1'].strip()
    email = postdata['email_contact'].strip()
    num_guests = int(postdata['number_of_guests'].strip())
    in_date = parser.parse(postdata['in_date'].split('(')[0].strip())
    out_date = parser.parse(postdata['out_date'].split('(')[0].strip())
    additional = postdata['additional_questions_or_concerns']

    street = postdata['street_number'].strip()
    route = postdata['route'].strip()
    city = postdata['city'].strip()
    state = postdata['state'].strip()
    zip_code = postdata['zip_code'].strip()
    country = postdata['country'].strip()

    try:
        new_address = Address(street_number=street,
                              route=route,
                              city=city,
                              state=state,
                              zip_code=zip_code,
                              country=country)
        new_address.save()

        existing_guest = Guest.objects.filter(phone_contact=phone)[0]
        guest = None

        if not existing_guest:
            guest = Guest(name=name,
                          age=age,
                          phone_contact=phone,
                          email_contact=email,
                          address=new_address)
            guest.save()

        else:
            existing_guest.name = name
            existing_guest.age = age
            existing_guest.email_contact = email
            existing_guest.address = new_address
            existing_guest.save()

            guest = existing_guest

        new_stay = Stay(guest=guest,
                        in_date=in_date,
                        out_date=out_date,
                        number_of_guests=num_guests,
                        additional_questions_or_concerns=additional)
        new_stay.full_clean()
        new_stay.save()

        result = {'success': True, 'stay': new_stay}

    except ValidationError as e:
        result = {
            'success': False,
            'error_source':
            'registration.utils.register_unapproved_stay: Validation Failed',
            'error_details': e.message_dict,
        }
    return result
예제 #8
0
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})