示例#1
0
def editProfile(request):
    profile = Profile.objects.get(user=request.user)
    if request.method == 'POST':
        form = ProfileForm(request.POST, request.FILES)
        if form.is_valid():
            profile.year = form.cleaned_data.get('year')
            profile.major = form.cleaned_data.get('major')
            profile.gender = form.cleaned_data.get('gender')
            profile.sexualOrientation = form.cleaned_data.get('sexualOrientation')
            profile.bio = form.cleaned_data.get('bio')
            profile.idealDate = form.cleaned_data.get('idealDate')
            profile.kagin = form.cleaned_data.get('kagin')
            profile.cafemac = form.cleaned_data.get('cafemac')
            profile.athletes = form.cleaned_data.get('athletes')
            profile.cold = form.cleaned_data.get('cold')
            profile.lookingFor = form.cleaned_data.get('lookingFor')
            profile.friendLookingFor = form.cleaned_data.get('friendLookingFor')
            profile.politics = form.cleaned_data.get('politics')
            profile.aesthetics = form.cleaned_data.get('aesthetics')
            profile.nap = form.cleaned_data.get('nap')
            profile.saturday = form.cleaned_data.get('saturday')
            profile.appSampler = form.cleaned_data.get('appSampler')
            pic = request.FILES['pic']
            total = idealDate+kagin+cafemac+athletes+cold+lookingFor+friendLookingFor+politics+aesthetics+nap+saturday+appSampler
            profile.score = float(total)/12.0
            profile.save()
            return redirect('home')
    else:
        data = {'year':profile.year,'major':profile.major,'gender':profile.gender,'sexualOrientation':profile.sexualOrientation,'bio':profile.bio,'email':profile.email,'idealDate':profile.idealDate,'kagin':profile.kagin,'cafemac':profile.cafemac,'athletes':profile.athletes,'cold':profile.cold,'lookingFor':profile.lookingFor}
        data1 = {'politics':profile.politics,'aesthetics':profile.aesthetics,'nap':profile.nap,'saturday':profile.saturday,'appSampler':profile.appSampler,'friendLookingFor':profile.friendLookingFor,'pic':profile.pic}
        data.update(data1)
        form = ProfileForm(initial=data)
    return render(request, 'smack/editProfile.html', {'form':form})
示例#2
0
def personalProfile(request):
    print(request.POST)
    currentProfile = request.user
    if request.method == 'POST':
        form = ProfileForm(request.POST, request.FILES)
        if form.is_valid():
            year = form.cleaned_data.get('year')
            major = form.cleaned_data.get('major')
            gender = form.cleaned_data.get('gender')
            sexualOrientation = form.cleaned_data.get('sexualOrientation')
            bio = form.cleaned_data.get('bio')
            idealDate = form.cleaned_data.get('idealDate')
            kagin = form.cleaned_data.get('kagin')
            cafemac = form.cleaned_data.get('cafemac')
            athletes = form.cleaned_data.get('athletes')
            cold = form.cleaned_data.get('cold')
            lookingFor = form.cleaned_data.get('lookingFor')
            friendLookingFor = form.cleaned_data.get('friendLookingFor')
            politics = form.cleaned_data.get('politics')
            aesthetics = form.cleaned_data.get('aesthetics')
            nap = form.cleaned_data.get('nap')
            saturday = form.cleaned_data.get('saturday')
            appSampler = form.cleaned_data.get('appSampler')
            pic = request.FILES['pic']
            total = idealDate+kagin+cafemac+athletes+cold+lookingFor+friendLookingFor+politics+aesthetics+nap+saturday+appSampler
            score = float(total)/12.0
            Profile.objects.create(user=currentProfile,year=year,major=major,gender=gender,sexualOrientation=sexualOrientation,bio=bio,idealDate=idealDate,kagin=kagin,cafemac=cafemac,athletes=athletes,cold=cold,lookingFor=lookingFor,friendLookingFor=friendLookingFor,politics=politics,aesthetics=aesthetics,nap=nap,appSampler=appSampler,saturday=saturday,score=score,pic=pic)
            return redirect('home')
    else:
        form = ProfileForm()
    return render(request, 'smack/personProfile.html',{'form':form})
示例#3
0
 def registerUser(self, request):
     p_key = ndb.Key(UserDetails, request.phoneNumber)
     succ = 1
     user = UserDetails(
         key=p_key,
         displayName=request.displayName,
         mainEmail=request.mainEmail,
         balance=0,
         phoneNumber=request.phoneNumber,
         pin=request.pin,
         uri=request.uri,
     )
     try:
         user.put()
     except datastore_errors.DuplicatePropertyError:
         succ = 0
     prof = ProfileForm()
     if succ == 1:
         prof.displayName = user.displayName
         prof.uri = user.uri
         prof.mainEmail = user.mainEmail
         prof.balance = user.balance
         prof.phoneNumber = user.phoneNumber
     prof.success = succ
     return prof
示例#4
0
def profile():
    form = ProfileForm(request.form)
    profile_settings = Profile.query.get(int(current_user.get_id()))

    if request.method == 'POST' and form.validate():
        profile_settings.fullname = f'{form.firstName.data} {form.surname.data}'
        profile_settings.firstName = form.firstName.data
        profile_settings.surname = form.surname.data
        profile_settings.age = form.age.data
        profile_settings.twitter = form.twitter.data
        profile_settings.instagram = form.instagram.data
        profile_settings.city = form.city.data
        profile_settings.country = form.country.data
        profile_settings.aboutMe = form.aboutMe.data
        profile_settings.profileEdited = True

        db.session.commit()

        return redirect(url_for('profile'))

    if profile_settings.profileEdited:
        form.firstName.default = profile_settings.firstName
        form.surname.default = profile_settings.surname
        form.age.default = profile_settings.age
        form.twitter.default = profile_settings.twitter
        form.instagram.default = profile_settings.instagram
        form.city.default = profile_settings.city
        form.country.default = profile_settings.country
        form.aboutMe.default = profile_settings.aboutMe

        form.process()

        return render_template(
            'profile.html',
            form=form,
            fullname=profile_settings.fullname,
            city=profile_settings.city,
            aboutMe=profile_settings.aboutMe,
            age=profile_settings.age,
            instagram=f'https://www.instagram.com/{profile_settings.instagram}',
            twitter=f'https://www.twitter.com/{profile_settings.twitter}')

    else:
        form.firstName.default = profile_settings.firstName
        form.surname.default = profile_settings.surname
        form.city.default = profile_settings.city
        form.country.default = profile_settings.country
        form.process()

        return render_template(
            'profile.html',
            form=form,
            fullname=profile_settings.fullname,
            city=profile_settings.city,
            aboutMe=profile_settings.aboutMe,
            age=profile_settings.age,
        )
示例#5
0
    def _copyProfileToForm(self, prof):

        pf = ProfileForm()
        for field in pf.all_fields():
            if hasattr(prof, field.name):
                # convert t-shirt string to Enum; just copy others
                if field.name == 'teeShirtSize':
                    setattr(pf, field.name,
                            getattr(TeeShirtSize, getattr(prof, field.name)))
                else:
                    setattr(pf, field.name, getattr(prof, field.name))
        pf.check_initialized()
        return pf
示例#6
0
 def _copyProfileToForm(self, prof):
     """Copy relevant fields from Profile to ProfileForm."""
     pf = ProfileForm()
     # Loop through all fields and copy data to form
     for field in pf.all_fields():
         if hasattr(prof, field.name):
           
             if field.name == 'teeShirtSize':
                 setattr(pf, field.name, getattr(TeeShirtSize, getattr(prof, field.name)))
             else:
                 setattr(pf, field.name, getattr(prof, field.name))
     pf.check_initialized()
     return pf
 def _copyProfileToForm(self, prof):
     """ Copy relevant fields from Profile to ProfileForm. """
     # copy relevant fields from Profile to ProfileForm
     pf = ProfileForm()
     for field in pf.all_fields():
         if hasattr(prof, field.name):
             # convert t-shirt string to Enum; just copy others
             if field.name == "teeShirtSize":
                 setattr(pf, field.name,
                         getattr(TeeShirtSize, getattr(prof, field.name)))
             else:
                 setattr(pf, field.name, getattr(prof, field.name))
     pf.check_initialized()
     return pf
示例#8
0
 def googleLoginUser(self, request):
     qry = UserDetails.GoogleLogin(request.mainEmail, request.uri)
     succ = 1
     user = qry.get()
     prof = ProfileForm()
     if user is None:
         succ = 0
     elif succ == 1:
         prof.displayName = user.displayName
         prof.mainEmail = user.mainEmail
         prof.phoneNumber = user.phoneNumber
         prof.balance = user.balance
         prof.uri = user.uri
     prof.success = succ
     return prof
示例#9
0
 def loginUser(self, request):
     p_key = ndb.Key(UserDetails, request.phoneNumber)
     user = p_key.get()
     succ = 1
     if user is None:
         succ = 0
     elif user.pin != request.pin:
         succ = 2
     prof = ProfileForm()
     if succ == 1:
         prof.displayName = user.displayName
         prof.mainEmail = user.mainEmail
         prof.phoneNumber = user.phoneNumber
         prof.balance = user.balance
         prof.uri = user.uri
     prof.success = succ
     return prof
 def _copyProfileToForm(self, prof):
     """Copy relevant fields from Profile to ProfileForm."""
     # copy relevant fields from Profile to ProfileForm
     pf = ProfileForm()
     for field in pf.all_fields():
         if hasattr(prof, field.name):
             # convert key objects to websafekey, put it back in a list
             if field.name.endswith('Attend'):
                 key_list = [x.urlsafe() for x in getattr(prof, field.name)]
                 setattr(pf, field.name, key_list)
             # convert t-shirt string to Enum;
             elif field.name == 'teeShirtSize':
                 setattr(pf, field.name,
                         getattr(TeeShirtSize, getattr(prof, field.name)))
             # just copy others
             else:
                 setattr(pf, field.name, getattr(prof, field.name))
     pf.check_initialized()
     return pf
示例#11
0
    def _copyProfileToForm(self, prof):
        """Copy relevant fields from Profile to ProfileForm."""
        # copy relevant fields from Profile to ProfileForm
        pf = ProfileForm()

        for field in pf.all_fields():
            if hasattr(prof, field.name):
                # convert t-shirt string to Enum; just copy others
                if field.name == 'teeShirtSize':
                    setattr(pf, field.name,
                            getattr(TeeShirtSize, getattr(prof, field.name)))
                elif field.name == 'conferenceKeysToAttend':
                    setattr(pf, field.name, [conf.urlsafe() for conf \
                        in prof.conferenceKeysToAttend])
                elif field.name == 'sessionKeysToAttend':
                    setattr(pf, field.name, [sess.urlsafe() for sess \
                        in prof.sessionKeysToAttend])
                else:
                    setattr(pf, field.name, getattr(prof, field.name))
        pf.check_initialized()
        return pf
示例#12
0
def profile():
    '''
    Profile
    '''
    form = ProfileForm()
    if request.method == 'POST' and form.validate_on_submit():
        if form.last_name.data:
            current_user.last_name = form.last_name.data
        if form.first_name.data:
            current_user.first_name = form.first_name.data
        if form.phone:
            current_user.phone = form.phone.data
        if form.email:
            current_user.email = form.email.data
        DB.session.commit()
        return redirect(url_for('index'))
    else:
        form.email.data = current_user.email
        form.first_name.data = current_user.first_name
        form.last_name.data = current_user.last_name
        form.phone.data = current_user.phone
    return render_template('profile.html', form=form)
示例#13
0
文件: views.py 项目: deexpabada/sMACk
def personalProfile(request):
    print(request.POST)
    currentProfile = request.user
    if request.method == 'POST':
        form = ProfileForm(request.POST, request.FILES)
        if form.is_valid():
            full_name = form.cleaned_data.get('full_name')
            email = form.cleaned_data.get('email')
            year = form.cleaned_data.get('year')
            major = form.cleaned_data.get('major')
            gender = form.cleaned_data.get('gender')
            sexualOrientation = form.cleaned_data.get('sexualOrientation')
            bio = form.cleaned_data.get('bio')
            idealDate = form.cleaned_data.get('idealDate')
            kagin = form.cleaned_data.get('kagin')
            cafemac = form.cleaned_data.get('cafemac')
            athletes = form.cleaned_data.get('athletes')
            cold = form.cleaned_data.get('cold')
            lookingFor = form.cleaned_data.get('lookingFor')
            friendLookingFor = form.cleaned_data.get('friendLookingFor')
            politics = form.cleaned_data.get('politics')
            aesthetics = form.cleaned_data.get('aesthetics')
            nap = form.cleaned_data.get('nap')
            saturday = form.cleaned_data.get('saturday')
            appSampler = form.cleaned_data.get('appSampler')
            pic = request.FILES['pic']
            total = int(idealDate) + int(kagin) + int(cafemac) + int(
                athletes) + int(cold) + int(lookingFor) + int(
                    friendLookingFor) + int(politics) + int(aesthetics) + int(
                        nap) + int(saturday) + int(appSampler)
            score = int(total) / 12
            Profile.objects.create(full_name=full_name,
                                   email=email,
                                   user=currentProfile,
                                   year=year,
                                   major=major,
                                   gender=gender,
                                   sexualOrientation=sexualOrientation,
                                   bio=bio,
                                   idealDate=idealDate,
                                   kagin=kagin,
                                   cafemac=cafemac,
                                   athletes=athletes,
                                   cold=cold,
                                   lookingFor=lookingFor,
                                   friendLookingFor=friendLookingFor,
                                   politics=politics,
                                   aesthetics=aesthetics,
                                   nap=nap,
                                   appSampler=appSampler,
                                   saturday=saturday,
                                   score=score,
                                   pic=pic)
            if request.user.is_authenticated():
                user = request.user
            profile = Profile.objects.get(user=user)
            profile.dislike.add(profile)
            return redirect('home')
    else:
        form = ProfileForm()
    return render(request, 'smack/personProfile.html', {'form': form})