Example #1
0
def edit_profile(username):
    form = UpdateForm()
    user = User.query.filter_by(username=username).first_or_404()
    # if validate_on_submit() returns True, the data is copying from the form into the user object
    # and then it is writing the object to the database
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            user.image_file = picture_file
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        current_user.email = form.email.data
        db.session.commit()
        flash(_l('Your account has been updated!'), 'success')
        return redirect(
            url_for('user',
                    username=form.username.data,
                    email=form.email.data,
                    about_me=form.about_me.data))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.about_me.data = current_user.about_me
    image_file = url_for('static', filename='profile_pics/' + user.image_file)
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form,
                           image_file=image_file)
Example #2
0
def account():
    form = UpdateForm()

    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.imgae_file = picture_file

        current_user.username = form.username.data
        current_user.emal = form.email.data
        db.session.commit()

        flash('Account Submited!', 'success')

        return redirect(url_for('account'))

    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email

    image_file = url_for('static', filename='profilepics/anonymous.jpeg')

    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
def update():
    '''
    Update the serial port.
    '''
    uform = UpdateForm()
    global ssProto

    if uform.validate_on_submit():
        n_port =  uform.serial_port.data;
        try:

            ssProto.open_serial(n_port, 9600, timeout = 1)
            ssProto.start()
            if ssProto.is_open():
                app.config['SERIAL_PORT'] = n_port;
                flash('We set the serial port to {}'.format(app.config['SERIAL_PORT']))
                return redirect(url_for('index'))
            else:
                 flash('Update of the serial port went wrong', 'error')
                 return redirect(url_for('config'))
        except Exception as e:
             flash('{}'.format(e), 'error')
             return redirect(url_for('config'))
    else:
        flash('Update of the serial port went wrong', 'error')
        return redirect(url_for('config'))
Example #4
0
def update():
    '''
    Update the serial port.
    '''
    global arduinos
    if not arduinos:
        flash('No arduino yet.', 'error')
        return redirect(url_for('add_arduino'))

    sform = UpdateSetpointForm()
    uform = UpdateForm()
    wform = SerialWaitForm()
    dform = DisconnectForm()
    cform = ReConnectForm()
    gform = UpdateGainForm()
    iform = UpdateIntegralForm()
    diff_form = UpdateDifferentialForm()

    id = int(uform.id.data)
    arduino = arduinos[id]

    if uform.validate_on_submit():

        arduino = arduinos[int(id)]
        n_port = uform.serial_port.data
        try:
            if arduino.is_open():
                arduino.stop()
            arduino.open_serial(n_port, 115200, timeout=1)
            if arduino.is_open():
                flash('We updated the serial to {}'.format(n_port))
            else:
                flash('Update of the serial port went wrong.', 'error')
        except Exception as e:
            flash('{}'.format(e), 'error')
        return redirect(url_for('change_arduino', ard_nr=id))
    else:
        props = {
            'name': arduino.name,
            'id': int(ard_nr),
            'port': arduino.serial.port,
            'active': arduino.is_open(),
            'setpoint': arduino.setpoint,
            'gain': arduino.gain,
            'tauI': arduino.integral,
            'tauD': arduino.diff
        }

        return render_template('change_arduino.html',
                               form=uform,
                               dform=dform,
                               cform=cform,
                               sform=sform,
                               gform=gform,
                               iform=iform,
                               diff_form=diff_form,
                               wform=wform,
                               props=props)
Example #5
0
def user(username):
    form = UpdateForm()
    user = User.query.filter_by(username=username).first_or_404()
    # update users account
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            user.image_file = picture_file
        user.username = form.username.data
        user.email = form.email.data
        db.session.commit()
        flash(_l('Your account has been updated!'), 'success')
        return redirect(
            url_for('user', username=form.username.data,
                    email=form.email.data))
    elif request.method == 'GET':
        form.username.data = user.username
        form.email.data = user.email
    image_file = url_for('static', filename='profile_pics/' + user.image_file)
    page_posts = request.args.get('page_posts', 1, type=int)
    page_visits = request.args.get('page_visits', 1, type=int)
    posts = user.posts.order_by(Post.timestamp.desc()).paginate(
        page_posts, app.config['POSTS_PER_PAGE_USER'], False)
    visits = user.visits.order_by(Visit.timestamp.desc()).paginate(
        page_visits, app.config['VISITS_PER_PAGE_USER'], False)
    next_url_post = url_for(
        'user',
        username=user.username,
        page_posts=posts.next_num,
        page_visits=page_visits) if posts.has_next else None
    prev_url_post = url_for(
        'user',
        username=user.username,
        page_posts=posts.prev_num,
        page_visits=page_visits) if posts.has_prev else None

    next_url_visit = url_for(
        'user',
        username=user.username,
        page_visits=visits.next_num,
        page_posts=page_posts) if visits.has_next else None
    prev_url_visit = url_for(
        'user',
        username=user.username,
        page_visits=visits.next_num,
        page_posts=page_posts) if visits.has_prev else None
    return render_template('user.html',
                           user=user,
                           image_file=image_file,
                           form=form,
                           posts=posts.items,
                           visits=visits.items,
                           next_url_post=next_url_post,
                           prev_url_post=prev_url_post,
                           next_url_visit=next_url_visit,
                           prev_url_visit=prev_url_visit)
Example #6
0
def update(id):
    form = UpdateForm()
    post = Post.query.filter_by(id=id).first()
    if form.validate_on_submit():
        post.title = form.title.data
        post.body = form.body.data
        db.session.add(post)
        db.session.commit()
        return redirect('index')
    return render_template('update.html', title='编辑', form=form)
Example #7
0
def edit_ticket(ticket_id):
    ticket = current_user.get_specific_ticket(ticket_id) # should check if they have the credentials to view that ticket
    form = UpdateForm(tag=ticket.tag, priority=ticket.priority)
    if form.validate_on_submit():
        ticket.priority = form.priority.data
        ticket.tag = form.tag.data
        db.session.commit()
        flash('Ticket Updated')
        return redirect(url_for('index'))
    return render_template('edit_ticket.html', title='Home', ticket = ticket, form=form)
Example #8
0
def update_user():
    '''
    Updates user information
    '''
    userId = current_user.id
    currentUser = User.query.get(userId)

    if "image" not in request.files:
       url = currentUser.image_url
    else:

        image = request.files["image"]

        if not allowed_file(image.filename):
            return {"errors": "file type not permitted"}, 400

        image.filename = get_unique_filename(image.filename)

        upload = upload_file_to_s3(image)

        if "url" not in upload:
            # if the dictionary doesn't have a url key
            # it means that there was an error when we tried to upload
            # so we send back that error message
            return upload, 400

        url = upload["url"]


    form = UpdateForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        newFirstname = request.form['first_name'];
        newLastname = request.form['last_name'];
        newZipcode = request.form['zipcode'];
        newPassword = request.form['password'];
        newImage = url



        if newFirstname:
            currentUser.first_name = newFirstname
        if newLastname:
            currentUser.last_name = newLastname
        if newZipcode:
            currentUser.zipcode = newZipcode
        if newPassword:
            currentUser.password = newPassword
        if newImage:
            currentUser.image_url = newImage

        db.session.commit()
        return currentUser.to_dict()
    return {'errors': validation_errors_to_error_messages(form.errors)}
Example #9
0
def updateFriend():
	form = UpdateForm();
	friend = Friends.query.get(form.hidden.data)
	if form.validate_on_submit():
		form.hidden.data = friend.id
		friend.name = form.name.data
		friend.address = form.address.data
		friend.age = form.age.data
		db.session.commit()
		return redirect('/data')
	else:
		flash('Fill up all the asked infromation!')
		return render_template('update.html',form=form)
Example #10
0
def update():
    form = UpdateForm()
    data = form.data
    print(data)
    if form.validate_on_submit():
        del data['csrf_token']
        data['date_of_birth'] = str(data['date_of_birth'])
        id_ = data.pop('id')
        redis.update_men([id_], [data])
        return redirect(
            url_for('.index', message='Пользователь успешно обновлён'))
    else:
        flash('Введены некорректные данные')
    return render_template('update_form.html', form=form)
Example #11
0
def update(id):
    form = UpdateForm()
    tweet = Tweet.query.get_or_404(id)

    if request.method == 'GET':
        form.tweet.data = tweet.tweet

    if request.method == 'POST':
        if form.validate_on_submit():
            tweet.tweet = form.tweet.data
            tweet.timestamp = datetime.utcnow()
            db.session.commit()
            flash('Your tweet was updated.', category='success')
            return redirect(url_for('index'))

    return render_template('update.html', form=form, id=tweet.id)
Example #12
0
def update_user():
    '''  
        This function updates the user details
            * If the user updates with a new email address, it is validated with the user DB to 
                see it is already taken by some previous users
            * Else:
                * If the email address remains the same -> No change
                * If first name, last name or email changes -> value gets updated
   '''
    global USER_DB
    form = UpdateForm()
    form.first_name.data = request.args.get('first_name')
    form.last_name.data = request.args.get('last_name')
    form.email.data = request.args.get('email')
    old_email_data = request.args.get('email')

    if form.validate_on_submit():
        if request.form["email"] == old_email_data:
            USER_DB[request.form["email"]] = {
                'first_name': request.form["first_name"],
                'last_name': request.form["last_name"]
            }
            return redirect(
                url_for('home',
                        message='updated',
                        name=request.form["first_name"]))
        elif request.form["email"] in USER_DB.keys():
            flash(f'User with this email address already exists!')
        else:
            if (re.search(email_validation_regex, request.form["email"])):
                USER_DB[request.form["email"]] = {
                    'first_name': request.form["first_name"],
                    'last_name': request.form["last_name"]
                }
                del USER_DB[old_email_data]
                return redirect(
                    url_for('home',
                            message='updated',
                            name=request.form["first_name"]))
            else:
                flash(f'Email address is invalid!')
    return render_template('update_user.html',
                           title='Update User Details',
                           data=[
                               form, form.first_name.data, form.last_name.data,
                               form.email.data
                           ])
Example #13
0
def update_book(user_book_id):
    form = UpdateForm()
    if form.validate_on_submit():
        book = User_books.query.filter_by(user_book_id=user_book_id).first()
        book.data_readed = form.data_readed.data
        if form.rating.data:
            book.rating = form.rating.data

        if form.rewiew.data:
            book.rewiew = form.rewiew.data


        db.session.commit()

        return redirect(url_for('book', user_book_id=book.user_book_id))

    return render_template('update_book.html', form=form, user_book_id=user_book_id) 
def user_page_update_info():
    if current_user.admin == 0:
        form = UpdateForm()
        if form.validate_on_submit():
            current_user.E_Name = form.fullname.data
            current_user.email = form.email.data
            db.session.commit()
            return redirect(url_for('user_page_info'))
        elif request.method == 'GET':
            form.email.data = current_user.email
            form.fullname.data = current_user.E_Name
        return render_template('user_page_update_info.html',
                               logo=logo,
                               form=form)
    else:
        logout_user()
        return redirect(url_for('login'))
Example #15
0
def event_mod(event_id):
    event = Event.query.filter(Event.id==event_id).first()
    locations = Location.query.all()
    form = UpdateForm()
    form.capacity.data = event.capacity

    form.org_cap.data = event.max_capacity
    form.org_name.data = event.name
    form.org_start_date.data = event.start
    form.org_end_date.data = event.end
    
    if form.validate_on_submit():
        if form.name.data is not "":
            event.name = form.name.data
            flash("Event name changed from {} to {}.".format(form.org_name.data, form.name.data))
        
        if form.max_cap.data is not None:
            event.max_capacity = form.max_cap.data
            difference = form.max_cap.data - form.org_cap.data
            event.capacity = event.capacity + difference
            flash("Max capacity for {} modified from {} to {}.".format(event.name, form.org_cap.data, form.max_cap.data), "info")

        if form.start_date.data is not None:
            event.start = form.start_date.data
            flash("Event {} start date modified from {} to {}.".format(event.name, form.org_start_date.data, form.start_date.data), "info")

        if form.end_date.data is not None:
            event.end = form.end_date.data
            flash("Event {} end date modified from {} to {}.".format(event.name, form.org_end_date.data, form.end_date.data), "info")

        if form.img_name.data is not None and event.img_name is not form.img_name.data:  
            file = form.img_name.data

            if file and allowed_file(file.filename):
                filename = secure_filename(file.filename);
                file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
                event.img_name = form.img_name.data.filename

        if form.description.data is not None and form.description.data is not "":
            event.description = form.description.data

        db.session.commit()
        app.logger.info('Event ID {} modified by Admin ID {} at {}'.format(event_id, current_user.id, datetime.now()))
        return redirect(url_for('admin_panel.event_modify'))
    
    return render_template('event_modify_id.html', form=form, event=event, locations=locations) if validation(current_user)==True else redirect(url_for('main_panel.index'))
Example #16
0
def account():
    form = UpdateForm()
    if form.validate_on_submit():
        current_user.email = form.email.data
        current_user.name = form.name.data
        current_user.phoneNo = form.phoneNo.data
        current_user.nokName = form.nokName.data
        current_user.nokNumber = form.nokNumber.data
        current_user.stripNo = form.stripNo.data
        db.session.commit()
        flash('Account has been updated', 'success')
        return redirect(url_for('account'))
    elif request.method == 'GET':
        form.name.data = current_user.name
        form.email.data = current_user.email
        form.phoneNo.data = current_user.phoneNo
        form.nokName.data = current_user.nokName
        form.nokNumber.data = current_user.nokNumber
        form.stripNo.data = current_user.stripNo
    return render_template('account.html', title='My account', form=form), 200
Example #17
0
def update():
    form = UpdateForm()
    if form.validate_on_submit():
        employee = db.session.query(Employee).filter_by(
            id=form.id.data).first()
        if form.name.data:
            employee.name = form.name.data
        if form.hourly_pay.data:
            employee.hourly_pay = form.hourly_pay.data
        if form.hours_worked.data:
            employee.hours_worked = form.hours_worked.data
        if form.allowance.data:
            employee.allowance = form.allowance.data
        if form.deduction.data:
            employee.deduction = form.deduction.data
        employee.payroll = employee.hourly_pay * employee.hours_worked + employee.allowance - employee.deduction
        db.session.commit()
        flash('Congratulations, you updated an employee!')
        return redirect(url_for('index'))
    return render_template('update.html', title='Update', form=form)
Example #18
0
def update():
    '''
    Update the watched folder.
    '''
    global arduinos
    if not arduinos:
        flash('No camera yet.', 'error')
        return redirect(url_for('add_camera'))

    uform = UpdateForm()
    roi_form = RoiForm()

    id = int(uform.id.data)
    camera = arduinos[id]

    if uform.validate_on_submit():

        camera = arduinos[int(id)]
        n_folder = uform.folder.data
        if os.path.isdir(n_folder):
            camera.folder = n_folder
            flash('Updated the folder to {}'.format(n_folder))
        else:
            flash('Folder does not exist', 'error')
        return redirect(url_for('change_arduino', ard_nr=id))
    else:
        props = {
            'name': camera.name,
            'id': int(ard_nr),
            'folder': camera.folder,
            'active': camera.is_open(),
            'xmin': arduino.xMin,
            'xmax': arduino.xMax,
            'ymin': arduino.yMin,
            'ymax': arduino.yMax
        }

        return render_template('change_arduino.html',
                               form=uform,
                               roi_form=roi_form,
                               props=props)
Example #19
0
def update_my_blog(blog_id):
    """update the blog"""
    if not session.get("user_id") is None:
        user_id = session.get("user_id")
        user = session.get("username")
        blog = Blog.query.filter_by(blog_id=blog_id,
                                    blog_user_id=user_id).first()
        form = UpdateForm(obj=blog)
        if not blog:
            flash("No such blog found!")
        if form.validate_on_submit():
            blog.blog_title = form.blog_title.data
            blog.blog_type = form.blog_type.data
            blog.blog_content = form.blog_content.data
            blog.blog_desc = form.blog_desc.data
            db.session.commit()
            flash("Blog succesfully updated!")
            return redirect(url_for("show_my_blogs"))
        return render_template("update.html", form=form, user=user)
    else:
        return redirect(url_for("page_error"))
Example #20
0
def update():
    form2=UpdateForm()
    
    if flask.request.method == 'GET':
        data=request.args.get('data')
        numdata=int(data)
        parsel = Partnum.query.get(numdata)

    if form2.validate_on_submit():
        idd = request.form['idd']
        partnumber = request.form['partnumber']
        location = request.form['location']
        quantity = request.form['quantity']
        description = request.form['description']
        numdata=int(idd)
        parsel = Partnum.query.get(numdata)
        parsel.partnumber = partnumber
        parsel.location = location
        parsel.quantity = quantity
        parsel.description = description
        db.session.commit()
    return render_template('update.html',form2=form2, parsel=parsel)
Example #21
0
def update(i):
    user = current_user.uname
    post = Post.query.filter(Post.pid == i).first()
    form = UpdateForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            title = form.title.data
            head = form.head.data
            body = form.body.data
            print(i)
            p = Post.query.get(i)
            p.title = title
            p.head = head
            p.body = body
            db.session.commit()  # 提交
            return redirect('/admin/')
        return '修改失败,请重试'

    return render_template('admin/update.html',
                           post=post,
                           form=form,
                           user=user)
Example #22
0
def profile():
    if not current_user.is_authenticated:
        return redirect(url_for("login"))

    form = UpdateForm()

    if form.validate_on_submit():

        if form.picture.data:
            #flash("Picture Data Available!!")
            picture_file = save_picture(form.picture.data)
            current_user.image_pic = picture_file

        current_user.firstname = form.firstname.data
        current_user.lastname = form.lastname.data
        current_user.email = form.email.data
        current_user.phone_number = form.phone_number.data
        db.session.commit()

        flash("Profile updated!")
        return redirect(url_for('profile'))
    elif request.method == 'GET':

        form.firstname.data = current_user.firstname
        form.lastname.data = current_user.lastname
        form.phone_number.data = current_user.phone_number
        form.email.data = current_user.email
        print(form.picture.data)

    posts = Post.query.filter_by(user_id=current_user.get_id()).all()
    image = url_for('static',
                    filename='profile_images/' + current_user.image_pic)

    return render_template("profile.html",
                           title='Profile Page',
                           posts=posts,
                           image=image,
                           form=form)
Example #23
0
def handover(handover_id, handover_hash=None):
    form = UpdateForm()
    handover = Handover.query.get(handover_id)
    user = User.query.get(handover.user_id)
    text = Text.query.join(Media).filter(
        Media.id == Text.media_id).join(Handover).filter(
            Media.id == Handover.media_id).filter(
                Handover.id == handover_id).limit(1)
    handover_count = Handover.query.filter(
        Handover.artifact_id == handover.artifact_id).count()
    print("text")
    print(text[0].text)
    if handover == None:
        return redirect(url_for('index'))
    if handover_hash is not None and handover.access_hash == handover_hash:
        editable = True
        form.email.data = user.email
        form.text.data = text[0].text
        form.name.data = user.name
    else:
        editable = False
    if form.validate_on_submit():
        user.email = form.email.data
        if handover.media_id != None:
            media = Media.query.get(handover.media_id)
        db.session.commit()
    return render_template('handover.html',
                           title="Show Handover",
                           form=form,
                           editable=editable,
                           handover=handover,
                           text=text[0],
                           username=user.name,
                           email=user.email,
                           artifact_id=handover.artifact_id,
                           handover_count=handover_count)