示例#1
0
def go():
    # GET请求
    from forms import Search
    search_form = Search()
    # 判断参数
    if search_form.validate_on_submit():
        search = search_form.search.data
        webServer.writeData(conn, search)
        print(search)
        if request.method == "POST":
            # resqult = sr(search)
            resqult = webServer.readData(conn)
            values = [
                search,
            ]
            for url in resqult:
                url = url.decode("gb2312")
                values.append(url)

            if len(values) > 1:
                return render_template("result.html",
                                       result=values,
                                       form1=search_form)
        # return render_template("result.html", title='Result', form1=search_form)
        else:
            pass
            #print("data:", search)
        values = []
        values.append("%s" % search)
        print(values)
        return render_template('result.html', result=values, form1=search_form)
示例#2
0
文件: web.py 项目: alexlint/PRJ7
def judge():
    from forms import Search
    sform = Search()
    if request.method == 'POST':
        if sform.validate_on_submit():
            search = sform.search.data
            print(search)
            return redirect(url_for('.go', search=search))
    return render_template('search.html', title='Search', form=sform)
示例#3
0
def search():
    """Search page."""
    form = Search()

    if form.validate_on_submit():
        search = request.form["search"]
        if not search:
            search = "*"
        select = request.form["select"]
        return redirect(url_for("search", **{select: search}, page=1))

    page = request.args.get('page', default=1, type=int)
    user_id = session["user_id"]
    if request.args.get("title"):
        select = "title"
        search = request.args.get("title")
    elif request.args.get("category"):
        select = "category"
        search = request.args.get("category")
    elif request.args.get("ingredient"):
        select = "ingredient"
        search = request.args.get("ingredient")
    else:
        return render_template('page_not_found.html'), 404

    if search == "*":
        recipes = db.execute("SELECT title, recipes.recipe_id FROM recipes JOIN owners ON "
                             "recipes.recipe_id=owners.recipe_id WHERE user_id = ?",
                             (user_id,))
    elif select == "title":
        recipes = db.execute("SELECT title, recipes.recipe_id FROM recipes JOIN owners ON "
                             "recipes.recipe_id=owners.recipe_id WHERE user_id = ? AND title "
                             "LIKE ?", (user_id, "%" + search + "%"))

    elif select == "category":
        recipes = db.execute("SELECT title, recipes.recipe_id FROM recipes INNER JOIN owners "
                             "ON recipes.recipe_id=owners.recipe_id INNER JOIN categories ON "
                             "recipes.recipe_id=categories.recipe_id WHERE user_id = ? AND "
                             "category = ? GROUP BY title", (user_id, search))
    else:
        recipes = db.execute("SELECT title, recipes.recipe_id FROM recipes INNER JOIN owners "
                             "ON recipes.recipe_id=owners.recipe_id INNER JOIN ingredients ON "
                             "recipes.recipe_id=ingredients.recipe_id WHERE user_id = ? AND "
                             "(' ' || ingredient || ' ') LIKE ? GROUP BY title", (user_id, "% " +
                                                                                  search + " %"))
    # try pages
    per_page = 10
    try:
        pages = Pagination(recipes, page, per_page)
    except IndexError:
        return render_template('page_not_found.html'), 404

    if pages.total >= pages.per_page:
        recipes = pages.items

    return render_template("search.html", form=form, select=select, search=search, pages=pages,
                           recipes=recipes)
示例#4
0
def search_results():
	form = Search()
	if form.validate_on_submit():
		if form.search_by.data == 'first_name':
			first_name_search = Patient.query.filter_by(first_name=form.search_term.data).all()
		elif form.search_by.data == 'last_name':
			last_name_search = Patient.query.filter_by(last_name=form.search_term.data).all()
		else:
			patient_number_search = Patient.query.filter_by(patient_number=form.search_term.data).all()
	return render_template('search_results.html', form=form, first_name_search=first_name_search, \
		last_name_search=last_name_search, patient_number_search=patient_number_search)
示例#5
0
def search():
    """ The search by name return page the lists pets with the searched name """
    form = Search()

    if form.validate_on_submit():
        search = form.name.data
        pets = Pet.query.filter(Pet.name.like('%' + search + '%'))
        return render_template('search_results.html', pets=pets, form=form)
    else:
        pets = Pet.query.all()
        return redirect('/')
示例#6
0
def index():
    """Website homepage."""
    form = Search()

    if form.validate_on_submit():
        search = request.form["search"]
        if not search:
            search = "*"
        select = request.form["select"]
        return redirect(url_for("search", **{select: search}, page=1))

    return render_template("index.html", form=form)
示例#7
0
def search():
    form = Search()
    name = form.name.data
    if form.validate_on_submit():
        rows = find(name)
        try:
            result = rows[0]
        except:
            return render_template('search.html',
                                   error="No match found",
                                   form=form)
        return render_template('search.html', result=result)
    return render_template('search.html', form=form)
示例#8
0
def home():
    form = Search()
    if form.validate_on_submit():
        if form.search_by.data == 'first_name':
            first_name_search = Patient.query.filter_by(
                first_name=form.search_term.data).all()
        elif form.search_by.data == 'last_name':
            last_name_search = Patient.query.filter_by(
                last_name=form.search_term.data).all()
        else:
            patient_number_search = Patient.query.filter_by(
                patient_number=form.search_term.data).all()
    return render_template('home.html', form=form, first_name_search=first_name_search, last_name_search=last_name_search, \
     patient_number_search=patient_number_search)
示例#9
0
文件: web.py 项目: alexlint/PRJ7
def go():
    from forms import Search
    sform = Search()
    db = MySQL.connectDatabase()
    if sform.validate_on_submit():
        search = sform.search.data
        webServer.writeData(connecter, search)
        print(search)
        if request.method == "POST":
            sqt = webServer.readData(connecter)
            val = []
            title = []
            for url in sqt:
                sql = "select id from urllist where url = '" + url + "' ;"
                urlid = MySQL.query(db, sql)
                try:
                    root = ET.parse('news/' + '%s.xml' % urlid[0][0]).getroot()
                    url = root.find('url').text
                    title = root.find('title').text
                    doc = {'url': url, 'title': title, 'id': urlid[0][0]}
                except:
                    article_content = fetch(url)
                    doc = ET.Element("doc")
                    ET.SubElement(doc, "id").text = "%d" % (urlid[0][0])
                    ET.SubElement(doc, "url").text = url
                    ET.SubElement(doc, "title").text = article_content["title"]
                    ET.SubElement(
                        doc, "datetime").text = article_content["publish_time"]
                    ET.SubElement(doc,
                                  "body").text = article_content["content"]
                    tree = ET.ElementTree(doc)
                    tree.write("news/" + "%d.xml" % (urlid[0][0]),
                               encoding="utf-8",
                               xml_declaration=True)
                    doc = {
                        'url': url,
                        'title': article_content["title"],
                        'id': urlid[0][0]
                    }
                val.append(doc)
            if len(val) > 1:
                return render_template("result.html", result=val, form1=sform)
        else:
            pass
        val = []
        val.append("%s" % search)
        print(val)
        return render_template('result.html', result=val, form1=sform)
示例#10
0
def pet_details(pet_id):
    """get  details on a particular pet"""
    pet = Pet.query.get(pet_id)
    editForm = EditPet()
    form = Search()
    if form.validate_on_submit():
        if editForm.photo_url.data != None and editForm.photo_url.data != '':
            pet.photo_url = editForm.photo_url.data
        if editForm.notes.data != None and editForm.notes.data != '':
            pet.notes = editForm.notes.data
        if editForm.available.data != None and editForm.available.data != '':
            pet.available = editForm.available.data
            if pet.available == False:
                flash(f'{pet.name} has been adopted!')
        db.session.commit()
        return redirect(f'/pets/{pet_id}')
    else:
        return render_template('pet_details.html',
                               pet=pet,
                               form=form,
                               editForm=editForm)
示例#11
0
def search():
    form = Search()
    pens = models.Pen.query.all()
    brands = models.Brand.query.all()
    tags = models.Tag.query.all()
    # populate the dropdown selections
    form.brand.choices = [(brand.id, brand.name) for brand in brands]
    form.tag.choices = [(tag.id, tag.name) for tag in tags]

    selected_tag = form.tag.data
    selected_brand = form.brand.data

    # if no search done yet
    results = pens
    has_searched = False

    if request.method == 'POST':
        if form.validate_on_submit():
            has_searched = True
            brand = models.Brand.query.filter_by(id=selected_brand).first()
            tag = models.Tag.query.filter_by(id=selected_tag).first()
            # Get a list of the pens common between the brand and the tag chosen.
            results = list(set(brand.pens).intersection(tag.pens))
            # render the search results
            return render_template('search.html',
                                   title="Find a Pen",
                                   form=form,
                                   results=results,
                                   brand=brand.name,
                                   tag=tag.name,
                                   has_searched=has_searched)
        else:
            abort(404)
    return render_template('search.html',
                           title="Find a Pen",
                           form=form,
                           results=results,
                           has_searched=has_searched)