示例#1
0
文件: app.py 项目: arishabh/easyscore
def output(query):
    if query:
        query = query.replace("&", ",")
        query = query.replace("=", ":")
        query = query.replace('_', ' ')
        elements = literal_eval("{" + query + "}")
        keyword = elements["keyword"]
        cr_fullfil = elements["requirement"]
        cr = elements["credit"]
        level = elements["level"]
        timing = elements["timing"]
        days = elements["days"]
        next_sem = elements["next sem"]
        with open("info/misc/search.txt", "a+") as f:
            f.write(str(datetime.now().strftime("%d/%m/%Y %H:%M:%S")) + str(elements))
        all_courses = search_all(cr_fullfil, level, cr, next_sem, keyword, timing, days)
        if len(all_courses)>40:
            all_courses = all_courses[:40]
    if request.method == 'POST':
        days = list(map(str, request.form.getlist("day")))
        search_query = dict(request.form)
        search_query.pop('dept')
        search_query.pop('day', None)
        search_query['days'] = days
        search_query = str(search_query)[1:-1]

        search_query = search_query.replace(",", "&")
        search_query = search_query.replace(":", "=")
        search_query = search_query.replace(' ', '_')
        url = '/results&searchquery=' + search_query
        return redirect(url)
    return render_template('result.html', all_courses=all_courses, credits_inv=credits_inv, inp=[cr_fullfil, cr, level, next_sem, keyword, timing, days], next_sem_name=next_sem_name)
示例#2
0
def export(request, format=None, kwargs=None):
    if request.method == 'GET':
        results = None
        exporter = None
        form = AdvancedSearchForm(request.GET)
        if form.is_valid():
            do_search = False
            for item in form.cleaned_data.values():
                if item:
                    do_search = True
            if do_search:
                #                 print form.cleaned_data['doc_type']
                #                 print type(form.cleaned_data['doc_type'])
                results = search_all(form.cleaned_data)
        else:
            return HttpResponseRedirect('/')

        if format:
            try:
                exporter = getattr(exporters, format)
            except AttributeError:
                raise Http404('No export format %s is available.' % format)

        if results:
            response = exporter(results)
            return response
        else:
            return HttpResponseRedirect('/')
示例#3
0
def main(argv):
    logging.basicConfig(
        format=
        u'%(filename)s[LINE:%(lineno)d]# %(levelname)-8s [%(asctime)s]  %(message)s',
        level=logging.DEBUG)
    db = DB()
    if db.table_is_empty('request'):
        logging.info('Table request is empty. Filling...')
        xslx_to_db()
    if db.table_is_empty('region_code'):
        logging.info('Table region_code is empty. Filling...')
        regions_to_db()
    search_all()
    insert_listner = Insertlistner(search_by_id)
    insert_listner.start()
    insert_listner.join()
示例#4
0
def export(request, format=None, kwargs=None):
    if request.method == 'GET':
        results = None
        exporter = None
        form = AdvancedSearchForm(request.GET)
        if form.is_valid():
            do_search = False
            for item in form.cleaned_data.values():
                if item:
                    do_search = True
            if do_search:
#                 print form.cleaned_data['doc_type']
#                 print type(form.cleaned_data['doc_type'])
                results = search_all(form.cleaned_data)
        else:
            return HttpResponseRedirect('/')

        if format:
            try:
                exporter = getattr(exporters, format)
            except AttributeError:
                raise Http404('No export format %s is available.' % format)
                
        if results:
            response = exporter(results)
            return response
        else:
            return HttpResponseRedirect('/')
示例#5
0
文件: server.py 项目: noelis/LitBits
def search():
    """ Loads search results page. """

    q = request.args.get("q")

    if q != "":
        # cleans up the query and formats it
        clean_query = clean_up_query(q)
        # calls function that queries db.
        search_results = search_all(clean_query)
        return render_template("search.html",
                               search_results=search_results,
                               q=q)
    else:
        flash("Please enter a valid alphanumeric character.")
        return redirect('/')
def show_all_results(page):
    form = forms.AllSearchForm()
    search_string = form.search.data

    if page == 1:
        if not form.validate_on_submit():
            return render_template('index.html', form=form, tabs=tabs)

    # keep copies in the session as next pages don't have the search string and filters available
    # in the form

    if search_string is None:
        search_string = session['search_string']
        filters = session['filters']
    else:
        session['search_string'] = search_string
        filters = json.loads(form.search_all_filters.data)
        session['filters'] = filters

    try:
        results = search.search_all(search_string, filters, page)
    except Exception as inst:
        try:
            reason = inst.info['error']['root_cause'][0]['reason']
        except (NameError, TypeError, AttributeError):
            reason = inst

        a = list(form.search.errors)
        a.append(reason)
        form.search.errors = tuple(a)
        form.search.data = None
        return render_template('index.html', form=form, tabs=tabs)

    count = results['total']

    if not results and page != 1:
        abort(404)

    pagination = Pagination(page, Config.ITEMS_PER_PAGE, count)
    return render_template('results.html',
                           pagination=pagination,
                           companies=results,
                           tabs=tabs,
                           view=view_type)
示例#7
0
文件: app.py 项目: arishabh/easyscore
def json_output(query):
    if query:
        query = query.replace("&", ",")
        query = query.replace("=", ":")
        query = query.replace('_', ' ')
        elements = literal_eval("{" + query + "}")
        keyword = elements["keyword"]
        cr_fullfil = elements["requirement"]
        level = elements["level"]
        cr = elements["credit"]
        timing = elements["timing"]
        days = elements["days"]
        next_sem = elements["next sem"]
        with open("info/misc/search.txt", "a+") as f:
            f.write(str(datetime.now().strftime("%d/%m/%Y %H:%M:%S")) + str(elements))
        all_courses = search_all(cr_fullfil, level, cr, next_sem, keyword, timing, days)
        if len(all_courses)>40:
            all_courses = all_courses[:40]
    return all_courses
示例#8
0
def search(request):
    if request.GET.has_key('format') and request.GET['format']:
        ref = request.META['HTTP_REFERER']
        start = ref.index('?')
        q_string = ref[start:]
        target = "/export/" + request.GET['format'] + "/" + q_string
        return HttpResponseRedirect(target)

    else:
        form = AdvancedSearchForm(request.GET)
        if form.is_valid():
            msg = None
            do_search = False
            for item in form.cleaned_data.values():
                if item and item not in [
                        'Last Name, First', 'Ex: Blood', 'Ex: melanoma', '0',
                        'BLANK'
                ]:
                    do_search = True
            if do_search:
                # results is a QuerySet
                results = search_all(form.cleaned_data)
                #                 print results
                result_count = len(results)
                #                 print result_count

                search_phrase, just_author = build_search_phrase(form)

                if results:
                    paginator = QuerySetPaginator(results, 200)
                    # print paginator

                    try:
                        result_count = paginator.count
                        # print "Result Count: ", result_count
                    except TypeError:
                        #                     result_count = 0
                        if just_author:
                            msg = u'Your search for <em>%s</em> returned no results.  If this is an MSK author, please contact <a href="/comments/" alt="Synapse Comments" title="Synapse Comments">the Synapse Administrators</a>.' % search_phrase
                        else:
                            msg = u'Your search for <em>%s</em> returned no results.  Please broaden your search and try again.' % search_phrase
                        form = AdvancedSearchForm()
                        return render_to_response(
                            'synapse/search.html', {
                                'form': form,
                                'show_dmt': False,
                                'is_internal': is_internal(request),
                                'msg': msg
                            })

#                     full_uri = "/documents/search/?"
#
#                     full_uri = full_uri + request.GET.urlencode()
#                     full_uri = request.path + '?' + request.GET.urlencode()
# TODO: rip request.GET apart, rebuild new URL without the extraneous page terms
                    new_url = {}
                    if request.GET.has_key('author'):
                        if request.GET['author'] != 'Last Name, First':
                            new_url['author'] = request.GET['author']

                    if request.GET.has_key('journal'):
                        if request.GET['journal'] != '':
                            new_url['journal'] = request.GET['journal']

                    if request.GET.has_key('year_start'):
                        if request.GET['year_start'] != 'BLANK':
                            new_url['year_start'] = request.GET['year_start']

                    if request.GET.has_key('year_end'):
                        if request.GET['year_end'] != 'BLANK':
                            new_url['year_end'] = request.GET['year_end']

                    if request.GET.has_key('keywords'):
                        if request.GET['keywords'] != '':
                            new_url['keywords'] = request.GET['keywords']

                    if request.GET.has_key('doc_type'):
                        new_url['doc_type'] = form.cleaned_data['doc_type']

                    results_page = None
                    page = 0
                    if request.GET.has_key('page'):
                        page = int(request.GET['page'])
                    else:
                        page = 1

                    results_page = paginator.page(page)

                    previous = 0
                    next = 0
                    if page > 0:
                        previous = results_page.number - 1
                    next = results_page.number + 1

                    #                     if request.GET.has_key('page'):
                    #                         if request.GET['page'] != '':
                    #                             new_url['page'] = request.GET['page']

                    #                     print "new_url: ", urlencode(new_url, doseq=True)

                    full_uri = '?' + urlencode(new_url, doseq=True)

                    context = {
                        'data': search_phrase,
                        'publications': results_page.object_list,
                        'pages': paginator.num_pages,
                        'page_range': paginator.page_range,
                        'page': results_page.number,
                        'has_next': results_page.has_next(),
                        'has_previous': results_page.has_previous(),
                        'next': next,
                        'previous': previous,
                        'uri': full_uri,
                        'result_count': paginator.count,
                        'is_internal': is_internal(request),
                    }
                    return render_to_response('synapse/results.html', context)
                else:
                    if just_author:
                        msg = u'Your search for <em>%s</em> returned no results.  If this is an MSK author, please contact <a href="/comments/" alt="Synapse Comments" title="Synapse Comments">the Synapse Administrators</a>.' % search_phrase
                    else:
                        msg = u'Your search for <em>%s</em> returned no results.  Please broaden your search and try again.' % search_phrase
                    form = AdvancedSearchForm()
                    return render_to_response(
                        'synapse/search.html', {
                            'form': form,
                            'show_dmt': False,
                            'is_internal': is_internal(request),
                            'msg': msg
                        })

            else:
                msg = u'Please enter at least one search term.'
                form = AdvancedSearchForm()
                return render_to_response(
                    'synapse/search.html', {
                        'form': form,
                        'show_dmt': False,
                        'is_internal': is_internal(request),
                        'msg': msg
                    })
示例#9
0
def search(request):
    if request.GET.has_key('format') and request.GET['format']:
        ref = request.META['HTTP_REFERER']
        start = ref.index('?')
        q_string = ref[start:]
        target = "/export/" + request.GET['format'] + "/" + q_string
        return HttpResponseRedirect(target)


    else:
        form = AdvancedSearchForm(request.GET)
        if form.is_valid():
            msg = None
            do_search = False
            for item in form.cleaned_data.values():
                if item and item not in ['Last Name, First', 'Ex: Blood', 'Ex: melanoma', '0', 'BLANK']:
                    do_search = True
            if do_search:
                # results is a QuerySet
                results = search_all(form.cleaned_data)
#                 print results
                result_count = len(results)
#                 print result_count

                search_phrase, just_author = build_search_phrase(form)
                
                if results:
                    paginator = QuerySetPaginator(results, 200)
                    # print paginator
                    
                    try:
                        result_count = paginator.count
                        # print "Result Count: ", result_count
                    except TypeError:
    #                     result_count = 0
                        if just_author:
                            msg = u'Your search for <em>%s</em> returned no results.  If this is an MSK author, please contact <a href="/comments/" alt="Synapse Comments" title="Synapse Comments">the Synapse Administrators</a>.' % search_phrase
                        else:
                            msg = u'Your search for <em>%s</em> returned no results.  Please broaden your search and try again.' % search_phrase
                        form = AdvancedSearchForm()
                        return render_to_response('synapse/search.html', {'form': form, 'show_dmt': False, 'is_internal': is_internal(request), 'msg':msg })
                        
                    
                    
                        
#                     full_uri = "/documents/search/?"
#     
#                     full_uri = full_uri + request.GET.urlencode()
#                     full_uri = request.path + '?' + request.GET.urlencode()
                    # TODO: rip request.GET apart, rebuild new URL without the extraneous page terms
                    new_url = {}
                    if request.GET.has_key('author'):
                        if request.GET['author'] != 'Last Name, First':
                            new_url['author'] = request.GET['author']
                            
                    if request.GET.has_key('journal'):
                        if request.GET['journal'] != '':
                            new_url['journal'] = request.GET['journal']
                            
                    if request.GET.has_key('year_start'):
                        if request.GET['year_start'] != 'BLANK':
                            new_url['year_start'] = request.GET['year_start']
                            
                    if request.GET.has_key('year_end'):
                        if request.GET['year_end'] != 'BLANK':
                            new_url['year_end'] = request.GET['year_end']
                            
                    if request.GET.has_key('keywords'):
                        if request.GET['keywords'] != '':
                            new_url['keywords'] = request.GET['keywords']
                        
                    if request.GET.has_key('doc_type'):
                        new_url['doc_type'] = form.cleaned_data['doc_type']
                        
                    
                    
                    results_page = None
                    page = 0
                    if request.GET.has_key('page'):
                        page = int(request.GET['page'])
                    else:
                        page = 1
                        
                    results_page = paginator.page(page)
                        
                    previous = 0
                    next = 0
                    if page > 0:
                        previous = results_page.number - 1
                    next = results_page.number + 1
                    
#                     if request.GET.has_key('page'):
#                         if request.GET['page'] != '':
#                             new_url['page'] = request.GET['page']

#                     print "new_url: ", urlencode(new_url, doseq=True)
                    
                    full_uri = '?' + urlencode(new_url, doseq=True)

                    
                    context = {
                            'data': search_phrase,
                            'publications': results_page.object_list,
                            'pages': paginator.num_pages,
                            'page_range':paginator.page_range,
                            'page': results_page.number,
                            'has_next':results_page.has_next(),
                            'has_previous':results_page.has_previous(),
                            'next':next,
                            'previous':previous,
                            'uri':full_uri,
                            'result_count':paginator.count,
                            'is_internal': is_internal(request),
                            }
                    return render_to_response('synapse/results.html', context)
                else:
                    if just_author:
                        msg = u'Your search for <em>%s</em> returned no results.  If this is an MSK author, please contact <a href="/comments/" alt="Synapse Comments" title="Synapse Comments">the Synapse Administrators</a>.' % search_phrase
                    else:
                        msg = u'Your search for <em>%s</em> returned no results.  Please broaden your search and try again.' % search_phrase
                    form = AdvancedSearchForm()
                    return render_to_response('synapse/search.html', {'form': form, 'show_dmt': False, 'is_internal': is_internal(request), 'msg':msg })

            else:
                msg = u'Please enter at least one search term.'
                form = AdvancedSearchForm()
                return render_to_response('synapse/search.html', {'form': form, 'show_dmt': False, 'is_internal': is_internal(request), 'msg':msg })
示例#10
0
def route_search_all(company_id: str):
    query: str = request.args.get("q", "")
    return search.search_all(db, int(company_id), query)