示例#1
0
def editpost(postid):
    # print(Post.query.filter_by(id=postid))
    if current_user.is_authenticated:
        current_post = Post.query.filter_by(id=postid)[0]
        author = current_post.author  #User.query.filter_by(id=current_post.user_id).first_or_404()

        #print(current_user)
        form = EditForm()
        if form.validate_on_submit():
            flash('Topic {} has been Editted.'.format(form.title.data))

            # new_text = form.text.data
            # user_id = current_user.id

            file = open(postid + ".txt", "w")
            file.write(form.text.data + "\n")
            file.close()
            # p = Post(title=new_title,body=new_text,user_id=user_id)
            #print(p.user_id)
            # # db.session.add(p)
            # db.session.commit()

            return redirect(url_for('index'))
        else:
            form.text.data = current_post.body
        return render_template('edit.html',
                               title='Edit this current Entry',
                               post=current_post,
                               author=author,
                               form=form)
    return render_template('notloggedin.html')
示例#2
0
def edit():
    form = EditForm(request.form)

    if form.validate_on_submit():
        bruker = Bruker.query.filter_by(id=current_user.get_id()).first()
        bruker.passord = form.passord.data
        bruker.telefon = form.telefon.data

        db.session.commit()

        flash(USR_ACCUPDT, FLASH_SUCCESS)
        return redirect(url_for('pages.index'))
    else:
        if form.errors:
            flash_errors(form)

        # pre-fill data i alle tekstfeldt
        form.email.data = current_user.email
        form.passord.data = current_user.passord
        form.passord_igjen.data = current_user.passord
        form.fornavn.data = current_user.fornavn
        form.etternavn.data = current_user.etternavn
        form.telefon.data = current_user.telefon

        return render_template('forms/edit.html', form=form, current_user=current_user)
示例#3
0
def edit():
    form = EditForm()
    if request.method == 'POST' and form.validate():
        user = User.objects(id=current_user.id).first()
        form_username = User.objects(username=form.username.data).first()
        form_email = User.objects(email=form.email.data).first()

        if form_username != None and user.id != form_username.id:
            flash('Ya existe un usuario con el mismo nombre, seleccione otro')
            return redirect(url_for('edit'))

        if form_email != None and user.id != form_email.id:
            flash('Ya existe un usuario con el mismo correo, seleccione otro')
            return redirect(url_for('edit'))

        user.username = form.username.data
        user.email = form.email.data
        user.about_me = form.about_me.data
        user.save()
        flash('Los cambios han sido guardados.')
        return redirect(url_for('edit'))
    else:
        user = User.objects(email=current_user.email).first()
        form.username.data = user.username
        form.email.data = user.email
        form.about_me.data = user.about_me
    return render_template('edit.html.j2', form=form)
示例#4
0
def edit():
    form = EditForm()
    if request.method == "GET":
        if current_user.img:
            img = decode_image(current_user.img)
        else:
            img = None
        return render_template("edit.html", form=form, img=img)
    else:
        img = request.files["change"]
        if form.validate_on_submit():
            if form.name.data:
                current_user.name = form.name.data
            if form.new_password.data:
                if current_user.check_password(form.old_password.data):
                    current_user.set_password(form.new_password.data)
            if img:
                current_user.img = img.read()
            db.session.commit()
            return redirect(url_for("account"))
        if img:
            current_user.img = img.read()
            db.session.commit()
            return redirect(url_for("account"))
        return redirect(url_for('account'))
示例#5
0
def edit(id):
    #qry=db.session.query(Item).filter(Item.id==id)
    #items=qry.first()
    u_items = current_user.items
    for i in u_items:
        if i.id == id:
            items = i

    if items:
        form = EditForm(formdata=request.form, obj=items)
        if request.method == 'GET':
            form.isold.data = items.isold
        if request.method == 'POST':
            if request.form.get('delete'):
                delete(id)
                flash('Deleted succesfuly!')
                return redirect('/showitems')
            elif form.validate():
                #save edited
                save_changes(items, form)

                flash('Edited succesfuly!')
                return redirect('/showitems')

        return render_template('edititem.html', form=form)
    else:
        return 'Error loading #{id}'.format(id=id)
示例#6
0
文件: admin.py 项目: Jamz06/nyam_pes
def add_row(table):
    """
        Добавить запись в таблицу
    """

    form = EditForm()
    # Получить запись из таблицы
    data = execute(table_fields.format(table=table))

    print(data)
    data_to_update = ''
    if form.validate_on_submit():
        flash('Добавлено ;)')
        print(form)

        raw_data = request.form

        for row in raw_data:
            if row != 'csrf_token':
                # Строка для апдейта
                data_to_update += "{}='{}', ".format(row, raw_data[row])

        # debug Вывести запрос в БД
        query = insert_query.format(table=table, setter=data_to_update[0:-2])
        print(query)
        # Выполнить обновление записи
        execute(query)
        return redirect(url_for('view_table', table=table))

    return render_template('admin/add.html',
                           table=table,
                           tables=table_names,
                           data=data,
                           form=form)
示例#7
0
文件: routes.py 项目: jroiseux/Chordy
def editprog(editid):
    chordChoices = [(chord.cid, chord.name) for chord in Chord.query.all()]
    prog = Progression.query.get(editid)
    form = EditForm()
    form.chord1.choices = chordChoices
    form.chord2.choices = chordChoices
    form.chord3.choices = chordChoices
    form.chord4.choices = chordChoices
    if request.method == 'GET':
        chord1 = Chord.query.filter_by(cid=prog.c1).first()
        form.chord1.default = chord1.cid
        chord2 = Chord.query.filter_by(cid=prog.c2).first()
        form.chord2.default = chord2.cid
        chord3 = Chord.query.filter_by(cid=prog.c3).first()
        form.chord3.default = chord3.cid
        chord4 = Chord.query.filter_by(cid=prog.c4).first()
        form.chord4.default = chord4.cid
        form.process()
    if form.validate_on_submit():
        prog.c1 = form.chord1.data
        prog.c2 = form.chord2.data
        prog.c3 = form.chord3.data
        prog.c4 = form.chord4.data
        db.session.commit()
        return redirect(url_for('chordsList'))
    else:
        print(form.errors.items())
    return render_template('edit.html',
                           title='Edit Progression',
                           form=form,
                           progression=prog)
def edit():
    form = EditForm(request.form)

    if form.validate_on_submit():
        bruker = Bruker.query.filter_by(id=current_user.get_id()).first()
        bruker.passord = form.passord.data
        bruker.telefon = form.telefon.data

        db.session.commit()

        flash(USR_ACCUPDT, FLASH_SUCCESS)
        return redirect(url_for('pages.index'))
    else:
        if form.errors:
            flash_errors(form)

        # pre-fill data i alle tekstfeldt
        form.email.data = current_user.email
        form.passord.data = current_user.passord
        form.passord_igjen.data = current_user.passord
        form.fornavn.data = current_user.fornavn
        form.etternavn.data = current_user.etternavn
        form.telefon.data = current_user.telefon

        return render_template('forms/edit.html',
                               form=form,
                               current_user=current_user)
示例#9
0
文件: views.py 项目: HAKSOAT/DuFarms
def edit_product(name):
    """
    Edit information on the requested product
    :param name:
    :return: product info page
    """
    product = models.Product.query.filter(
        sa.func.lower(models.Product.name) == sa.func.lower(name)).first()
    if product:
        form = EditForm(obj=product)
        if request.method == "POST" and form.validate_on_submit():
            product.name = form.name.data
            product.description = form.description.data
            # Handle cases when a product's name already exists
            try:
                models.db.session.commit()
                flash("Product edited successfully", "success")
                return redirect(url_for("products"))
            except sa.exc.IntegrityError:
                flash("Product name exists", "danger")
        page_title = "DuFarms - Edit Product"
        form_type = "Product"
        return render_template("edit.html",
                               page_title=page_title,
                               form=form,
                               form_type=form_type)
    else:
        abort(404)
示例#10
0
def edit():
    """
    编辑个人信息
    :return:
    """
    form = EditForm(g.user.nickname)

    if form.validate_on_submit():
        app.logger.debug('nickname: %s', form.nickname.data)
        app.logger.debug('about_me: %s', form.about_me.data)

        g.user.nickname = form.nickname.data
        g.user.about_me = form.about_me.data
        db.session.add(g.user)
        db.session.commit()

        flash(gettext('Your changes have been saved.'))

        return redirect(url_for('edit'))
    else:
        form.nickname.data = g.user.nickname
        form.about_me.data = g.user.about_me

    return render_template(
        'edit.html',
        form=form,
    )
示例#11
0
 def test_good(self):
     app.app.config['WTF_CSRF_ENABLED'] = False
     with app.app.test_request_context('/'):
         r = Record(**test_record)
         form = EditForm(MultiDict(r.record))
         result = form.validate()
         self.assertEqual(result, True)
示例#12
0
def user_edit():
    form = EditForm()
    if request.method == 'POST' and form.validate():
        user = User.objects(id=current_user.id).first()
        #form_username = User.objects(username=form.username.data).first()
        form_email = User.objects(email=form.email.data).first()

        # if form_username != None and user.id != form_username.id:
        # flash('"{}" has already been registered'.format(form_username))
        # return redirect(url_for('user_edit'))

        if form_email != None and user.id != form_email.id:
            flash('"{}" has already been registered'.format(form_email))
            return redirect(url_for('user_edit'))

        # user.username = form.username.data
        user.email = form.email.data

        if form.password.data != None:
            user.reset_password(form.password.data)

        user.save()
        flash('Your changes have been saved!')
        return redirect(url_for('user', username=current_user.username))
    else:
        user = User.objects(email=current_user.email).first()
        # form.username.data = user.username
        form.email.data = user.email
        # form.about_me.data = user.about_me

    return render_template('user_edit.html', form=form)
示例#13
0
def edit():
    form = EditForm()
    existing_data = []
    for i in range(5):
        j = Book.query.filter_by(user_id=current_user.id).filter_by(rank=i +
                                                                    1).first()
        existing_data.append(j)
    if form.validate_on_submit():
        form_data = [(form.title1.data, form.author1.data),
                     (form.title2.data, form.author2.data),
                     (form.title3.data, form.author3.data),
                     (form.title4.data, form.author4.data),
                     (form.title5.data, form.author5.data)]
        for i in range(5):
            # b = Book.query.filter_by(user_id=current_user.id).filter_by(rank=i+1).first()
            b = existing_data[i]
            if b:
                b.title = form_data[i][0]
                b.author = form_data[i][1]
                db.session.commit()
            else:
                b = Book(user_id=current_user.id,
                         rank=i + 1,
                         title=form_data[i][0],
                         author=form_data[i][1])
                db.session.add(b)
                db.session.commit()
        return (redirect(url_for('index')))
    return (render_template('edit.html',
                            title='Edit',
                            form=form,
                            existing_data=existing_data))
示例#14
0
def edit():
    form = EditForm()
    if form.validate_on_submit():
        g.user.username = form.username.data
        g.user.about_me = form.about_me.data

        if request.files['file']:
            file = request.files['file']
            filename = file.filename
            path = os.path.dirname(app.config['UPLOAD_FOLDER'] + "/{}/".format(g.user.username) + filename)
            if not os.path.exists(path):
                os.makedirs(path)
            app.config["UPLOAD_FOLDER"] = path
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            g.user.avatar_url = filename
        db.session.add(g.user)
        db.session.commit()

        flash('Your changes have been saved.')
        return redirect(url_for('edit'))
    else:
        form.username.data = g.user.username
        form.about_me.data = g.user.about_me

    return render_template('edit.html', form=form)
示例#15
0
def edit_student():
    form = EditForm()
    user = current_user
    if request.method == 'GET':
        form.firstname.data = user.firstname
        form.lastname.data = user.lastname
        form.wsuid.data = user.wsuid
        #form.phonenumber = user.phonenumber //not able to call done know why

    if form.validate_on_submit():
        user = current_user
        user.firstname = form.firstname.data
        user.lastname = form.lastname.data
        user.wsuid = form.wsuid.data
        user.phonenumber = form.phonenumber.data
        user.gpa = form.gpa.data
        user.major = form.major.data
        user.grad_date = form.grad_date.data
        user.experience = form.experience.data
        db.session.commit()
        return redirect(url_for('student_main'))

    return render_template("edit_student.html",
                           title='edit_Student_page',
                           form=form)
def edit():
    form = EditForm(g.user.username)
    if form.validate_on_submit():
        g.user.username = form.username.data
        g.user.brokerID = form.brokerID.data
        g.user.mdAddress = form.mdAddress.data
        g.user.tdAddress = form.tdAddress.data
        g.user.userID = form.userID.data
        g.user.password = form.password.data
        db.session.add(g.user)
        db.session.commit()
        param = {}
        param['brokerID'] = form.brokerID.data
        param['mdAddress'] = g.user.mdAddress
        param['tdAddress'] = g.user.tdAddress
        param['userID'] = g.user.userID
        param['password'] = g.user.password
        print param
        writeCTP_connect_json(param)
        flash(u'您的修改已经保存')
        return redirect(url_for('edit'))

    form.username.data = g.user.username

    #form.about_me.data = g.user.about_me
    return render_template('edit.html', form=form)
示例#17
0
文件: views.py 项目: RamyRais/monkey
def edit_profile(name=""):
    monkey = Monkey.query.filter_by(name=name).first()
    if monkey is None:
        return redirect(url_for('index'))
    form = EditForm()
    if form.validate_on_submit():
        number_errors = 0
        if monkey.email != form.email.data: #testing email unicity
            if Monkey.query.filter_by(email=form.email.data).first():
                form.email.errors.append("Email {0} is already used".format(
                    form.email.data))
                number_errors += 1
        if monkey.name != form.name.data: #testing name unicity
            if Monkey.query.filter_by(name=form.name.data).first():
                form.name.errors.append("Name {0} is already used".format(
                    form.name.data))
                number_errors += 1
        if number_errors > 0:
            return render_template('edit.html', form=form)
        monkey.email = form.email.data
        monkey.name = form.name.data
        monkey.age = form.age.data
        db.session.add(monkey)
        db.session.commit()
        return redirect(url_for('profile', name=monkey.name))
    else:
        form.name.data = monkey.name
        form.email.data = monkey.email
        form.age.data = monkey.age
    return render_template('edit.html', form=form)
示例#18
0
def edit_post(id):
    p = Post.query.filter_by(id=id).first_or_404()
    form = EditForm()
    if form.validate_on_submit():
        p.title = form.title.data
        p.body = form.post.data
        db.session.commit()
        return redirect(url_for('post', id=p.id))
    return render_template('_edit-post.html', form=form, post=p)
示例#19
0
 def validate(self, record={}):
     """
     Validates a single record.
     Returns a list of issues found, which can be empty.
     """
     form = EditForm(MultiDict(record), meta={'csrf': False})
     result = form.validate()
     errors = form.errors
     return result, errors, form
示例#20
0
def test_should_fail_validation_when_text_is_too_long(app):
    app.config['MAX_PASTE_LENGTH'] = 4
    with app.app_context():
        form = EditForm(
            MultiDict([('text', 'abcde'), ('extension', ''),
                       ('delete_after', '4')]))
        assert form.validate() is False
        assert len(form.errors) == 1
        assert form.text.errors[
            0] == 'Your snippet is too long.  Max 4 characters.'
示例#21
0
def change():
    form = EditForm()
    article_id = form.country.data
    article = Article.query.get(article_id)
    if form.validate_on_submit():
        article.UpdatedContent = form.UpdatedContent.data
        db.session.commit()
        flash('Your submission has been accepted! We will consider and update it in a while. Thank you!', 'success')
        return redirect(url_for('home'))
    return render_template('change.html', title='Edit Info', form=form)
示例#22
0
def addNewTask():
    form = EditForm()

    if form.validate_on_submit():
        newTask = Task(title=form.title.data, description=form.description.data, completed=False, dateAdded=datetime.datetime.now())
        db.session.add(newTask)
        db.session.commit()

        return redirect('/')

    return render_template('new-task.html', title='Add New Task', form=form)
示例#23
0
 def post(self):
     form = EditForm(g.user.nickname)
     if form.validate_on_submit():
         g.user.nickname = form.nickname.data
         g.user.about_me = form.about_me.data
         db.session.add(g.user)
         db.session.commit()
         flash('Your changes have been saved.')
         app.logger.info('edited profile {}'.format(g.user.nickname))
         return redirect(url_for('UserView:get'))
     return render_template('edit.html', form=form)
示例#24
0
def edit():
    form = EditForm(g.user.username)
    if form.validate_on_submit():
        g.user.username = form.username.data
        g.user.about_me = form.about_me.data
        db.session.add(g.user)
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('edit'))
    form.username.data = g.user.username
    form.about_me.data = g.user.about_me
    return render_template('edit.html', form=form)
示例#25
0
def edit(id):
    tsk = Task.query.get(id)
    form = EditForm()
    if form.validate_on_submit():
        tsk.task_name = form.task_name.data
        db.session.add(tsk)
        db.session.commit()
        flash('Your changes have been saved')
        return redirect(url_for('addTask'))
    elif request.method == 'GET':
        form.task_name.data = tsk.task_name
    return render_template('edit_task.html', form=form)
示例#26
0
文件: views.py 项目: andkns/mysite
def edit():
    form = EditForm()
    if form.validate_on_submit():
        g.user.nickname = form.nickname.data
        g.user.about_me = form.about_me.data
        db.session.add(g.user)
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('edit'))
    else:
        form.nickname.data = g.user.nickname
        form.about_me.data = g.user.about_me
    return render_template('edit.html', form=form)
示例#27
0
def edit(id):
    if current_user.is_authenticated:
        student = Student.query.filter_by(student_id=id).first()

        clock = EditTime.query.filter_by(id = current_user.id).first()
        clock.placeholder += 1
        db.session.add(clock)
        db.session.commit()

        if student != None:
            form = EditForm(obj=student)
            if form.validate_on_submit():
                form.populate_obj(student)
                db.session.commit()
                return redirect(url_for('index'))
        else:
            form = EditForm()
            if form.validate_on_submit():
                student = Student( firstName=form.firstName.data, lastName=form.lastName.data, bannerID=form.bannerID.data, address=form.address.data, phone=form.phone.data, gpa=form.gpa.data, creditTotal=form.creditTotal.data, student_id=id )
                db.session.add(student)
                db.session.commit()
                if(current_user.faculty == True):
                    return redirect(url_for('index'))
                else:
                    return redirect(url_for('index', id = current_user.id))
        return render_template('edit.html', title='Edit', form=form)
    else:
        return redirect(url_for('login'))
示例#28
0
def edit(address_id):
    address = Address.query.filter_by(id=address_id).first_or_404()
    form = EditForm(current_user.username)
    if form.validate_on_submit():
        address.body = form.address.data
        db.session.commit()
        flash(_('Your changes have been saved.'))
        return redirect(url_for('edit', address_id=address.id))
    elif request.method == 'GET':
        form.address.data = address.body
    return render_template('edit.html',
                           title=_('Edit'),
                           form=form,
                           address=address)
示例#29
0
def edit():

    form = EditForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        user.set_favorite_stock(form.stock.data)
        user.set_state_code(form.state.data)
        user.set_age(form.age.data)
        db.session.merge(user)
        db.session.commit()

        return redirect(url_for('main.index'))

    return render_template('edit.html', title='Edit', form=form)
示例#30
0
def edit():
    form = EditForm(g.user.nickname)
    if form.validate_on_submit():
        g.user.nickname = form.nickname.data
        g.user.about_me = form.about_me.data
        g.user.last_seen = datetime.datetime.now()
        db.session.add(g.user)
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('edit'))
    else:
        form.nickname.data = g.user.nickname
        form.about_me.data = g.user.about_me
    return render_template('edit.html', form=form, title='Edit')
示例#31
0
def editpost(postid):
	if current_user.is_authenticated:
		current_post = Post.query.filter_by(id=postid)[0]
		title = current_post.title
		text = current_post.body
		form = EditForm()
		if form.validate_on_submit():
			flash("Edit for topic " + title + " has been saved in " + str(postid) + ".txt")
			new_text = form.text.data
			thefile = open(str(postid) + ".txt", "w+")
			thefile.write(new_text)
			return redirect(url_for('index'))
		form.update_text(text)
		return render_template('editpost.html', title='Edit an Existing Entry', form=form, topictitle=title)
	return render_template('notloggedin.html')
示例#32
0
def movie_trailer(id):
    m = Movie.query.get_or_404(id)
    form = EditForm()
    if form.validate_on_submit():
        if form.editable.data:
            m.trailer_url = form.editable.data
            db.session.commit()
        return redirect(url_for('admin.movie'))
    else:
        form.editable.data = m.trailer_url if m.trailer_url else ''
    return render_template('admin_edit.html',
                           title='admin.edit',
                           movie_title=m.title,
                           movie_year=m.year,
                           form=form,
                           editable_name='trailer\'s url')
示例#33
0
def edit():
    form = EditForm(g.user.nickname)
    if form.validate_on_submit():
        g.user.nickname = form.nickname.data
        g.user.about_me = form.about_me.data
        g.user.name = form.name.data
        db.session.add(g.user)
        db.session.commit()
        flash(gettext("Your changes have been saved."), "success")
        return redirect(url_for("edit"))
    else:
        form.nickname.data = g.user.nickname
        form.about_me.data = g.user.about_me
        form.name.data = g.user.name

    return render_template("edit.html", form=form)
示例#34
0
def edit(folder, name):
    path = Config.CONTENT_PATH
    folders = Config.CONTENT_FOLDERS
    form = EditForm()
    if form.validate_on_submit():
        data = form.content.data
        with open(os.path.join(path, folder, name), 'w') as f:
            f.write(data)
        return redirect(url_for('show', folder=folder, name=name))
    elif request.method == 'GET':
        with open(os.path.join(path, folder, name), 'r') as f:
            data = f.read()
        form.content.data = data
    return render_template('form.html',
                           title=f'Edit {name}',
                           folders=folders,
                           form=form)
示例#35
0
def edit():
    '''###############################
    Edit user information
    ##################################
    '''
    form = EditForm(g.user.nickname)
    if form.validate_on_submit():
        g.user.nickname = form.nickname.data
        g.user.about_me = form.about_me.data
        db.session.add(g.user)
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('.user', nickname=g.user.nickname))
    else:
        form.nickname.data = g.user.nickname
        form.about_me.data = g.user.about_me
    return render_template('edit.html', form=form)