예제 #1
0
def add_recipe():

    form = AddForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            # Get the image from the submitted form
            image = request.files.get('file')

            # Get the submitted form and perform the required
            # manipulation
            form_data = request.form.to_dict()
            form_data = populate_form(form_data, image_name=image.filename
                                      ) if image else populate_form(form_data)

            # Saves the image to the file system
            if image:
                image.save(
                    os.path.join(app.config.get('IMAGES_FOLDER'),
                                 image.filename))

            recipes = mongo.db.recipes
            recipes.insert_one(form_data)
            return redirect(url_for('get_recipes'))

    # Implicit GET request
    return render_template("addrecipe.html",
                           form=form,
                           cuisines=mongo.db.cuisines.find(),
                           countries=mongo.db.countries.find())
예제 #2
0
def add_pup():
    form = AddForm()
    if form.validate_on_submit():
        name = form.name.data
        pup = Puppy(name)
        db.session.add(pup)
        db.session.commit()
        return redirect(url_for('list_pup'))
    return render_template('addpup.html', form=form)
예제 #3
0
파일: app.py 프로젝트: spyd3r00/Database
def Edit(id_number):
	form = AddForm()
	var = Students.query.filter_by(idNumber=id_number).first()
	if form.validate_on_submit():
		var.idNumber = form.idNumber.data
		var.fullName = form.fullName.data
		var.Course = form.Course.data
		db.session.commit()

		return redirect(url_for('View'))
	return render_template('edit.html',title='Edit', var = var, form = form)
예제 #4
0
파일: app.py 프로젝트: spyd3r00/Database
def Register():
	form = AddForm()
	if form.validate_on_submit():
		try:
			students_1 = Students(fullName=form.fullName.data, Course=form.Course.data, idNumber=form.idNumber.data)
			db.session.add(students_1)
			db.session.commit()
			flash('Registered Successfully!')
		except:
			flash('Information Already Exist!')
		return redirect(url_for('home'))
	return render_template('register.html',title='Register', form=form)
예제 #5
0
def add():

    form = AddForm()

    if form.validate_on_submit():
        name = form.name.data  ## Getting name from the form.
        new_name = Student(name)  ## new_name is the object of the class.
        db.session.add(new_name)  ## We are adding new_name
        db.session.commit()

        return redirect(url_for("list"))

    return render_template("add.html", form=form)
예제 #6
0
def sync_add():
    response = {}
    form = AddForm(request.form)
    if not form.validate():
        response['status'] = 'ERROR_INVALID_FORM'
        return response
    data = form.data

    x = data['x']
    y = data['y']
    result = x + y

    response['status'] = 'ok'
    response['result'] = result
    return json.dumps(response)
예제 #7
0
def submit_add():
    response = {}
    form = AddForm(request.form)
    if not form.validate():
        response['status'] = 'ERROR_INVALID_FORM'
        return response
    data = form.data

    x = data['x']
    y = data['y']
    token = make_token('add')
    task.async_add.delay(token, x, y)

    response['status'] = 'ok'
    response['token'] = token
    return json.dumps(response)
예제 #8
0
def add():

    form = AddForm()

    if form.validate_on_submit():

        key = form.key.data
        main_data_source_key = form.main_data_source_key.data
        entity = form.entity.data
        field = form.field.data
        normalize_type = form.normalize_type.data
        new_data = DataCatalog(key, main_data_source_key, entity, field, normalize_type)
        db.session.add(new_data)
        db.session.commit()
        return redirect(url_for("index"))

    return render_template("add.html", form=form)
예제 #9
0
def edit_cuisine(cuisine_id):
    form = AddForm()

    if request.method == 'POST' and form.validate_on_submit():
        # Get the image from the submitted form
        image = request.files.get('file')

        # Get the submitted form and perform the required
        # manipulation
        form_data = request.form.to_dict()
        form_data = populate_form(
            form_data,
            image_name=image.filename) if image else populate_form(form_data)

        # Saves the image to the file system
        if image:
            image.save(
                os.path.join(app.config.get('IMAGES_FOLDER'), image.filename))

        cuisines = mongo.db.cuisines
        cuisines.update({'_id': ObjectId(cuisine_id)}, form_data)
        return redirect(url_for('get_cuisines'))

    # Implicit GET request
    the_cuisine = mongo.db.cuisines.find_one({"_id": ObjectId(cuisine_id)})
    form.cuisine.data = the_cuisine.get('recipe')
    form.allergens.data = the_cuisine.get('allergens')

    form.ingredients.data = '; '.join(the_cuisine.get('ingredients'))
    form.methods.data = '; '.join(the_cuisine.get('methods'))

    form.cuisine.data = next(k for k, v in cuisine_mapping.items()
                             if v == the_cuisine.get('cuisine'))
    form.country.data = next(k for k, v in country_mapping.items()
                             if v == the_cuisine.get('country'))

    all_cuisines = mongo.db.cuisines.find()
    all_countries = mongo.db.countries.find()

    return render_template('editcuisine.html',
                           cuisine=the_cuisine,
                           form=form,
                           cuisines=all_cuisines,
                           countries=all_countries)
예제 #10
0
파일: views.py 프로젝트: chenfengqiannian/1
def diyongyuanapi(request):
    if request.method == 'POST':# 当提交表单时
     
        form = AddForm(request.POST) # form 包含提交的数据
         
        if form.is_valid():# 如果提交的数据合法
            a = form.cleaned_data['identifying_code']
            
            dw=diyongjuan.objects.filter(yanzhengma=a)
           
            if(len(dw)==0):
                return HttpResponseForbidden(u"找不到此验证码")
            if(dw[0].yanzhengzhuangtai==0):
                dw[0].yanzhengzhuangtai=1
                dw[0].save()
                return HttpResponse(u"验证成功")
            else:
                return HttpResponseForbidden(u"此验证码已经使用")
     
    else:# 当正常访问时
        form = AddForm()
    return render(request, 'index.html', {'form': form})