Пример #1
0
def templates():

    temps = db.session.query(template).all()
    form = template_form()
    if form.validate_on_submit():
        if request.method == 'POST':
            file = request.files['img']
            try:
                if file and allowed_file(file.filename):
                    filename = secure_filename(file.filename)
                    img_temp = os.path.join(UPLOAD_FOLDER, filename)
                    file.save(img_temp)
                    name = form.name.data
                    mssg_1 = form.mssg_1.data
                    mssg_2 = form.mssg_2.data
                    mssg_3 = form.mssg_3.data
                    mssg_4 = form.mssg_4.data
                    mssg_5 = form.mssg_5.data
                    mssg_6 = form.mssg_6.data
                    mssg_7 = form.mssg_7.data
                    mssg_8 = form.mssg_8.data
                    if mssg_1 or mssg_2 or mssg_3 or mssg_4 or mssg_5 or mssg_6 or mssg_7 or mssg_8 is '':
                        new_temp = template(name=name, img_path=filename)
                    else:
                        new_temp = template(name = name , mssg_1 = mssg_1 , img_path = filename , mssg_2 = mssg_2 , mssg_3 = mssg_3 ,\
                            mssg_4 = mssg_4, mssg_5 = mssg_5, mssg_6 = mssg_6, mssg_7 = mssg_7 , mssg_8 = mssg_8)
                    db.session.add(new_temp)
                    db.session.commit()
                    mssg = "Template successfully added"
                    print(mssg)
                    return redirect(url_for('templates'))
            except Exception as e:
                print(str(e))
    return render_template('templates.html', form=form, temps=temps), 200
Пример #2
0
def templates():
    if (int(curr_project()) > 0):

        form = template_form()
        c_p = int(curr_project())
        project_active = Project.query.filter_by(id=int(c_p)).first()
        temps = project_active.template

        if form.validate_on_submit():
            if request.method == 'POST':
                file = request.files['img']
                try:
                    if file and allowed_file(file.filename):
                        filename = secure_filename(file.filename)
                        img_temp = os.path.join(UPLOAD_FOLDER, filename)
                        file.save(img_temp)
                        name = form.name.data
                        mssg_1 = form.mssg_1.data
                        mssg_2 = form.mssg_2.data
                        mssg_3 = form.mssg_3.data
                        mssg_4 = form.mssg_4.data
                        mssg_5 = form.mssg_5.data
                        mssg_6 = form.mssg_6.data
                        mssg_7 = form.mssg_7.data
                        mssg_8 = form.mssg_8.data

                        if mssg_1 or mssg_2 or mssg_3 or mssg_4 or mssg_5 or mssg_6 or mssg_7 or mssg_8 is '':
                            new_temp = template(name=name, img_path=filename)
                            project_active.template.append(new_temp)
                        else:
                            new_temp = template(name = name , mssg_1 = mssg_1 , img_path = filename , mssg_2 = mssg_2 , mssg_3 = mssg_3 ,\
                                mssg_4 = mssg_4, mssg_5 = mssg_5, mssg_6 = mssg_6, mssg_7 = mssg_7 , mssg_8 = mssg_8)
                            project_active.template.append(new_temp)

                        db.session.add(new_temp)
                        db.session.commit()
                        mssg = "Template successfully added"
                        print(mssg)
                        return redirect(url_for('templates'))
                except Exception as e:
                    print(str(e))
        return render_template('templates.html', form=form, temps=temps), 200
    else:
        session['mssg'] = "No project selected . Redirecting to Projects page."
        return redirect('projects')