Пример #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
def search_func(request, films_on_page = 10):
    if request.GET.get("page", False) and int(request.GET.get("page", False)) != 1:
        query_page = "[int(request.GET.get('page', False)) * films_on_page - films_on_page:int(request.GET.get('page', False)) * films_on_page ]"
    else:
        query_page = "[:films_on_page]"
    search_query = "Films.objects"
    search_form = Search(request.GET)
    if search_form.is_valid():
        form = search_form.cleaned_data
    if form["name"] != "":
        search_query += ".filter(name='" + form["name"].strip() + "')"
    if form["director"] != "":
        search_query += ".filter(director='" + form["director"].strip() + "')"
    for item in request.GET:
        if "author_" in item:
            search_query += ".filter(authors__name__exact='" + devideAuthors(item).strip() + "')"
        if "actor_" in item:
            search_query += ".filter(actors__name__exact='" + devideActors(item).strip() + "')"
    if "genre" in request.GET:
        search_query += ".filter(genre__name='" + request.GET["genre"] + "')"
    if "start_date" in request.GET:
        search_query += ".filter(release_date__range=('"+ request.GET["start_date"] + "-01-01','" + request.GET["end_date"] + "-12-31'))"
    films_list = eval(search_query + query_page)
    films_count = eval(search_query).count()
    return films_list, range((films_count / films_on_page) + 1 if films_count % films_on_page == 0\
                                                               else (films_count / films_on_page) + 2), True
Пример #3
0
def search_func(request, films_on_page=10):
    if request.GET.get("page",
                       False) and int(request.GET.get("page", False)) != 1:
        query_page = "[int(request.GET.get('page', False)) * films_on_page - films_on_page:int(request.GET.get('page', False)) * films_on_page ]"
    else:
        query_page = "[:films_on_page]"
    search_query = "Films.objects"
    search_form = Search(request.GET)
    if search_form.is_valid():
        form = search_form.cleaned_data
    if form["name"] != "":
        search_query += ".filter(name='" + form["name"].strip() + "')"
    if form["director"] != "":
        search_query += ".filter(director='" + form["director"].strip() + "')"
    for item in request.GET:
        if "author_" in item:
            search_query += ".filter(authors__name__exact='" + devideAuthors(
                item).strip() + "')"
        if "actor_" in item:
            search_query += ".filter(actors__name__exact='" + devideActors(
                item).strip() + "')"
    if "genre" in request.GET:
        search_query += ".filter(genre__name='" + request.GET["genre"] + "')"
    if "start_date" in request.GET:
        search_query += ".filter(release_date__range=('" + request.GET[
            "start_date"] + "-01-01','" + request.GET["end_date"] + "-12-31'))"
    films_list = eval(search_query + query_page)
    films_count = eval(search_query).count()
    return films_list, range((films_count / films_on_page) + 1 if films_count % films_on_page == 0\
                                                               else (films_count / films_on_page) + 2), True
Пример #4
0
def city_search(request):
    context = {}
    context['request'] = request
    # states = State.objects.all().order_by("name")
    # context['states'] = states
    states = []
    

    if (request.method == 'POST'):
        form = Search(request.POST)
        context['form'] = form
        if (form.is_valid()):
            search = form.cleaned_data['search']
            context['search'] = search
            if (search != None):
                cities = Area.objects.filter(city__icontains=search).order_by("city")
                states = State.objects.filter(id__in=cities.values_list('state_id', flat=True))

                context['states'] = states.order_by("name")

            else:
                # cities = Area.objects.all().order_by("city")[:100]
                cities = None
                context['states'] = State.objects.all().order_by("name")
    else:
        form = Search()
        context['form'] = form
        cities = None
           

    context['cities'] = cities
    return render_to_response('city_search.html',context, context_instance=RequestContext(request))
Пример #5
0
def city_search(request):
    context = {}
    context['request'] = request
    # states = State.objects.all().order_by("name")
    # context['states'] = states
    states = []

    if (request.method == 'POST'):
        form = Search(request.POST)
        context['form'] = form
        if (form.is_valid()):
            search = form.cleaned_data['search']
            context['search'] = search
            if (search != None):
                cities = Area.objects.filter(
                    city__icontains=search).order_by("city")
                states = State.objects.filter(
                    id__in=cities.values_list('state_id', flat=True))

                context['states'] = states.order_by("name")

            else:
                # cities = Area.objects.all().order_by("city")[:100]
                cities = None
                context['states'] = State.objects.all().order_by("name")
    else:
        form = Search()
        context['form'] = form
        cities = None

    context['cities'] = cities
    return render_to_response('city_search.html',
                              context,
                              context_instance=RequestContext(request))
Пример #6
0
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)
Пример #7
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)
def search(username):
    #Search User Input
    wtform = Search(request.form)
    if wtform.validate():
        return redirect('/' + username + '/' + 'search' + '/' +
                        request.form["search"] + '?limit=10&offset=0')
    return render_template("search.html",
                           username=username,
                           form=wtform,
                           errors=wtform.errors)
Пример #9
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)
Пример #10
0
def enter_relation1():
    form = Search(request.form)
    if request.method == 'POST' and form.validate():
        search_string = form.searchbar.data
        result_set = movies_like(db, search_string)
        movie_listing = []
        for row in result_set:
            movie_listing.append((row.id, row.name.strip()))
        return render_template('movie_results.html',
                                   movie_listing=movie_listing)
    return render_template("enter_relation.html", form=form)
Пример #11
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('/')
Пример #12
0
 def post(self,request):
     form = Search(request.POST)
     if form.is_valid():
         cat_name = form.cleaned_data['category']
         key = form.cleaned_data['enter_keyword']
         p = models.Products.objects.searchall(key)
         q = models.Products.objects.searchcat(key,cat_name)
         if cat_name =='0':
             return render(request,'showproduct.html',{'products':p,'media_url':settings.MEDIA_URL})
         else:
             return render(request,'showproduct.html',{'products':q,'media_url':settings.MEDIA_URL})
     return render(request,'base.html',{'form':form,'title':'search','head':'search','value':'search'})
Пример #13
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)
Пример #14
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)
Пример #15
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)
Пример #16
0
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)
def search():
    form = Search()

    if request.method == 'POST':
        # fetch 'form data'
        userDetails = request.form

        # Initializing the values from input to variables
        search = userDetails['search']

        # Establishing Connection calling 'cursor' from 'connection class'
        cur = mysql.connection.cursor()

        # Executing the MySQL query
        value = cur.execute(
            "SELECT * FROM EM_DETAILS WHERE NAME LIKE %s OR DESIGNATION LIKE %s OR PHONE LIKE %s",
            (search, search, search))

        userDetails = cur.fetchall()
        # Commiting changes into MySQL Data-Base
        mysql.connection.commit()

        # Closing the connection by closing cursor
        cur.close()

        if value == 0:
            return redirect('/')
        else:
            return render_template('searched.html', userDetails=userDetails)
    return render_template('search.html', form=form)
Пример #18
0
def ihome():
    form = Search()
    curs = conn.cursor()
    selec = (
        "SELECT email, username, contact, skills, noticePeriod, jobID , source "
        "FROM UserProfiles ")
    curs.execute(selec)
    result = curs.fetchall()
    if request.method == 'POST':
        if form.selectN.data == '':
            form.selectN.data = '%'
        select = (
            "SELECT u.email, username, contact, skills, noticePeriod, jobID , source  "
            "FROM UserProfiles as u INNER JOIN trackCandidate as t "
            "ON u.email=t.email "
            "WHERE skills like ? AND noticePeriod like ? AND jobId like ? AND "
            + form.selectR.data + " = ?")
        values = [
            form.selectS.data, form.selectN.data, form.selectJ.data,
            form.selectT.data
        ]
        print(values)
        curs.execute(select, values)
        result = curs.fetchall()
        if result:
            flash("Filter Applied", 'success')
        else:
            flash("No Record Found", 'danger')
    return render_template('home2.html', form=form, result=result)
Пример #19
0
def home():
    form = Search()
    # it work but not needed here.
    #CompuStore = mysql_main.connection.cursor()
    #CompuStore.execute("call getByModel('Acer')")
    #rv = CompuStore.fetchall()
    return render_template("home.html", form=form)
Пример #20
0
def emailsearch():
    from nylas import APIClient

    nylas = APIClient(creds.CLIENT_ID, creds.CLIENT_SECRET, creds.ACCESS_TOKEN)

    data = Search()

    return render_template("email-search.html", data=data)
Пример #21
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)
Пример #22
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)
Пример #23
0
def state_list(request):

    context = {}
    context['request'] = request
    temp = request.user
    context['user'] = temp
    form = Search(request.GET, "by State")
    context['form'] = form
    context['states'] = State.objects.all().order_by('name')
    print context['states']
    if request.method == 'POST':
        username = request.POST.get('username', None)
        password = request.POST.get('password', None)
        print username
        print password

        user = authenticate(username=username, password=password)
        if user is not None:
            # the password verified for the user
            if user.is_active:
                login(request, user)
                print("User is valid, active and authenticated")
            else:
                print(
                    "The password is valid, but the account has been disabled!"
                )
        else:
            # the authentication system was unable to verify the username and password
            print("The username and password were incorrect.")

    # print request.user.is_authenticated()
    # print request.user

    return render_to_response('state_list.html',
                              context,
                              context_instance=RequestContext(request))
Пример #24
0
def search(request):
    form = Search()
    return render(request,'searchby.html',{'form':form,'value':'search'})
Пример #25
0
 def get(self,request):
     form = Search()
     return render(request,'base.html',{'form':form,'title':'search','head':'search','value':'search'})
Пример #26
0
def home():
    """homepage, displays a list of all the pets in \d pets"""
    form = Search()
    pets = Pet.query.order_by(Pet.id.desc()).all()
    return render_template('home.html', pets=pets, form=form)