示例#1
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)
示例#2
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)
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'))
示例#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)
示例#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)
示例#6
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)
示例#7
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)
示例#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)}
示例#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)
示例#10
0
 def post(self,request,*args,**kwargs):
     #print(json.loads(request.body))
     print(request.body)
     print(request.POST)
     form = UpdateForm(request.POST)
     if form.is_valid():
         obj = form.save(commit=True)
         obj_data = obj.serialize1()
         return HttpResponse(obj_data,content_type="application/json",status=200)
     json_data = json.dumps({
         "message":"sorry bro"
     })
     return HttpResponse(json_data, content_type='application/json', status=200)
示例#11
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)
示例#12
0
def change_arduino(ard_nr):
    '''
    Change the parameters of a specific arduino
    '''
    global arduinos
    if not arduinos:
        flash('No arduinos installed', 'error')
        return redirect(url_for('add_arduino'))

    n_ards = len(arduinos)
    arduino = arduinos[int(ard_nr)]
    props = {
        'name': arduino.name,
        'id': int(ard_nr),
        'port': arduino.serial.port,
        'active': arduino.is_open()
    }

    uform = UpdateForm(id=ard_nr)

    wform = SerialWaitForm(id=ard_nr)
    dform = DisconnectForm(id=ard_nr)
    cform = ReConnectForm(id=ard_nr)

    return render_template('change_arduino.html',
                           form=uform,
                           dform=dform,
                           cform=cform,
                           wform=wform,
                           props=props)
示例#13
0
def change_arduino(ard_nr):
    '''
    Change the parameters of a specific arduino
    '''
    global arduinos
    if not arduinos:
        flash('No cameras installed', 'error')
        return redirect(url_for('add_camera'))

    n_ards = len(arduinos)
    arduino = arduinos[int(ard_nr)]
    props = {
        'name': arduino.name,
        'id': int(ard_nr),
        'folder': arduino.folder,
        'active': arduino.is_open(),
        'xmin': arduino.xMin,
        'xmax': arduino.xMax,
        'ymin': arduino.yMin,
        'ymax': arduino.yMax
    }

    uform = UpdateForm(id=ard_nr)
    roi_form = RoiForm(id=ard_nr)
    return render_template('change_arduino.html',
                           form=uform,
                           roi_form=roi_form,
                           props=props)
示例#14
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)
示例#15
0
def hello(user_ip=0, username='******'):
    user_ip = session.get('user_ip')
    username = current_user.id
    todo_form = todoForm()
    delete_form = DeleteForm()
    update_form = UpdateForm()

    context = {
        'user_ip': user_ip,
        'lista': get_todos(username),
        'username': username,
        'todo_form': todo_form,
        'delete_form': delete_form,
        'update_form': update_form
    }

    if todo_form.validate_on_submit():
        description = todo_form.description.data
        put_todo(description=description, user_name=username)

        flash('Tarea creada con exito')

        redirect(url_for('hello'))

    # users = get_users()
    #
    # for user in users:
    #     print(user.id)
    #     print(user.to_dict().get('password'))

    return render_template('hello.html', **context)
示例#16
0
def arduino():
    '''
    Configure now settings for the arduino.
    '''
    aform = UpdateArduinoForm()
    global ssProto

    if aform.validate_on_submit():
        n_setpoint =  aform.setpoint.data;
        if ssProto.is_open():
            o_str = 's{}'.format(n_setpoint)
            b = o_str.encode()
            ssProto.serial.write(b)
            flash('We set the serial port to {}'.format(n_setpoint))
        else:
            flash('Serial port not open.', 'error')
        return redirect(url_for('config'))
    else:
        port = app.config['SERIAL_PORT']
        uform = UpdateForm()
        dform = DisconnectForm()
        cform = ConnectForm()

        conn_open = ssProto.connection_open()

        return render_template('config.html', port = port, form=uform, dform = dform,
            cform = cform, conn_open = conn_open, arduino_form = aform)
示例#17
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
                           ])
示例#18
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'))
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'))
示例#20
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) 
示例#21
0
def adminPage():
    form = UpdateForm()
    if not session['logged_in']:
        return redirect(url_for('admin.login'))
    else:
        if form.validate():
            post = Post(body=form.new_post.data,
                        title=form.title.data,
                        page=form.dropdown.data,
                        timestamp=datetime.utcnow())
            s.add(post)
            s.commit()
            if s.commit() is True:
                flash('Success')

    return render_template('admin.html',
                           form=form)
示例#22
0
def edit_person(request):
    user = request.user
    group = user.groups.first()
    if str(group) == "Person":
        person = get_object_or_404(Person, user_id=user.id)
        address = person.address
        if request.method == 'POST':
            user_form = UpdateForm(
                request.POST,
                instance=user,
                initial={'fullname': user.first_name + " " + user.last_name})
            address_form = AddressForm(request.POST, instance=address)
            person_form = PersonForm(request.POST,
                                     request.FILES,
                                     instance=person)
            if user_form.is_valid() and address_form.is_valid(
            ) and person_form.is_valid():
                user_form.save()
                address_form.save()
                person_form.save()
                return HttpResponseRedirect("/profile/" + str(user.id) + "/")
        else:
            user_form = UpdateForm(
                instance=user,
                initial={'fullname': user.first_name + " " + user.last_name})
            address_form = AddressForm(instance=address)
            person_form = PersonForm(instance=person)
        context = {
            'user_form': user_form,
            'address_form': address_form,
            'person_form': person_form,
        }
        return render(request, 'edit_person.html', context)
    else:
        return HttpResponseRedirect("/index/")
示例#23
0
def edit_investor(request):
    user = request.user
    group = user.groups.first()
    if str(group) == "Investor":
        investor = get_object_or_404(Investor, user_id=user.id)
        if request.method == 'POST':
            user_form = UpdateForm(
                request.POST,
                instance=user,
                initial={'fullname': user.first_name + " " + user.last_name})
            investor_form = InvestorForm(request.POST,
                                         request.FILES,
                                         instance=investor)
            if user_form.is_valid() and investor_form.is_valid():
                user_form.save()
                investor_form.save()
                return HttpResponseRedirect("/profile/" + str(user.id) + "/")
        else:
            user_form = UpdateForm(
                instance=user,
                initial={'fullname': user.first_name + " " + user.last_name})
            investor_form = InvestorForm(instance=investor)
        context = {
            'user_form': user_form,
            'investor_form': investor_form,
        }
        return render(request, 'edit_investor.html', context)
    else:
        return HttpResponseRedirect("/index/")
示例#24
0
def update():
    form = UpdateForm(request.form)

    if request.method == 'GET':
        if request.values.get('ix'):
            movimiento = recuperarregistro(request.values.get('ix'))
            print(movimiento)

            nombre = [
                'ix', 'fecha', 'concepto', 'monedaComprada',
                'cantidadComprada', 'monedaPagada', 'cantidadPagada'
            ]
            for i in range(len(nombre)):
                form[nombre[i]].data = movimiento[i]
            '''
            contador = 0
            for campo in nombre:
                form[campo].data = movimiento[contador]
                contador += 1

            form.fecha.data = movimiento[0]
            form.concepto.data = movimiento[1]
            form.monedaComprada.data = movimiento[2]
            form.cantidadComprada.data = movimiento[3]
            form.monedaPagada.data = movimiento[4]
            form.cantidadPagada.data = movimiento[5]
            '''
            return render_template('update.html', form=form)

    else:
        form.monedaComprada.data = int(form.monedaComprada.data)
        form.monedaPagada.data = int(form.monedaPagada.data)

        if form.validate():
            registro_seleccionado = [
                form.fecha.data, request.values['fecha'],
                request.values['concepto'], request.values['monedaComprada'],
                request.values['cantidadComprada'],
                request.values['monedaPagada'],
                request.values['cantidadPagada']
            ]
            modificarregistro(request.values)
            return redirect(url_for('index'))
        return render_template('update.html', form=form)
示例#25
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
示例#26
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)
示例#27
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)
示例#28
0
def config():
    port = app.config['SERIAL_PORT']
    uform = UpdateForm()
    dform = DisconnectForm()
    cform = ConnectForm()
    arduino_form = UpdateArduinoForm()

    global ssProto;
    conn_open = ssProto.connection_open()

    return render_template('config.html', port = port, form=uform, dform = dform,
        cform = cform, conn_open = conn_open, arduino_form = arduino_form)
示例#29
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"))
示例#30
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)
示例#31
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)
示例#32
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)