Example #1
0
def record(collid,path):
    res = bibserver.dao.Record.query(q='collection:"' + collid + '" AND citekey:"' + path + '"')
    if res["hits"]["total"] == 0:
        abort(404)
    if res["hits"]["total"] > 1:
        return render_template('record.html', msg="hmmm... there is more than one record in this collection with that id...")
    recorddict = res["hits"]["hits"][0]["_source"]
    return render_template('record.html', record=recorddict)
Example #2
0
def send_collaborate():
    '''
    @todo:index page:
    '''
    return render_template('collaborate/send.html')  
    
    
Example #3
0
def render_results(s, qs, template):
    #qp = qparser.QueryParser("content", s.schema)
    qp = qparser.MultifieldParser(["tgrams", "title"], s.schema)

    # Add the DateParserPlugin to the parser
    qp.add_plugin(DateParserPlugin())

    q = qp.parse(qs)

    results = s.search(q, limit=100, sortedby="title")
    #results = s.search(q, limit=100, sortedby="title", reverse=True)
    #results = s.search(q, limit=100, groupedby="chapter")
    q = results.q

    #hf = highlight.HtmlFormatter()
    #results.highlighter = highlight.Highlighter(formatter=hf)

    qc = None

    def hilite(hit):
        with open(SOURCEDIR + hit["path"], "rb") as hitfile:
            text = hitfile.read().decode("utf-8")
        return hit.highlights("content", text)

    return render_template(template,
                           qs=qs,
                           q=q,
                           results=results,
                           hilite=hilite,
                           corrected=qc,
                           args=request.args)
Example #4
0
def invest_detail():
    '''
    @todo:index page:
    '''
    return render_template(
        'invest/invest_detail.html',
        info=get_one_info('invest', {'_id': request.args.get('_id')})
    )     
Example #5
0
def yellow_page_detail():
    '''
    @todo:index page:
    '''
    return render_template(
        'yellow_page/yellow_page_detail.html',
        info=get_one_info('yellow_page', {'_id': request.args.get('_id')})
    )  
Example #6
0
def teach_detail():
    '''
    @todo:index page:
    '''
    return render_template(
        'teach/teach_detail.html',
        info=get_one_info('teach', {'_id': request.args.get('_id')})
    )  
Example #7
0
def news_detail():
    '''
    @todo:index page:
    '''
    return render_template(
        'news/news_detail.html',
        news=get_one_info('news', {'_id': request.args.get('_id')})
    )    
Example #8
0
def business_detail():
    '''
    @todo:index page:
    '''
    return render_template(
        'business/business_detail.html',
        info=get_one_info('business', {'_id': request.args.get('_id')})
    ) 
Example #9
0
def collaborate_detail():
    '''
    @todo:index page:
    '''
    return render_template(
        'collaborate/collaborate_detail.html',
        info=get_one_info('collaborate', {'_id': request.args.get('_id')})
    )        
Example #10
0
def analyzer():
    with get_searcher() as s:
        fieldname = request.args.get("fieldname")
        q = request.args.get("q", "")
        return render_template("analyzer.html",
                               searcher=s,
                               fieldname=fieldname,
                               q=q)
Example #11
0
def home():
    # get list of available collections
    try:
        result = bibserver.dao.Record.query(q="type.exact:collection",sort={"received.exact":{"order":"desc"}})
        if result["hits"]["total"] != 0:
            colls = [i["_source"]["collection"] for i in result["hits"]["hits"]]
    except:
        colls = None
    return render_template('home/index.html', colls=colls, upload=config["allow_upload"] )
Example #12
0
def settings():
    if session.get('_id', None):
        return render_template(
            'setting.html',
            user=get_one_info("users", {'_id': session.get('_id', None)}),
            provice_list = get_info_list("city", query={'f_id': "0"}, return_type = "list", sort=1),
            city_list = get_info_list("city", query={'f_id': "35"}, return_type = "list", sort=1)
        )
    else:
        return redirect('/')    
Example #13
0
def reg_user_by_form():
    '''
    @todo:注册用户
    '''
    res = reg_user(form2dic(request.form)) 
    if res:
        session.update(set_user_session({}, res))
        return redirect('/')
    else:
       return render_template('info.html', info=u"服务器错误")
Example #14
0
def search(path=''):

    # read args from config and params    
    args = {"terms":{},"facet_fields" : [i + config["facet_field"] for i in config["facet_fields"]]}
    if 'from' in request.values:
        args['start'] = request.values.get('from')
    if 'size' in request.values:
        args['size'] = request.values.get('size')
    if 'sort' in request.values:
        if request.values.get("sort") != "...":
            args['sort'] = {request.values.get('sort')+config["facet_field"] : {"order" : request.values.get('order','asc')}}
    if 'q' in request.values:
        if len(request.values.get('q')) > 0:
            args['q'] = request.values.get('q')
    for param in request.values:
        if param in config["facet_fields"]:
            vals = json.loads(unicodedata.normalize('NFKD',urllib2.unquote(request.values.get(param))).encode('utf-8','ignore'))
            args["terms"][param + config["facet_field"]] = vals
    
    # get implicit facet
    c = {'implicit_facet': {}}
    if path != '' and "search" not in path:
        path = path.strip()
        if path.endswith("/"):
            path = path[:-1]
        bits = path.split('/')
        if len(bits) == 2:
            # its an implicit facet
            args['terms'][bits[0]+config["facet_field"]] = [bits[1]]
            c['implicit_facet'][bits[0]] = bits[1]
        elif len(bits) == 1:
            # send request through as an implicit facet on type, if said type exists
            qry = 'type' + config["facet_field"] + ':' + bits[0]
            check = bibserver.dao.Record.query(q=qry,size=1)
            if check["hits"]["total"] != 0:
                c['implicit_facet']["type"] = bits[0]
                args['terms']["type"+config["facet_field"]] = [bits[0]]
            else:
                # otherwise just show a listing of the facet values for that key
                if 'q' in args:
                    qryval = args['q']
                else:
                    qryval = "*:*"
                result = bibserver.dao.Record.query(q=qryval,facet_fields=[bits[0]+config["facet_field"]])
                vals = result["facets"][bits[0]+config["facet_field"]]["terms"]
                #return render_template('search/listing.html', vals=vals)
        

    # get results and render
    results = bibserver.dao.Record.query(**args)
    args['path'] = path
    c['io'] = bibserver.iomanager.IOManager(results, args)
    return render_template('search/index.html', c=c)
Example #15
0
def register():
    # TODO: re-enable csrf
    form = RegisterForm(request.form, csrf_enabled=False)
    if request.method == 'POST' and form.validate():
        account = dao.Account(id=form.username.data, email=form.email.data)
        account.set_password(form.password.data)
        account.save()
        login_user(account, remember=True)
        flash('Thanks for signing-up', 'success')
        return redirect(url_for('home'))
    if request.method == 'POST' and not form.validate():
        flash('Please correct the errors', 'error')
    return render_template('account/register.html', form=form)
Example #16
0
def login():
    form = LoginForm(request.form, csrf_enabled=False)
    if request.method == 'POST' and form.validate():
        password = form.password.data
        username = form.username.data
        user = dao.Account.get(username)
        if user and user.check_password(password):
            login_user(user, remember=True)
            flash('Welcome back', 'success')
            return redirect(url_for('home'))
        else:
            flash('Incorrect email/password', 'error')
    if request.method == 'POST' and not form.validate():
        flash('Invalid form', 'error')
    return render_template('account/login.html', form=form)
Example #17
0
def homepage():
    """ Render and return the main homepage HTML. 
    """
    versions = {}
    for host in app.config['HOSTS']:
        versions[host['hostname']] = h.get_solr_version(host)

    pool = Pool(processes=len(app.config['HOSTS']))
    pool_data = []
    for core in app.config['CORES']:
        for host in app.config['HOSTS']:
            pool_data.append({'core': core, 'host': host})
    c = h.repackage_details(pool.map(h.get_details, pool_data))
    return render_template('/main.mako', c=c, h=h, 
                           versions=versions, config=app.config)
Example #18
0
def login():
    '''
    @todo:登录
    '''
    user =  vertify_user(
        request.form.get('_id', ''),
        request.form.get('password', '')
    )
    if user:
        session.update(set_user_session({}, user))
        session.permanent = True
        return redirect(request.headers.get("Referer", "/"))
    else:
        session['err_msg'] = u"帐号密码错误"
        if request.form.get("return", None):
            return render_template('login.html',login="******",  info=u"帐号密码错误")
        else:
            return redirect(request.headers.get("Referer", "/"))
Example #19
0
def index():
    '''
    @todo:index page:
    '''
    pages = get_query_page(
        session.get('page', None),
        get_query(request.values, session.get('boot_time', now())),
        session.get('sid'),
        'news'
    )
    return_html = "index.html"
    if request.values.get("ajax", None): 
        return_html = "news/list.html"
    session.update(set_page_session(request.url, pages))
    return render_template(
        return_html,
        pages=pages,
        search_value=request.args.get('title','')
    ) 
Example #20
0
def buy_index():
    pages = get_query_page(
        session.get('page', None),
        get_query(request.values, session.get('boot_time', now())),
        session.get('sid'),
        'buy'
    )
    return_html = "buy/index.html"
    if request.values.get("ajax", None): 
        return_html = "buy/list.html"

    session.update(set_page_session(request.url, pages))
    return render_template(
        return_html,
        pages = pages,
        provice_list = get_info_list("city", query={'f_id': "0"}, return_type = "list", sort=1),
        city_list = get_info_list("city", query={'f_id': "35"}, return_type = "list", sort=1),
        search_value=request.args.get('title','')
        
    )     
Example #21
0
    def post(self):
        pkg = self.package()
        if self.validate(pkg):
            importer = bibserver.importer.Importer()
#            try:
            res = importer.upload(pkg)
            if res != "DUPLICATE":
                if "collection" in pkg:
                    return redirect('/collection/' + pkg["collection"])
                msg = "Your records were uploaded but no collection name could be discerned."
            elif res == "DUPLICATE":
                msg = "The collection name you specified is already in use."
                msg += "<br />Please use another collection name."
            else:
                msg = "Sorry! There was an indexing error. Please try again."                    
#            except:
#                msg = 'Sorry! There was an error indexing your collection. Please try again.'
        else:
            msg = 'Your upload failed to validate. Please try again.'
        return render_template('upload.html', msg=msg)
Example #22
0
 def get(self):
     if request.values.get("source") is not None:
         return self.post()
     return render_template('upload.html')
Example #23
0
def send_invest():
    '''
    @todo:index page:
    '''
    return render_template('invest/send.html')    
Example #24
0
def content(path):
    return render_template('home/content.html', page=path)
Example #25
0
def send_sell():
    '''
    @todo:index page:
    '''

    return render_template('sell/send_sell.html')
Example #26
0
def send_buy():
    '''
    @todo:index page:
    '''

    return render_template('buy/send_buy.html')
Example #27
0
def send_news():
    return render_template('news/send_news.html')
Example #28
0
def lexicon():
    with get_searcher() as s:
        fieldname = request.args.get("fieldname")
        return render_template("lexicon.html",
                               reader=s.reader(),
                               fieldname=fieldname)
Example #29
0
def send_teach():
    '''
    @todo:index page:
    '''

    return render_template('teach/send_teach.html')
Example #30
0
def search():
    return render_template("search.html", args=request.args)
Example #31
0
def send_yellow_page():
    '''
    @todo:index page:
    '''
    return render_template('yellow_page/send.html')    
Example #32
0
def send_business():
    '''
    @todo:index page:
    '''
    return render_template('business/send.html')     
Example #33
0
def render_to():
     return render_template(request.args.get('html'),
            info=eval(request.args.get('info', '{}')),
        )
Example #34
0
def detail_sell():
    return render_template(
        'sell/detail_sell.html',
        info=get_one_info('sell', {'_id': request.args.get('_id')})
      
    )