def do_GET(self):
        """ Handle all GET request """
        try:
            if self.path.endswith("/restaurants"):
                self.send_response(200)
                self.send_header('Content-type', 'text/html')
                self.end_headers()

                output = render_template('../templates/restaurant/index.html')
                self.wfile.write(output)
                return

            if self.path.endswith("/restaurant/new"):
                self.send_response(200)
                self.send_header('Content-Type', 'text/html')
                self.end_headers()

                output = render_template('../templates/restaurant/new.html')
                self.wfile.write(output)
                return

            if self.path.endswith("/edit"):
                self.send_response(200)
                self.send_header('Content-Type', 'text/html')
                self.end_headers()

                output = render_template("../templates/restaurant/edit.html")
                self.wfile.write(output)
                return

        except IOError:
            self.send_response(404, "File Not Found %s" % self.path)
Ejemplo n.º 2
0
def navigation(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    obj = db[path_components]
    #if obj.philo_type == 'doc' and q['doc_page']:
    #    page_text = f.get_page_text(db, obj, q['doc_page'], path, q['byte'])
    #    #page_text = obj.get_page() This does not fetch the right page, just the first page of the object
    #    if page_text:
    #        doc_id = str(obj.philo_id[0]) + ' %'
    #        prev_page, next_page = get_neighboring_pages(db, doc_id, q['doc_page'])    
    #        return render_template(obj=obj,page_text=page_text,prev_page=prev_page,next_page=next_page,
    #                               dbname=dbname,current_page=q['doc_page'],f=f,navigate_doc=navigate_doc,
    #                               db=db,q=q,template_name='pages.mako')
    #    else:
    #        path_components += ['2']
    #        obj = db[path_components]
    #if has_pages(obj, db):
    #    page_num = get_page_num(obj,db)
    #    if page_num:
    #        page_text = f.get_page_text(db, obj, q['doc_page'], path, q['byte'])
    #        if page_text:  ## In case the page does not contain any text
    #            doc_id = str(obj.philo_id[0]) + ' %'
    #            prev_page, next_page = get_neighboring_pages(db, doc_id, page_num)
    #            return render_template(obj=obj,page_text=page_text,prev_page=prev_page,next_page=next_page,
    #                                    dbname=dbname,current_page=page_num,f=f,navigate_doc=navigate_doc,
    #                                    db=db,q=q,template_name='pages.mako')
    if obj.philo_type == 'doc':
        return render_template(obj=obj,philo_id=obj.philo_id[0],dbname=dbname,f=f,navigate_doc=navigate_doc,
                       db=db,q=q,template_name='t_o_c_template.mako')
    obj_text = f.get_text_obj(obj, path, query_args=q['byte'])
    #obj_text = obj_pager(db, obj, obj_text)  ## this creates virtual pages
    prev = ' '.join(obj.prev.split()[:7])
    next = ' '.join(obj.next.split()[:7])
    return render_template(obj=obj,philo_id=obj.philo_id[0],dbname=dbname,f=f,navigate_doc=navigate_doc,
                       db=db,q=q,obj_text=obj_text,prev=prev,next=next,template_name='object.mako')
Ejemplo n.º 3
0
def navigation(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    obj = db[path_components]
    print >> sys.stderr, "OBJ", obj.philo_type
    if obj.philo_type == 'doc' and q['doc_page']:
        page_text = f.get_page_text(db, obj.philo_id[0], q['doc_page'], obj.filename, path, q['byte'])
        if page_text:
            doc_id = str(obj.philo_id[0]) + ' %'
            prev_page, next_page = get_neighboring_pages(db, doc_id, q['doc_page'])    
            return render_template(obj=obj,page_text=page_text,prev_page=prev_page,next_page=next_page,
                                   dbname=dbname,current_page=q['doc_page'],f=f,navigate_doc=navigate_doc,
                                   db=db,q=q,template_name='pages.mako')
        else:
            path_components += ['2']
            obj = db[path_components]
    if has_pages(obj, db):
        page_num = get_page_num(obj,db)
        if page_num:
            page_text = f.get_page_text(db, obj.philo_id[0], page_num, obj.filename, path, '')
            if page_text:  ## In case the page does not contain any text
                doc_id = str(obj.philo_id[0]) + ' %'
                prev_page, next_page = get_neighboring_pages(db, doc_id, page_num)
                return render_template(obj=obj,page_text=page_text,prev_page=prev_page,next_page=next_page,
                                        dbname=dbname,current_page=page_num,f=f,navigate_doc=navigate_doc,
                                        db=db,q=q,template_name='pages.mako')
    if obj.philo_type == 'doc':
        return render_template(obj=obj,philo_id=obj.philo_id[0],dbname=dbname,f=f,navigate_doc=navigate_doc,
                       db=db,q=q,template_name='toc.mako')
    obj_text = f.get_text_obj(obj, path, query_args=q['byte'])
    #obj_text = obj_pager(db, obj, obj_text)  ## this creates virtual pages
    prev = ' '.join(obj.prev.split()[:7])
    next = ' '.join(obj.next.split()[:7])
    return render_template(obj=obj,philo_id=obj.philo_id[0],dbname=dbname,f=f,navigate_doc=navigate_doc,
                       db=db,q=q,obj_text=obj_text,prev=prev,next=next,template_name='object.mako')
Ejemplo n.º 4
0
def navigation(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    path = os.getcwd().replace('functions/', '')
    obj = db[path_components]
    if obj.philo_type == 'doc':
        return render_template(obj=obj,dbname=dbname,f=f,navigate_doc=navigate_doc,db=db,q=q,form=False,template_name='navigation.mako')
    else:
        return render_template(obj=obj,dbname=dbname,f=f,navigate_obj=navigate_obj,db=db,q=q,form=False,template_name='object.mako')
Ejemplo n.º 5
0
def navigation(environ, start_response):
    db, dbname, path_components, q = wsgi_response(environ, start_response)
    path = os.getcwd().replace('functions/', '')
    obj = db[path_components]
    config = f.WebConfig()
    prev = ' '.join(obj.prev.split()[:7])
    next = ' '.join(obj.next.split()[:7])
    current = obj.philo_id[:7]
    if q['format'] == "json":
        if check_philo_virtual(db, path_components):
            obj = db[path_components[:-1]]
        obj_text = f.get_text_obj(obj, path, query_args=q['byte'])
        return json.dumps({
            'current':
            current,
            'text':
            obj_text,
            'prev':
            prev,
            'next':
            next,
            'shrtcit':
            f.cite.make_abs_doc_shrtcit_mobile(db, obj),
            'citation':
            f.cite.make_abs_doc_cite_mobile(db, obj)
        })
    if obj.philo_type == 'doc':
        concatenate_files(path, "t_o_c", debug=db.locals["debug"])
        return render_template(obj=obj,
                               philo_id=obj.philo_id[0],
                               dbname=dbname,
                               f=f,
                               navigate_doc=navigate_doc,
                               db=db,
                               q=q,
                               config=config,
                               template_name='t_o_c.mako',
                               report="t_o_c",
                               ressources=f.concatenate.report_files)
    obj_text = f.get_text_obj(obj, path, query_args=q['byte'])
    concatenate_files(path, "navigation", debug=db.locals["debug"])
    return render_template(obj=obj,
                           philo_id=obj.philo_id[0],
                           dbname=dbname,
                           f=f,
                           navigate_doc=navigate_doc,
                           db=db,
                           q=q,
                           obj_text=obj_text,
                           prev=prev,
                           next=next,
                           config=config,
                           template_name='object.mako',
                           report="navigation",
                           ressources=f.concatenate.report_files)
Ejemplo n.º 6
0
def execute():
    """
    Execute
    :return: {str} Success
    """
    response = False
    try:

        # GET FILES
        get_csv_files = get_files(current_working_directory=CLASS_DATA_FILES_PATH,
                                  extension=CSV_EXTENSION)

        # PROCESS STUDENTS INFORMATION
        class_details_list = process_student_progress(files_path=CLASS_DATA_FILES_PATH, files=get_csv_files)

        # CALCULATE HIGHEST CLASS AVERAGE
        data = calculate_highest_average(data=class_details_list)

        # RENDER TEMPLATE
        rendered_data = render_template(class_details=data, template_path=TEMPLATE_PATH)

        # GENERATE OUTPUT FILE
        generate_output(data=rendered_data, file_path=OUTPUT_FILE_NAME)

        response = True
    except Exception as e:
        print(e)
    return response
Ejemplo n.º 7
0
def bibliography(f,path, db, dbname, q, environ):
    if q["no_q"]:
        hits = db.get_all(db.locals['default_object_level'])
    else:
        hits = db.query(**q["metadata"])
    return render_template(results=hits,db=db,dbname=dbname,q=q, template_name='bibliography.mako',
                           results_per_page=q['results_per_page'], f=f)
Ejemplo n.º 8
0
def render_time_series(hits, db, dbname, q, path, config):
    concatenate_files(path, "time_series", debug=db.locals["debug"])
    biblio_criteria = f.biblio_criteria(q, config, time_series=True)
    frequencies, date_counts = generate_time_series(q, db, hits)
    return render_template(frequencies=frequencies,db=db,dbname=dbname,q=q,f=f, template_name='time_series.mako',
                           biblio_criteria=biblio_criteria, date_counts=date_counts,
                           config=config, total=len(hits),report="time_series", ressources=f.concatenate.report_files)
Ejemplo n.º 9
0
def access(environ, start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    config = f.WebConfig()
    incoming_address = environ['REMOTE_ADDR']
    hostname = socket.gethostname()
    return render_template(db=db,dbname=dbname, config=config,form=True, client_address=incoming_address, q=q,
                           hostname=environ['HTTP_HOST'], report='access', template_name='access_denied.mako')
Ejemplo n.º 10
0
def landing_page(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    config = f.WebConfig()
    path = os.getcwd()
    concatenate_files(path, "landing_page", debug=db.locals["debug"])
    return render_template(db=db,dbname=dbname,form=True, q=q, template_name='landing_page.mako',
                           config=config, report="landing_page", ressources=f.concatenate.report_files)
Ejemplo n.º 11
0
def relevance(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ)
    else:
        results = retrieve_hits(q, db)
    return render_template(results=results,db=db,dbname=dbname,q=q,fetch_relevance=fetch_relevance,f=f,format=format,
                                path=path, results_per_page=q['results_per_page'], template_name='relevance.mako')
Ejemplo n.º 12
0
def concordance(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ)
    else:
        hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
        return render_template(results=hits,db=db,dbname=dbname,q=q,fetch_concordance=fetch_concordance,f=f,
                                path=path, results_per_page=q['results_per_page'], template_name="concordance.mako")
Ejemplo n.º 13
0
def kwic(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ)
    else:
        hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
        return render_template(results=hits,db=db,dbname=dbname,q=q,fetch_kwic=fetch_kwic,f=f,
                                path=path, results_per_page=q['results_per_page'], template_name='kwic.mako')
Ejemplo n.º 14
0
def render_collocation(hits, db, dbname, q, path, config):
    biblio_criteria = f.biblio_criteria(q, config)
    concatenate_files(path, "collocation", debug=db.locals["debug"])
    all_colloc, left_colloc, right_colloc = fetch_collocation(hits, path, q, db)
    hit_len = len(hits)
    return render_template(all_colloc=all_colloc, left_colloc=left_colloc, right_colloc=right_colloc,
                           db=db,dbname=dbname,q=q,f=f,path=path, results_per_page=q['results_per_page'],
                           hit_len=hit_len, order=sort_to_display,dumps=json.dumps,biblio_criteria=biblio_criteria,
                           config=config, template_name='collocation.mako', report="collocation",
                           ressources=f.concatenate.report_files)
def concordance_from_collocation(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ)
    else:
        hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
        return render_template(results=hits,db=db,dbname=dbname,q=q,fetch_colloc_concordance=fetch_colloc_concordance,
                               fetch_concordance=fetch_concordance,f=f,path=path, results_per_page=q['results_per_page'],
                               template_name="concordance_from_collocation.mako")
Ejemplo n.º 16
0
def theme_rheme(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ)
    else:
        hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
        new_hits, full_report = adjust_results(hits, path, q)
        return render_template(results=new_hits,full_report=full_report,db=db,dbname=dbname,q=q,f=f,path=path,
                               results_per_page=q['results_per_page'], template_name="theme_rheme.mako")
Ejemplo n.º 17
0
def pagination(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    doc_page = q['doc_page']
    philo_id = q['philo_id']
    filename = q['filename']
    bytes = q['byte']
    page_text = f.get_page_text(db, philo_id, doc_page, filename, path, bytes)
    prev_page, next_page = get_neighboring_pages(db, philo_id, doc_page)
    return render_template(page_text=page_text,db=db,dbname=dbname,current_page=doc_page,
                           prev_page=prev_page,next_page=next_page,pagination=pagination,
                           filename=filename, philo_id=philo_id,bytes=bytes,template_name="doc_page.mako")
Ejemplo n.º 18
0
def collocation(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ) ## the default should be an error message
    hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
    all_colloc, left_colloc, right_colloc = fetch_collocation(hits, path, q, db)
    hit_len = len(hits)
    return render_template(all_colloc=all_colloc, left_colloc=left_colloc, right_colloc=right_colloc,
                           db=db,dbname=dbname,q=q,link=link_to_concordance,f=f,path=path,
                           results_per_page=q['results_per_page'],hit_len=hit_len,
                           order=sort_to_display,dumps=json.dumps,template_name='collocation.mako')
Ejemplo n.º 19
0
def landing_page(environ, start_response):
    db, dbname, path_components, q = wsgi_response(environ, start_response)
    config = f.WebConfig()
    path = os.getcwd()
    concatenate_files(path, "landing_page", debug=db.locals["debug"])
    return render_template(db=db,
                           dbname=dbname,
                           form=True,
                           q=q,
                           template_name='landing_page.mako',
                           config=config,
                           report="landing_page",
                           ressources=f.concatenate.report_files)
Ejemplo n.º 20
0
def navigation(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    path = os.getcwd().replace('functions/', '')
    obj = db[path_components]
    if obj.philo_type == 'doc':
        return render_template(obj=obj,
                               dbname=dbname,
                               f=f,
                               navigate_doc=navigate_doc,
                               db=db,
                               q=q,
                               form=False,
                               template_name='navigation.mako')
    else:
        return render_template(obj=obj,
                               dbname=dbname,
                               f=f,
                               navigate_obj=navigate_obj,
                               db=db,
                               q=q,
                               form=False,
                               template_name='object.mako')
Ejemplo n.º 21
0
def access(environ, start_response):
    db, dbname, path_components, q = wsgi_response(environ, start_response)
    config = f.WebConfig()
    incoming_address = environ['REMOTE_ADDR']
    hostname = socket.gethostname()
    return render_template(db=db,
                           dbname=dbname,
                           config=config,
                           form=True,
                           client_address=incoming_address,
                           q=q,
                           hostname=environ['HTTP_HOST'],
                           report='access',
                           template_name='access_denied.mako')
Ejemplo n.º 22
0
def fetch_bibliography(f,path, db, dbname, q, environ):
    if q["no_q"]:
        hits = db.get_all(db.locals['default_object_level'])
    else:
        hits = db.query(**q["metadata"])
    if q['format'] == "json":
        return hits
    else:
        concatenate_files(path, "bibliography", debug=db.locals["debug"])
        config = f.WebConfig()
        biblio_criteria = f.biblio_criteria(q, config)
        return render_template(results=hits,db=db,dbname=dbname,q=q, template_name='bibliography.mako',
                           results_per_page=q['results_per_page'], f=f, biblio_criteria=biblio_criteria,
                           config=config, report="bibliography", ressources=f.concatenate.report_files)
Ejemplo n.º 23
0
def navigation(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    obj = db[path_components]
    config = f.WebConfig()
    prev = ' '.join(obj.prev.split()[:7])
    next = ' '.join(obj.next.split()[:7])
    current = obj.philo_id[:7]
    if q['format'] == "json":
        if check_philo_virtual(db, path_components):
            obj = db[path_components[:-1]]
        obj_text = f.get_text_obj(obj, path, query_args=q['byte'])
        return json.dumps({'current': current, 'text': obj_text, 'prev': prev, 'next': next, 'shrtcit':  f.cite.make_abs_doc_shrtcit_mobile(db,obj), 'citation': f.cite.make_abs_doc_cite_mobile(db,obj)})
    if obj.philo_type == 'doc':
        concatenate_files(path, "t_o_c", debug=db.locals["debug"])
        return render_template(obj=obj,philo_id=obj.philo_id[0],dbname=dbname,f=f,navigate_doc=navigate_doc,
                       db=db,q=q,config=config,template_name='t_o_c.mako', report="t_o_c",
                       ressources=f.concatenate.report_files)
    obj_text = f.get_text_obj(obj, path, query_args=q['byte'])
    concatenate_files(path, "navigation", debug=db.locals["debug"])
    return render_template(obj=obj,philo_id=obj.philo_id[0],dbname=dbname,f=f,navigate_doc=navigate_doc,
                       db=db,q=q,obj_text=obj_text,prev=prev,next=next,config=config,
                       template_name='object.mako', report="navigation", ressources=f.concatenate.report_files)
Ejemplo n.º 24
0
def render_concordance(hits, db, dbname, q, path, config):
    concatenate_files(path, "concordance", debug=db.locals["debug"])
    biblio_criteria = f.biblio_criteria(q, config)
    return render_template(results=hits,
                           db=db,
                           dbname=dbname,
                           q=q,
                           fetch_concordance=fetch_concordance,
                           f=f,
                           path=path,
                           results_per_page=q['results_per_page'],
                           biblio_criteria=biblio_criteria,
                           config=config,
                           template_name="concordance.mako",
                           report="concordance",
                           ressources=f.concatenate.report_files)
Ejemplo n.º 25
0
def theme_rheme(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f, path, db, dbname, q, environ)
    else:
        hits = db.query(q["q"], q["method"], q["arg"], **q["metadata"])
        new_hits, full_report = adjust_results(hits, path, q)
        return render_template(results=new_hits,
                               full_report=full_report,
                               db=db,
                               dbname=dbname,
                               q=q,
                               f=f,
                               path=path,
                               results_per_page=q['results_per_page'],
                               template_name="theme_rheme.mako")
Ejemplo n.º 26
0
def frequency(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
    if q["format"] == "json":
        # if we have a json report, directly dump the table in a json wrapper.
        # if you want to change the URL value of a key, do it in generate_frequency() below.
        field, counts = generate_frequency(hits,q,db)

        l = len(counts)
        wrapper = {"length":l,"result":[],"field":field}
        for label,count,url in counts:
            table_row = {"label":label,"count":count,"url":url}
            wrapper["result"].append(table_row)
        return json.dumps(wrapper,indent=1)
        
    else:
        return render_template(results=hits,db=db,dbname=dbname,q=q,generate_frequency=generate_frequency,f=f, template_name='frequency.mako')
Ejemplo n.º 27
0
def collocation(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f, path, db, dbname, q,
                            environ)  ## the default should be an error message
    else:
        hits = db.query(q["q"], q["method"], q["arg"], **q["metadata"])
    return render_template(results=hits,
                           db=db,
                           dbname=dbname,
                           q=q,
                           fetch_collocation=fetch_collocation,
                           link=link_to_concordance,
                           f=f,
                           path=path,
                           results_per_page=q['results_per_page'],
                           template_name='collocation.mako')
Ejemplo n.º 28
0
def frequencies(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    print >> sys.stderr, "Q",q
    path = os.getcwd().replace('functions/', '')
#    results = prominent_features(q, db)
    res = ""
    count = 0;
    res = []
    for result in make_frequency_query(db,q["metadata"]):
#        print >> sys.stderr,result
        res.append(result)
        count += 1;
        if count > 1000:
            break
    #hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
    #return render_template(results=hits,db=db,dbname=dbname,q=q,fetch_concordance=fetch_concordance,
    #                       f=f, path=path, results_per_page=q['results_per_page'],
    #                       template_name="concordance.mako")
    return render_template(results=res,db=db,dbname=dbname,q=q,f=f,template_name="frequencies.mako", report="frequencies")
def concordance_from_collocation(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    config = f.WebConfig()
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ)
    else:
        hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
        colloc_results = fetch_colloc_concordance(hits, path, q, db, config)
        biblio_criteria = []
        for k,v in q["metadata"].iteritems():
            if v:
                if k in config.metadata_aliases:
                    k = config.metadata_aliases[k]
                biblio_criteria.append('<span class="biblio_criteria">%s: <b>%s</b></span>' % (k.title(), v.decode('utf-8', 'ignore'), ))
        biblio_criteria = ' '.join(biblio_criteria)
        concatenate_files(path, "concordance_from_collocation", debug=db.locals["debug"])
        return render_template(results=colloc_results,db=db,dbname=dbname,q=q,colloc_concordance=colloc_concordance,
                               f=f,path=path, results_per_page=q['results_per_page'], config=config,report="concordance_from_collocation",
                               biblio_criteria=biblio_criteria, template_name="concordance_from_collocation.mako",
                               ressources=f.concatenate.report_files)
Ejemplo n.º 30
0
def fetch_bibliography(f, path, db, dbname, q, environ):
    if q["no_q"]:
        hits = db.get_all(db.locals['default_object_level'])
    else:
        hits = db.query(**q["metadata"])
    if q['format'] == "json":
        return hits
    else:
        concatenate_files(path, "bibliography", debug=db.locals["debug"])
        config = f.WebConfig()
        biblio_criteria = f.biblio_criteria(q, config)
        return render_template(results=hits,
                               db=db,
                               dbname=dbname,
                               q=q,
                               template_name='bibliography.mako',
                               results_per_page=q['results_per_page'],
                               f=f,
                               biblio_criteria=biblio_criteria,
                               config=config,
                               report="bibliography",
                               ressources=f.concatenate.report_files)
Ejemplo n.º 31
0
def render_collocation(hits, db, dbname, q, path, config):
    biblio_criteria = f.biblio_criteria(q, config)
    concatenate_files(path, "collocation", debug=db.locals["debug"])
    all_colloc, left_colloc, right_colloc = fetch_collocation(
        hits, path, q, db)
    hit_len = len(hits)
    return render_template(all_colloc=all_colloc,
                           left_colloc=left_colloc,
                           right_colloc=right_colloc,
                           db=db,
                           dbname=dbname,
                           q=q,
                           f=f,
                           path=path,
                           results_per_page=q['results_per_page'],
                           hit_len=hit_len,
                           order=sort_to_display,
                           dumps=json.dumps,
                           biblio_criteria=biblio_criteria,
                           config=config,
                           template_name='collocation.mako',
                           report="collocation",
                           ressources=f.concatenate.report_files)
Ejemplo n.º 32
0
def frequency(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    hits = db.query(q["q"], q["method"], q["arg"], **q["metadata"])
    if q["format"] == "json":
        # if we have a json report, directly dump the table in a json wrapper.
        # if you want to change the URL value of a key, do it in generate_frequency() below.
        field, counts = generate_frequency(hits, q, db)

        l = len(counts)
        wrapper = {"length": l, "result": [], "field": field}
        for label, count, url in counts:
            table_row = {"label": label, "count": count, "url": url}
            wrapper["result"].append(table_row)
        return json.dumps(wrapper, indent=1)

    else:
        return render_template(results=hits,
                               db=db,
                               dbname=dbname,
                               q=q,
                               generate_frequency=generate_frequency,
                               f=f,
                               template_name='frequency.mako')
def concordance_from_collocation(environ, start_response):
    db, dbname, path_components, q = wsgi_response(environ, start_response)
    path = os.getcwd().replace('functions/', '')
    config = f.WebConfig()
    if q['q'] == '':
        return bibliography(f, path, db, dbname, q, environ)
    else:
        hits = db.query(q["q"], q["method"], q["arg"], **q["metadata"])
        colloc_results = fetch_colloc_concordance(hits, path, q, db, config)
        biblio_criteria = []
        for k, v in q["metadata"].iteritems():
            if v:
                if k in config.metadata_aliases:
                    k = config.metadata_aliases[k]
                biblio_criteria.append(
                    '<span class="biblio_criteria">%s: <b>%s</b></span>' % (
                        k.title(),
                        v.decode('utf-8', 'ignore'),
                    ))
        biblio_criteria = ' '.join(biblio_criteria)
        concatenate_files(path,
                          "concordance_from_collocation",
                          debug=db.locals["debug"])
        return render_template(
            results=colloc_results,
            db=db,
            dbname=dbname,
            q=q,
            colloc_concordance=colloc_concordance,
            f=f,
            path=path,
            results_per_page=q['results_per_page'],
            config=config,
            report="concordance_from_collocation",
            biblio_criteria=biblio_criteria,
            template_name="concordance_from_collocation.mako",
            ressources=f.concatenate.report_files)
Ejemplo n.º 34
0
def render_kwic(hits, db, dbname, q, path, config):
    biblio_criteria = f.biblio_criteria(q, config)
    concatenate_files(path, "kwic", debug=db.locals["debug"])
    return render_template(results=hits,db=db,dbname=dbname,q=q,fetch_kwic=fetch_kwic,f=f,
                                path=path, results_per_page=q['results_per_page'], biblio_criteria=biblio_criteria,
                                config=config, template_name='kwic.mako', report="kwic", ressources=f.concatenate.report_files)
Ejemplo n.º 35
0
def bibliography(f,path, db, dbname, q, environ):
    if q["no_q"]:
        hits = db.get_all("doc")
    else:
        hits = db.query(**q["metadata"])
    return render_template(results=hits,db=db,dbname=dbname,q=q, template_name='bibliography.mako',f=f)
Ejemplo n.º 36
0
def form(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    return render_template(db=db,dbname=dbname,form=True, template_name='form.mako')
Ejemplo n.º 37
0
def render_concordance(hits, db, dbname, q, path, config):
    concatenate_files(path, "concordance", debug=db.locals["debug"])
    biblio_criteria = f.biblio_criteria(q, config)
    return render_template(results=hits,db=db,dbname=dbname,q=q,fetch_concordance=fetch_concordance,
                               f=f, path=path, results_per_page=q['results_per_page'],biblio_criteria=biblio_criteria,
                               config=config,template_name="concordance.mako", report="concordance", ressources=f.concatenate.report_files)
Ejemplo n.º 38
0
def form(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    return render_template(db=db,
                           dbname=dbname,
                           form=True,
                           template_name='form.mako')
Ejemplo n.º 39
0
def time_series(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    frequencies, relative_frequencies = generate_frequency(q, db)
    #frequencies, relative_frequencies = time_frequency(q, db)
    return render_template(frequencies=frequencies,relative_frequencies=relative_frequencies,
                           db=db,dbname=dbname,q=q,f=f, template_name='time_series.mako')
def collocation(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ) ## the default should be an error message
    else:
        hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
    return render_template(results=hits,db=db,dbname=dbname,q=q,fetch_collocation=fetch_collocation,link=link_to_concordance,
                           f=f,path=path, results_per_page=q['results_per_page'], template_name='collocation.mako')