Esempio n. 1
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'))
Esempio n. 2
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))
Esempio n. 3
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)
Esempio n. 4
0
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)
Esempio n. 5
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)
Esempio n. 6
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,
    )
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)
Esempio n. 8
0
def profile():
    """Update profile for current user."""
    #Ensure that use is logged in
    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    #Initialize Edit Form with user data from g
    form = EditForm(obj=g.user)

    if form.validate_on_submit():
        user = User.authenticate(g.user.username, form.password.data)
        if not user:
            flash("Password did not match", "danger")
            return redirect('/')
        else:
            #Remove the password field from the form we do not want any password modications here
            form.__delitem__("password")
            #Populate user model from form data and commit to db
            form.populate_obj(g.user)
            db.session.commit()

            return redirect(url_for('users_show', user_id=g.user.id))

    return render_template('/users/edit.html', form=form)
Esempio n. 9
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')
Esempio n. 10
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'))
Esempio n. 11
0
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)
Esempio n. 12
0
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)
Esempio n. 13
0
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)
Esempio n. 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)
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)
Esempio n. 16
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)
Esempio n. 17
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)
Esempio n. 18
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)
Esempio n. 19
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)
Esempio n. 20
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)
Esempio n. 21
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)
Esempio n. 22
0
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)
Esempio n. 23
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')
Esempio n. 24
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)
Esempio n. 25
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)
Esempio n. 26
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')
Esempio n. 27
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')
Esempio n. 28
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)
Esempio n. 29
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)
Esempio n. 30
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)
Esempio n. 31
0
def edit():
    """
    Edit allows the user to edit their profile after being logged in
    note the user of the g variable
    :return:
    """
    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('edit'))
    else:
        form.nickname.data = g.user.nickname
        form.about_me.data = g.user.about_me
    return render_template('edit.html', form=form)
Esempio n. 32
0
def edit():
    form = EditForm()
    if form.validate_on_submit():
        doc = PAN()
        docs = PAN.query.all()
        if (form.type.data == 'Aadhar Card'):
            doc = Aadhar()
            docs = Aadhar.query.all()
        doc.set_data(form.docid.data, form.firstname.data, form.lastname.data)
        for d in docs:
            if (d.check_docid(form.docid.data)):
                flash("Document Already Exists")
                return redirect(url_for('edit'))
        db.session.add(doc)
        db.session.commit()
        flash('Document Added Succesfully')
        return redirect(url_for('edit'))
    return render_template('edit.html', title='Add a Doc', form=form)
Esempio n. 33
0
def editpost(postid):
    if current_user.is_authenticated:
        current_post = Post.query.filter_by(id=postid)[0]
        # print(current_user)
        form = EditForm()
        if form.validate_on_submit():
            filename = str(postid)+".txt"
            file = open(filename, "w")
            file.write("".join([current_post.title, form.text.data]))
            flash('Topic {} has been updated.'.format(current_post.title))
            # new_title = form.title.data
            new_text = form.text.data
            # print(new_text)
            current_post.body = new_text
            db.session.commit()
            return redirect(url_for('index'))
        return render_template('edit.html', title='Edit Entry', post=current_post, form=form)
    return render_template('notloggedin.html')
Esempio n. 34
0
def edit():
    form = EditForm()

    if form.validate_on_submit():
        current_user.nickname = form.nickname.data
        current_user.about_me = form.about_me.data
        current_user.avatar = form.avatar.data
        current_user.email = form.email.data
        db.session.add(current_user)
        db.session.commit()
        return redirect(url_for('user', nickname=current_user.nickname))
    else:
        form.nickname.data = current_user.nickname
        form.about_me.data = current_user.about_me
        form.avatar.data = current_user.avatar
        form.email.data = current_user.email

    return render_template('edit.html', form=form)
Esempio n. 35
0
def edit():
    form = EditForm()
    if form.validate_on_submit():
        if not current_user.check_password(form.oldpassword.data):
            flash('Your old password isn\'t correct')
        else:
            current_user.set_password(form.password.data)

        current_user.first_name = form.first_name.data
        current_user.last_name = form.last_name.data
        current_user.bio = form.bio.data
        current_user.spol = form.spol.data
        if form.picture.data is not None:
            filename = secure_filename(form.picture.data.filename)
            form.picture.data.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            current_user.user_picture = filename
        db.session.commit()
        return redirect(url_for('home'))
    return render_template('edit.html', title='Edit Profile', form = form)