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


Python SearchForm.is_valid方法代码示例

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


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

示例1: search

# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import is_valid [as 别名]
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,代码行数:34,代码来源:views.py

示例2: home

# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import is_valid [as 别名]
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,代码行数:29,代码来源:views.py

示例3: search_form

# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import is_valid [as 别名]
def search_form(request,queryset,Model):
    if request.method =="POST":
        form = SearchForm(request.POST)

        if form.is_valid():
            search = str(form.cleaned_data['search']).lower()
            results = list()
            #Loop over object in queryset of model
            for object in queryset:
                model_dict = model_to_dict(object)
                print (model_dict)

                #Check if the searched string is included in one of the Object field
                """
                for key in model_dict:
                    print('Searching: ')
                    print (model_dict[key])
                """

                if search in str(model_dict['name']):
                        #Add the users id in a list
                        print('I found d')
                        results.append(object.id)
                        break
            #Re-initialize the model queryset filtering by found objects.id
            queryset = Model.objects.filter(pk__in = (results))


    else:
        form = SearchForm()
        queryset = Model.objects.all()

    return queryset
开发者ID:unistra,项目名称:rfpportal-frcsxb,代码行数:35,代码来源:views.py

示例4: check_in

# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import is_valid [as 别名]
def check_in(request):
    form = SearchForm(request.GET or None)
    members = orchestras = None

    if form.is_valid():
        term = form.cleaned_data.get('q')
        members = (Member.objects.filter(Q(first_name__istartswith=term) |
                                         Q(last_name__istartswith=term) |
                                         Q(pid__contains=term))
                   .select_related('orchestras')
                   .order_by('first_name', 'last_name'))

        if len(members) == 1:
            member = members[0]
            return redirect('check_in_list',
                            token=member.orchestras.all()[0].token, member_pk=member.pk)

        orchestras = Orchestra.objects.filter(Q(orchestra_name__icontains=term) |
                                              Q(short_name__icontains=term))

        if len(orchestras) == 1:
            return redirect('check_in_list', token=orchestras[0].token)

        for member in members:
            member.orchestra_token = member.orchestras.all()[0].token

    return render(request, 'orkester/search.html',
                  {'form': form, 'members': members, 'orchestras': orchestras})
开发者ID:LinTek,项目名称:SOF13,代码行数:30,代码来源:views.py

示例5: test_search

# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import is_valid [as 别名]
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,代码行数:29,代码来源:views.py

示例6: account_view

# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import is_valid [as 别名]
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,代码行数:29,代码来源:views.py

示例7: search

# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import is_valid [as 别名]
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,代码行数:37,代码来源:views.py

示例8: List

# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import is_valid [as 别名]
def	List(request):

    try:
	if CheckAccess(request,'23') != 'OK':
	    return render_to_response("mtmc/notaccess/mtmc.html")
    except:
	return HttpResponseRedirect('/')




    if request.method == 'POST':
	formuser = UserForm(request.POST)
	if formuser.is_valid():
	    user = formuser.cleaned_data['user']
	    request.session['user_id'] = user

	formsearch = SearchForm(request.POST)
	if formsearch.is_valid():
	    search = formsearch.cleaned_data['search']
	    r = FindKey(search)
	    if len(r) == 1:
		return HttpResponseRedirect('/mtmcedit/?eq_id=%s' % search)

    ### --- Сохранное занчение user_id ---
    try:
	user_id = request.session['user_id']
    except:
	user_id = ''

    try:
	print_ok = request.GET['print']
	response = HttpResponse(content_type='application/pdf')
	response['Content-Disposition'] = 'attachment; filename="list.pdf"'
	buff = StringIO()
	result = PrintForm(buff,user_id)
	response.write(result.getvalue())
	buff.close()
	return response
    except:
	pass



    formmove = MoveForm(None)
    formsearch = SearchForm(None)
    formuser = UserForm(None)
    formuser.fields['user'].initial = user_id


    data = GetList(user_id)

    if len(data)!=0 and user_id != 'ALL':
	print_ok = True
    else:
	print_ok = False

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

示例9: index_view

# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import is_valid [as 别名]
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,代码行数:34,代码来源:views.py

示例10: search

# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import is_valid [as 别名]
def search(request):
    did_post_pun = ""
    if request.method == "POST":
        form, did_post_pun = process_pun_form(request)
    else:
        form = PunForm()
    context_dict = {"new_pun_form": form, "search_form": SearchForm()}
    query_string = ""
    puns = Pun.objects.all()

    search_form = SearchForm(request.GET)
    if search_form.is_valid():
        data = search_form.cleaned_data
        query_string = data["search"]
        puns = watson.filter(Pun, query_string)
    if puns is not None:
        puns = order_query_set_by_pun_score(puns)
        for pun in puns:
            pun.profile = UserProfile.objects.get(user=pun.owner)
    if request.user.is_authenticated():
        puns = set_up_down_votes(request, puns)
        profile = UserProfile.objects.get(user=request.user)
        if not profile.show_nsfw:
            puns = [pun for pun in puns if pun.NSFW == False]
    context_dict["tags_list"] = get_all_tags_list()
    context_dict["query_string"] = query_string
    context_dict["puns"] = puns
    response = render_to_response("punny/search-results.html", context_dict, context_instance=RequestContext(request))
    if did_post_pun is True:
        response.set_cookie("success", "pun posted!", max_age=3)
    elif did_post_pun is False:
        response.set_cookie("failed", "post failed", max_age=3)
    return response
开发者ID:mhsaleem,项目名称:ITECH-,代码行数:35,代码来源:views.py

示例11: search

# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import is_valid [as 别名]
def search(request, term=None):
    form = search_term = result_list = results = None
    if request.POST:
        form = SearchForm(request.POST)
        if form.is_valid():
            search_term = form.cleaned_data['terms']
    if term is not None:
        # Note, we might need to do some cleanup here
        search_term = term
    if search_term is not None:
        # Get results
        result_list = BaseStop.search(search_term)

        paginator = Paginator(result_list, 25)
        page = request.GET.get('page', 1)
        try:
            results = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            results = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            results = paginator.page(paginator.num_pages)
    if form is None:
        form = SearchForm()

    return render(request, 'stops/results.html', {
        'results': results,
        'term': search_term,
        'form': form
    })
开发者ID:StichtingOpenGeo-Museum,项目名称:haltebeheer,代码行数:33,代码来源:views.py

示例12: search

# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import is_valid [as 别名]
def search(request):
    if request.method == 'POST':
        form = SearchForm(request.POST)
        if form.is_valid():
            return HttpResponse(stream_response(
                request.POST['url'],
                request.POST['depth'],
                request.POST['search']), mimetype='text/html')
开发者ID:kezakez,项目名称:python-django-web-crawler-webui,代码行数:10,代码来源:views.py

示例13: test_valid_data

# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import is_valid [as 别名]
	def test_valid_data(self):
		# valid data is at least 1 input is given

		form = SearchForm({
			'dept_name' : 'Admin'
			})

		self.assertTrue(form.is_valid())
开发者ID:allisonng,项目名称:salesforce-django,代码行数:10,代码来源:tests.py

示例14: search

# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import is_valid [as 别名]
def search(request):
    """ Поиск пациентов """
    patients_qs = Patient.objects.all()
    form = SearchForm(request.GET)
    special_cure_text = ''
    header = u'Все'
    
    if len(request.GET) == 0:
        # Если поиск не запускали, то и не надо показывать всех пациентов
        return render_to_response('search.html',
                              {'form': form, 'have_search_result': False},
                              context_instance=RequestContext(request))

    
    if form.is_valid():
        full_name = form.cleaned_data.get('full_name')
        if full_name:
            patients_qs = patients_qs.filter(all_full_names__icontains=full_name)
        type_residence = form.cleaned_data.get('type_residence')
        if type_residence:
            patients_qs = patients_qs.filter(type_residence=type_residence)
        social_status = form.cleaned_data.get('social_status')
        if social_status:
            patients_qs = patients_qs.filter(social_status=social_status)
        birthday = form.cleaned_data.get('birthday')
        if birthday:
            patients_qs = patients_qs.filter(birthday=birthday)
        death = form.cleaned_data.get('death')
        if death:
            patients_qs = patients_qs.filter(death=death)
        mo_added = form.cleaned_data.get('mo_added')
        if mo_added:
            patients_qs = patients_qs.filter(visit__is_add=True,
                                             visit__mo=mo_added)
        special_cure = form.cleaned_data.get('special_cure')
        if special_cure:
            if special_cure in HEADER_SEARCH:
                header = HEADER_SEARCH[special_cure]
            patients_qs = patients_qs.filter(special_cure=special_cure)
        diagnosis = form.cleaned_data.get('diagnosis')
        if diagnosis:
            q_st = Q(diagnosis__code__contains=diagnosis) | \
                   Q(diagnosis__name__contains=diagnosis)
            with_diagnosis = patients_qs.filter(diagnosis__code__contains=diagnosis)
            patients_qs = patients_qs.filter(pk__in=with_diagnosis)

    patients_qs = patients_qs.values('pk', 'all_full_names',
                                     'birthday', 'diagnosis_text_code',
                                     'name_allocate_mo', 'gender')
    response = {'patients': patients_qs,
                'count': patients_qs.count(),
                'special_cure_text': special_cure_text,
                'form': form,
                'header': header,
                'have_search_result': True}
    return render_to_response('search.html',
                              response,
                              context_instance=RequestContext(request))
开发者ID:dicos,项目名称:geneticist,代码行数:60,代码来源:views.py

示例15: home

# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import is_valid [as 别名]
def home(request, *arg):
    if request.method == 'POST':
        form = SearchForm(request.POST)
        if form.is_valid():
            pass
    else:
        form = SearchForm()
    c = RequestContext(request, {'form': form})
    return render_to_response('home.html', c)
开发者ID:ntoll,项目名称:IssueTracker,代码行数:11,代码来源:views.py


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