예제 #1
0
def profile():
    form = forms.ProfileForm(request.form)
    if request.method == 'POST' and form.validate():
        phone = form.phone_no.data
        address= form.address.data
        blood=form.blood_group.data
        heart=form.heartrate.data
        pressure=form.pressure.data
        algs =form.allergies.data

        # Create cursor
        cur = mysql.connection.cursor()

        # Execute query
        cur.execute("INSERT INTO patients(phoneno, address, blood, heartrate, pressure, allergic, people) VALUES(%s, %s, %s, %s, %s, %s, %s)", (phone, address, blood, heart, pressure, algs, session['username']))

        # Commit to DB
        mysql.connection.commit()

        # Close connection
        cur.close()

        flash('You have successfully completed your profile', 'success')
        return render_template('dashboard.html')
        
    return render_template('addprofile.html',form = form)
예제 #2
0
파일: views.py 프로젝트: morristech/tasket
    def image_upload(self, request, user_id):
        res = HttpResponse()
        if int(user_id) != request.user.pk:
            res.write(json.dumps({'error': "Unauthorized", 'status': 401}))
            res.status_code = 401
            return res

        # Handle image upload
        profile = request.user.profile

        for k, v in profile.as_dict().items():
            if k not in request.POST:
                request.POST[k] = v

        form = forms.ProfileForm(request.POST,
                                 request.FILES,
                                 instance=profile,
                                 request=request)
        if form.is_valid():
            P = form.save()
            res.write(json.dumps({'image': P.image.name}))
            res.status_code = 201
        else:
            res.write(json.dumps({'error': 'Cannot upload image'}))
            res.status_code = 400
        return res
예제 #3
0
def settings_profile_edit():
    if session['login']:
        user = db.member_info(session['user_id'])
        form = forms.ProfileForm(x=user[0][0],
                                 username=user[0][1],
                                 email=user[0][3],
                                 dob=user[0][4],
                                 bio=user[0][5])
        if form.validate_on_submit():
            if (form.username.data
                    in db.username_not_mine_fetch(session['username'])):
                flash("Username is already in use!", "error")
            elif (form.email.data
                  in db.email_not_mine_fetch(session['email'])):
                flash("Email is already in use!", "error")
            else:
                result = db.update_member(session['user_id'],
                                          form.username.data, form.email.data,
                                          form.dob.data, form.bio.data)
                if result:
                    session['username'] = form.username.data
                    session['email'] = form.email.data
                    session['dob'] = form.dob.data
                    flash('Edited', 'success')
                    return redirect(url_for('settings'))
        return render_template('profile_edit.html', form=form)
예제 #4
0
def edit_profile(username):
    '''Edit user profile.'''
    form = forms.ProfileForm()
    user = models.User.get(models.User.username == username)
    profile = models.Profile.get(models.Profile.user == user)

    # Update fields, redirect to view updated profile.
    if current_user == user and form.validate_on_submit():
        if form.about.data:
            profile.about = form.about.data
        if form.twitter.data:
            profile.twitter = form.twitter.data
        if form.facebook.data:
            profile.facebook = form.facebook.data
        if form.instagram.data:
            profile.instagram = form.instagram.data
        profile.save()
        return redirect(url_for('view_profile', username=username))

    # Show edit profile form if authenticated as the correct user.
    if current_user == user:
        return render_template('editprofile.html', form=form)

    # Wrong user tries to access edit page.
    else:
        return "Nice try, but that's not your profile bruh."
예제 #5
0
파일: views.py 프로젝트: sophilabs/pyuy
def profile(request):
    if request.method == 'POST':
        form = forms.ProfileForm(request.POST, instance=request.user)
        if form.is_valid():
            form.instance.username = form.cleaned_data['username']
            form.instance.first_name = form.cleaned_data['first_name']
            form.instance.last_name = form.cleaned_data['last_name']
            form.save()
            messages.add_message(request, messages.SUCCESS,
                                 'Profile updated successfully.')
            return HttpResponseRedirect('')
    else:
        form = forms.ProfileForm(instance=request.user)
    return render_to_response('profile.html', {
        'form': form,
    },
                              context_instance=RequestContext(request))
예제 #6
0
파일: views.py 프로젝트: zalun/pto
def profile(request):
    profile = request.user.get_profile()
    data = {}
    if request.method == 'POST':
        form = forms.ProfileForm(instance=profile, data=request.POST)
        if form.is_valid():
            city = form.cleaned_data['city']
            country = form.cleaned_data['country']
            profile.city = city
            profile.country = country
            profile.save()

            messages.info(request,
              'Profile details saved'
            )
            return redirect('/')
    else:
        form = forms.ProfileForm(instance=profile)

    data['form'] = form
    return render(request, 'users/profile.html', data)
예제 #7
0
파일: views.py 프로젝트: morristech/tasket
    def post(self, request, user_id=None, image=None):
        if image:
            return self.image_upload(request, user_id)
        request.POST = request.JSON
        username = request.JSON.get('username')
        password = request.JSON.get('password')
        password_confirm = request.JSON.get('password_confirm')
        email = request.JSON.get('email')

        form = forms.UserCreationForm({
            'username': username,
            'email': email,
            'password1': password,
            'password2': password_confirm
        })
        if not form.is_valid():
            error_dict = dict(form.errors.items())

            # Rename password fields to better fit in to the front end
            if 'password1' in error_dict:
                error_dict['password'] = error_dict['password1']
                del error_dict['password1']
            if 'password2' in error_dict:
                error_dict['password_confirm'] = error_dict['password2']
                del error_dict['password2']

            self.res.write(json.dumps(error_dict))
            self.res.status_code = 400
            return self.res

        user = form.save()
        if email:
            user.email = email
            user.save()

        user = authenticate(username=username, password=password)

        form = forms.ProfileForm(request.JSON, request=request)
        T = form.save(commit=False)
        T.user = user
        T.save()

        user = authenticate(username=username, password=password)
        login(request, user)

        self.res.write(json.dumps({'id': user.pk}))
        return self.res
예제 #8
0
def edit_profile(netid):
    person = db.session.query(models.People)\
        .filter(models.People.netid == netid).one()
    student = models.Student.get(netid)
    if student:
        faculty = None
    else:
        faculty = models.Faculty.get(netid)
    form = forms.ProfileForm(person, faculty, student)

    if form.validate_on_submit():
        try:
            form.errors.pop('database', None)
            if form.resume.data:
                resume_name = '%s.pdf' % netid
                form.resume.data.save(
                    os.path.join(app.root_path, app.config['RESUME_FOLDER'],
                                 resume_name))
            else:
                resume_name = person.resume
            models.People.edit(netid, form.first_name.data,
                               form.last_name.data, form.email.data,
                               form.website.data, resume_name, person.password)
            models.Member.query.filter_by(netid=netid).delete()
            models.Member.insert(netid, form.department1.data)
            if form.department2.data:
                models.Member.insert(netid, form.department2.data)
            interests = []
            for interest in form.interests.data.split(','):
                interest = interest.strip()
                if interest:
                    interests.append(interest)
            models.Interest.edit(netid, interests)

            if student:
                models.Student.edit(netid, form.status.data,
                                    form.start_year.data)
            elif faculty:
                models.Faculty.edit(netid, form.title.data, form.opening.data)
            return redirect(url_for('profile', netid=netid))
        except BaseException as e:
            form.errors['database'] = str(e)
            return render_template('edit-profile.html', user=person, form=form)
    else:
        return render_template('edit-profile.html', user=person, form=form)
예제 #9
0
def editprofile(id):
    # Create cursor
    cur = mysql.connection.cursor()

    # Get profile by id
    cur.execute("SELECT * FROM patients WHERE id = %s", [id])

    patient = cur.fetchone()
    cur.close()
    # Get form
    form = forms.ProfileForm(request.form)

    # Populate patient form fields
    form.phone_no.data = patient['phoneno']
    form.address.data = patient['address']
    form.blood_group.data =patient['blood']
    form.heartrate.data=patient['heartrate']
    form.pressure.data=patient['pressure']
    form.allergies.data=patient['allergic']

    if request.method == 'POST' and form.validate():
        phone = request.form['phone_no']
        address= request.form['address']
        blood= request.form['blood_group']
        heart= request.form['heartrate']
        pressure= request.form['pressure']
        algs = request.form['allergies']

        # Create Cursor
        cur = mysql.connection.cursor()
        app.logger.info(phone)
        # Execute
        cur.execute ("UPDATE patients SET phoneno=%s, address=%s , blood=%s, heartrate=%s, pressure=%s, allergic=%s, people=%s WHERE id=%s",(phone, address, blood, heart, pressure, algs, session['username'], id))
        # Commit to DB
        mysql.connection.commit()

        #Close connection
        cur.close()

        flash('profile Updated', 'success')

        return redirect(url_for('dashboard'))

    return render_template('editprofile.html', form=form)
예제 #10
0
def edit_profile(request):
    """Edit user profile view."""
    # Don't user request.user
    user = User.objects.get(pk=request.user.id)
    profile = user.get_profile()
    user_groups = stringify_groups(profile.groups.all().order_by('name'))
    user_skills = stringify_groups(profile.skills.all().order_by('name'))
    user_languages = stringify_groups(profile.languages.all().order_by('name'))

    user_form = forms.UserForm(request.POST or None, instance=user)
    profile_form = forms.ProfileForm(request.POST or None,
                                     request.FILES or None,
                                     instance=profile,
                                     initial=dict(groups=user_groups,
                                                  skills=user_skills,
                                                  languages=user_languages),
                                     locale=request.locale)

    if request.method == 'POST':
        if (user_form.is_valid() and profile_form.is_valid()):
            old_username = request.user.username
            user_form.save()
            profile_form.save()

            # Notify the user that their old profile URL won't work.
            if user.username != old_username:
                messages.info(
                    request,
                    _(u'You changed your username; please '
                      'note your profile URL has also '
                      'changed.'))
            return redirect(reverse('profile', args=[user.username]))

    d = dict(profile_form=profile_form,
             user_form=user_form,
             mode='edit',
             user_groups=user_groups,
             my_vouches=UserProfile.objects.filter(vouched_by=profile),
             profile=profile,
             apps=user.apiapp_set.filter(is_active=True))

    # If there are form errors, don't send a 200 OK.
    status = 400 if (profile_form.errors or user_form.errors) else 200
    return render(request, 'phonebook/edit_profile.html', d, status=status)
예제 #11
0
def profile():
    form = forms.ProfileForm()
    if form.validate_on_submit():
        # data_model.Profile.create_user(
        models.update_user(nickName=form.nickName.data,
                           profileStatus=form.status.data,
                           public=form.public.data,
                           campus=form.campus.data,
                           pastCampus=form.pastCampus.data,
                           hometown=form.hometown.data,
                           about=form.about.data,
                           profilePicture=form.profilePicture.data,
                           uploadedPictures=form.uploadedPictures.data,
                           interests=form.interests.data,
                           linkedPages=form.linkedPages.data,
                           campusInvolvement=form.campusInvolvement.data,
                           gender=form.gender.data,
                           phone=form.phone.data)
        return render_template('thankyou_register.html',
                               username=form.username.data)
    return render_template('register.html', form=form)
예제 #12
0
파일: views.py 프로젝트: morristech/tasket
    def put(self, request, user_id=None):
        profile = request.user.profile
        if request.user.profile.pk != int(user_id):
            self.res.write(json.dumps({
                'error': "Unauthorized",
                'status': 401
            }))

            self.res.status_code = 401
            return self.res

        form = forms.ProfileForm(request.PUT,
                                 instance=profile,
                                 request=request)
        if form.is_valid():
            T = form.save(commit=False)
            T.user = profile.user

            if request.PUT.get('email'):
                T.user.email = request.PUT.get('email', T.user.email)

            if request.PUT.get('password'):
                T.user.set_password(request.PUT['password'])

            T.user.save()
            T.save()
            self.res.write(T.as_json(request_user=request.user))
        else:
            self.res.write(json.dumps(form.errors))
            self.res.status_code = 500
        return self.res

        def invalid(self, *args):
            self.res.write(json.dumps({
                'errors': args,
            }))
            return self.res
예제 #13
0
def x_profile(request):

	profile = models.Profile.objects.get(user=request.user)

	if profile.email_code != '':
		return HttpResponseRedirect(reverse('thankyou'))

	plans = models.UserPlan.objects.all().order_by('fee')
	user = request.user
	form = forms.ProfileForm(initial={
		'username': user.username, 
		'email': user.email, 
		'first_name': user.first_name, 
		'last_name': user.last_name
		})

	password_form = forms.PasswordResetForm()

	error = ''
	msg = ''
	msg_type = ''

	if request.method == 'POST':

		if request.POST.get('resetpassword'):
			old_pw = request.POST.get('old_password')
			new_pw = request.POST.get('password')
			user = authenticate(request, username=user.username, password=old_pw)
			if user is None:
				error = 'Password Incorrect'
				msg = 'Password Incorrect'
				msg_type = 'danger'
			else:
				user.set_password(new_pw)
				user.save()
				msg_type = 'success'
				msg = 'Password Changed.'
		else:
			username = request.POST.get('username')
			email = request.POST.get('email')
			firstname = request.POST.get('first_name')
			lastname = request.POST.get('last_name')

			user.username = username
			user.email = email
			user.first_name = firstname
			user.last_name = lastname
			user.save()
			msg_type = 'success'
			msg = 'Saved Successfully'
		login(request, user)

	return render(request, 'profile.html', {
		'msg': msg, 
		'msg_type': msg_type, 
		'user': request.user, 
		'form': form, 
		'plans': plans, 
		'current_plan': profile.plan, 
		'password_form': password_form, 
		'error': error
		})
예제 #14
0
def my_profile():
    user = current_user
    form = forms.ProfileForm()
    return render_template('my-profile.html', form=form)