当前位置: 首页>>代码示例>>Python>>正文


Python forms.SearchForm类代码示例

本文整理汇总了Python中forms.SearchForm的典型用法代码示例。如果您正苦于以下问题:Python SearchForm类的具体用法?Python SearchForm怎么用?Python SearchForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SearchForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: List

def	List(request):

    try:
	user = GetUserKod(request)
    except:
	return HttpResponseRedirect('/')


    ### --- Удаление файла ---
    if request.method == 'GET':
	try:
	    delete_id = request.GET['delete_file']
	    DelFile(delete_id)
	except:
	    pass


    ### --- Получение номера страницы ---
    try:
	page = int(request.GET.get('page',1))
	request.session['page'] = page
    except:
	pass
	
    try:
	page = int(request.session['page'])
    except:
	page = 1



    try:
	search = request.session['search']
    except:
	search = ''



    if request.method == 'POST':
	
	form = SearchForm(request.POST)
	if form.is_valid():
	    search = form.cleaned_data['search']
	    request.session['search'] = search

    data = ListFile(user,search)


    paginator = Paginator(data,50)
    try:
	data_page = paginator.page(page)
    except (EmptyPage, InvalidPage):
	data_page = paginator.page(paginator.num_pages)

    form = SearchForm(None)
    form.fields['search'].initial = search

    c = RequestContext(request,{'data':data_page,'form':form})
    c.update(csrf(request))
    return render_to_response("userfiles/list.html",c)
开发者ID:v-komarov,项目名称:scatalog,代码行数:60,代码来源:views.py

示例2: index_view

def index_view(request):
    search_form = SearchForm()
    bugs = Bugs.objects
    if request.method == "GET":
        search_form = SearchForm(request.GET)
        if search_form.is_valid():
            search = search_form.cleaned_data["search_text"]
            status = search_form.cleaned_data["status"]
            issue_types = search_form.cleaned_data["issue_types"]
            product = search_form.cleaned_data["product"]
            priority = search_form.cleaned_data["priority"]
            keyword = search_form.cleaned_data["keyword"]

            bugs = bugs.filter(short_desc__icontains=search) | \
                    bugs.filter(longdescs__thetext__icontains=search)
            bugs = bugs.distinct()
            if status != "":
                bugs = bugs.filter(bug_status__exact=status)
            if priority != "":
                bugs = bugs.filter(priority__exact=priority)
            if product:
                bugs = bugs.filter(product__name__exact=product)
            if keyword:
                bugs = bugs.filter(kws__id__exact=keyword)
            if issue_types == 1:
                bugs = bugs.exclude(bug_status__in=["CLOSED", "RESOLVED"])
    bugs = bugs.order_by("bug_id").reverse()
    return render_to_response("index.html", {
        "bugs": bugs,
        "search_form": search_form,
        },
        context_instance=RequestContext(request))
开发者ID:certik,项目名称:bugzilla_ui,代码行数:32,代码来源:views.py

示例3: search

def search(request):
    """
    On post, recieve a string and radius, geocode, and return a bunch of
    buddies within that radius
    """
    # prevent access by non-organisations
    try:
        organisation = request.user.organisation.all()[0]
    except IndexError:
        return HttpResponseForbidden()
    
    form = SearchForm(request.POST or None)
    if form.is_valid():
        buddies_in_range = []
        # geocode address
        lat, lng = geocode(request.POST.get('location'))
        # to keep things super simple, pull out all buddies, then filter in
        # memory. obviously this will have to be fixed once there is a
        # non-trivial number of buddies in the db. and when we have more 
        # than a day to work on this thing
        buddies = Buddy.objects.all()
        for buddy in buddies:
            buddy_lat, buddy_lng = float(buddy.location['latitude']), float(buddy.location['longitude'])
            radius = int(request.POST.get('radius'))
            dist = points2distance(((buddy_lng, 0, 0), (buddy_lat, 0, 0)),((lng, 0, 0), (lat, 0, 0)))
            if dist <= radius:
                buddies_in_range.append(buddy)
    else:
        buddies_in_range = None
        
    return render_to_response('buddies/search.html', {
        'form': form,
        'buddies_in_range': buddies_in_range,
        'is_get': request.method == 'GET'
    }, context_instance=RequestContext(request))
开发者ID:adivik2000,项目名称:Refugee-Buddy,代码行数:35,代码来源:views.py

示例4: index

def index():
    # logic for the edit my profile page
    # pull text from input fields and rewrite JSON entry in the DB associated with that profile
    form = SearchForm()
    if form.validate_on_submit():
	# creating dictionary to store text from input text fields
        s = {}
	for i in ['Profname','about','age','email','phone','loc','empid','school','gradYear','involv', 'picture', 'groupd']:
	    if request.form[i] != "":
		s[i] = request.form[i]
	    else:
		s[i] = ''
	s['inter'] = {}
	s['username'] = current_user.username
	for i in ['exploring', 'nightlife', 'outdoors', 'sports', 'videogames']:
	    if i in request.form.getlist('interests'):
		s['inter'][i] = 1
	    else:	
		s['inter'][i] = 0
	#converting dictionary to JSON
	json_string = json.dumps(s)
	#checking if a profile with the username already exists in the db
	result = db_connection.execute("""SELECT p.comment_id, p.doc FROM user_profile p WHERE p.doc.username = :x""", x=current_user.username).fetchone()[0] 
	if result:
	    this_profile = UserProfile.get(result)
	    this_profile.doc = json_string
	    db.session.commit()
	else:
	    db.session.add(UserProfile(json_string))
	    db.session.commit()
	return redirect(url_for('viewprof', username = current_user.username))
    return render_template('index.html', form=form)
开发者ID:ImNitinNayar7,项目名称:json-in-db,代码行数:32,代码来源:views.py

示例5: search

def search():
    form1 = SearchForm()
    m = []
    entries = {}
    message = None
    if form1.validate_on_submit():
    	keywords = form1.query.data
    	  #parse the HTTP response
        m = searchWord(keywords)

    elif request.form.get("like") != None:
        smallURL = request.form.get("small")
        bigURL = request.form.get("big")
        message = LikeImage(smallURL, bigURL)
        return message

    elif request.form.get("review") != None:
        entries = reviewLiked()
        
    elif request.form.get("dislike") != None:
        smallURL = request.form.get("small")
        bigURL = request.form.get("big")
        dislikeImage(smallURL, bigURL)
        entries = reviewLiked()
    return render_template('search.html',
        title = 'Flickr Search',
        form1 = form1,
        liked = entries,
        imgs = m,
        message = message)
开发者ID:charliezhangqian,项目名称:Flickr_Feeds,代码行数:30,代码来源:views.py

示例6: search

def search():
    form = SearchForm()
    if form.validate_on_submit():
        results = wiki.search(form.term.data, form.ignore_case.data)
        return render_template('search.html', form=form,
                               results=results, search=form.term.data)
    return render_template('search.html', form=form, search=None)
开发者ID:Tutt-Library,项目名称:wiki,代码行数:7,代码来源:app.py

示例7: book

def book(book_id):
    form = SearchForm()
    book = Book.query.filter_by(id = book_id).first()
    pics = Picture.query.filter_by(book_id = book_id).order_by(Picture.order)
    if book == None:
        flash('Book not found')
        return redirect(url_for('index'))

    if form.validate_on_submit():
        api = InstagramAPI(client_id=app.config['INSTAGRAM_ID'], client_secret = app.config['INSTAGRAM_SECRET'])
        # if max_tag_id > 0:
        #     if request.args['query']:
        #         tag_name = request.args['query']
        #     tag_media, next = api.tag_recent_media(count = 20, max_id = max_tag_id, tag_name = request.args['query'])
        # else:
        tag_media, next = api.tag_recent_media(count = 20, tag_name = form.query.data)
        instagram_results = []
        for media in tag_media:
            instagram_results.append(media.images['thumbnail'].url)
        try:
            max_tag_id = next.split('&')[2].split('max_tag_id=')[1]
        except: 
            max_tag_id = None
        return render_template('book.html',
            query = form.query.data,
            instagram_results = tag_media,
            pics = pics,
            form = form,
            next = max_tag_id,
            book = book)

    return render_template('book.html',
        book = book,
        pics = pics,
        form = form)
开发者ID:danlopez,项目名称:weddstagram,代码行数:35,代码来源:views.py

示例8: search

def search():
    """ Search form """
    search = SearchForm()
    if search.validate_on_submit():
        return redirect(url_for('.search_results', query=search.search.data))
    else:
        return redirect(request.referrer)
开发者ID:urschrei,项目名称:CDP,代码行数:7,代码来源:views.py

示例9: events

def events():
    form = SearchForm(request.forms.decode())
    # XXX: make WTForm for this and validate!

    if form.validate():
        filters = {}
        if form.country.data != "":
            filters['country'] = form.country.data

        session = create_session()
        matching_events = session.query(Event).filter_by(**filters).\
            order_by(Event.start_date)

        print "--------------------"
        print form.yob.data
        print form.yob is None
        if form.yob is not None:
            print form['yob']
            matching_events = ((matching_events)
                .filter(form.yob.data <= Event.max_yob) #1985 <= 2000
                .filter(form.yob.data >= Event.min_yob)) #1985 >= 1980


        e = list(matching_events)
        return dict(events=e, get_url=app.get_url)
    return dict(events=[], error="nothing found", get_url=app.get_url)
开发者ID:steinnes,项目名称:judo-events,代码行数:26,代码来源:index.py

示例10: search

def search(request):
    
    def make_tups(list, name='None'):
        tup = (('None', '%s' % name),)
        for item in list:
            tup = tup + ((item, item),)
        return tup

    poller_choices = make_tups(Poller.objects.all().values_list('name', flat=True).order_by('name'), 'Pollers')
    server_choices = make_tups(Server.objects.all().values_list('name', flat=True).order_by('name'), 'Servers')

    if request.method == 'POST':
        form = SearchForm(request.POST, poller_choices=poller_choices, server_choices=server_choices)
        if form.is_valid():
            data = form.cleaned_data

            transfers = TransferLog.objects.all().order_by('-started')
            if data['server'] != 'None':
                transfers = transfers.filter(server__exact=data['server']).order_by('-started')
            if data['poller'] != 'None':
                transfers = transfers.filter(name__exact=data['poller']).order_by('-started')
            if data['status'] != 'None':
                transfers = transfers.filter(status__exact=data['status']).order_by('-started')
            if data['filename'] != '':
                transfers = transfers.filter(filename__icontains=data['filename']).order_by('-started')

            return render(request, 'dispatch_web/search.html', {'form': form, 'transfers': transfers})

    else:
        form = SearchForm(poller_choices=poller_choices, server_choices=server_choices)

    return render(request, 'dispatch_web/search.html', {'form': form})
开发者ID:powellchristoph,项目名称:dispatch_web,代码行数:32,代码来源:views.py

示例11: account_view

def account_view(request):
    context = {}
    context['user'] = request.user
    # Search
    if request.method == 'POST':
        form = SearchForm(request.POST)
        if request.user.is_authenticated():
            if form.is_valid():
                search = Search.objects.create(
                    url=form.cleaned_data['url'],
                    title=form.cleaned_data['title'],
                    owner=request.user)
                search.save()
                # redirect to proper search
                return redirect(reverse('search'))
            else:
                # return form errors
                return render_to_response('account.html', context, RequestContext(request))
        else:
            # permissions should make this impossible
            return render_to_response('account.html', context, RequestContext(request))
    context['search_form'] = SearchForm()
    # context['searches'] = Search.objects.filter(owner=request.user).all()
    context['searches'] = Search.objects.all()
    for search in Search.objects.all():
        print search.created
    return render_to_response('account.html', context, RequestContext(request))
开发者ID:josephtoles,项目名称:search-engine,代码行数:27,代码来源:views.py

示例12: test_search

def test_search(request, code):
    invitation = check_invitation(code)
    if not invitation:
        messages.error(request, 'Your personal URL is incorrect, please reset your account or provide proper url')
        return redirect('index') 
    
    results={}
    from forms import SearchForm
    if request.method == 'POST':
        form = SearchForm(request.POST) 
        if form.is_valid(): 
            keywords = __to_keywords(form.cleaned_data['search'])
            for k in keywords:
                profiles = Profile.objects.filter(keywords=k)
                for p in profiles:
                    count = results.get(p, 0)
                    results[p]=count+1
            if len(results)==0:
                messages.error(request, "Sorry, we couldn't find match for you. Try later.")
    
    else:
        form=SearchForm()
    
    return render_to_response('researchers/test_search.html', {'key':code, 
                                                                'form':form, 
                                                                'results':results,
                                                                'sorted':sorted(results.items(), key=lambda x: -x[1])},  context_instance=RequestContext(request))
开发者ID:Top500Innovators,项目名称:but,代码行数:27,代码来源:views.py

示例13: raw_email

def raw_email(stype,docnumber):
	#Get the raw email from the database
	db_name = '01_database/hrc.sqlite'
	db = sqlite3.connect(db_name)
	cursor = db.cursor()

	#search = docnumber
	sql_cmd = 'SELECT RawText FROM emails\
		   WHERE DocNumber IS ?'
	cursor.execute(sql_cmd, (docnumber,))
	tmp = cursor.fetchone()
	raw_email = tmp[0]
	#Remove special characters and split into lines:
	evec = raw_email.split('\n')
	for line in evec:
		line.strip()
	#Take care of search form
	form = SearchForm()
	if form.validate_on_submit():# and request.method == 'POST':
		flash('Searching Hillary\'s emails for "%s"' % 
              	(form.search.data ))
		#stype as placeholder in case we want to add different seach schemes
		#'bs' = body/subject
		#'ps' = people search 
		#'es' = email search (to/from address)
        	return redirect(url_for('.search', stype = stype, search = form.search.data))

	return render_template('raw_email.html',
				raw_email = evec,
				docnumber = docnumber,
				form = form)
开发者ID:pstraus,项目名称:hrc-ee,代码行数:31,代码来源:app.py

示例14: main

def main(key_id=0, act=""):
    user_obj = User()
    tran_obj = Transaction()
    key_obj = Key()
    search_form = SearchForm()
    keys = user_obj.list_all_key(current_user.role, current_user.company_id)
    if request.method == "POST":
        if act == "take":
            selected_key = key_obj.query.get(key_id)
            selected_key.available = False
            db.session.add(selected_key)
            new_transaction = Transaction(user=current_user, key_id=key_id, time_stamp=datetime.datetime.now() + timedelta(hours=3))
            db.session.add(new_transaction)
            db.session.commit()
            flash("Key Taken")
            return redirect(url_for('main'))
        elif act == "release":
            selected_key = key_obj.query.get(key_id)
            selected_key.available = True
            db.session.add(selected_key)
            db.session.commit()
            flash("Key Release")
            return redirect(url_for('main'))
    if search_form.validate_on_submit():
        print search_form.key_input.data
        string_input = search_form.key_input.data
        if string_input == "":
            flash("Please enter something for searching")
            return redirect(url_for("main"))
        else:
            return redirect(url_for('search', input=string_input))
    elif request.method == "GET":
        return render_template("main.html", keys=keys, search_form=search_form)
开发者ID:nnduc1994,项目名称:Aurio,代码行数:33,代码来源:views.py

示例15: home

def home(request):
    """ Manages our home page.  If a POST request is received, then
    we're going to pull the search value out and attempt to filter
    for it.  This can be a hash or a plaintext value.
    """
    
    if request.method == 'POST':
        form = SearchForm(request.POST)

        if form.is_valid():
            data =  HashModel.objects.all()
            search = request.POST.get("search_input")

            # search the hashval and plaintext fields 
            result = data.filter(Q(hashval=search) | Q(plaintext=search))

            return render_to_response('home.html',
                            {'form':SearchForm(),
                             'results':result
                            },
                            context_instance=RequestContext(request))

    return render_to_response("home.html", 
                                {'form' : SearchForm(),
                                 'results':HashModel.objects.all()[:50]
                                },
                                context_instance=RequestContext(request))
开发者ID:CoalfireLabs,项目名称:Doozer,代码行数:27,代码来源:views.py


注:本文中的forms.SearchForm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。