def compute_activity(lang="", cache=True, url=''): set_language_switch_link("activity_index", lang=lang) art, lang = getcache('activity', lang, cache) if art is not None: return art infotext = helpers.get_infotext("activity", request.url_rule.rule) # Fix list with references to be inserted in results reference_list = static_info.activities_reference_list [ref.append("reference") for ref in reference_list] art = bucketcall(queryfield='verksamhetstext', name='activity', title=gettext("Activities"), infotext=infotext, alphabetical=True, description=helpers.get_shorttext(infotext), insert_entries=reference_list, page_url=url) try: with mc_pool.reserve() as client: client.set(cache_name('activity', lang), art, time=app.config['CACHE_TIME']) except: # TODO what to do? pass return art
def keyword_index(): infotext = helpers.get_infotext("keyword", request.url_rule.rule) set_language_switch_link("keyword_index") lang = 'sv' if 'sv' in request.url_rule.rule else 'en' pagename = 'keyword' art = check_cache(pagename, lang=lang) if art is not None: return art if lang == "en": reference_list = [] queryfield = "nyckelord_eng" else: # Fix list with references to be inserted in results reference_list = static_info.keywords_reference_list [ref.append("reference") for ref in reference_list] queryfield = "nyckelord" art = computeviews.bucketcall(queryfield=queryfield, name='keyword', title='Keywords', infotext=infotext, alphabetical=True, insert_entries=reference_list, description=helpers.get_shorttext(infotext)) return set_cache(art, name=pagename, lang=lang, no_hits=app.config['CACHE_HIT_LIMIT'])
def start(): page = check_cache("start") if page is not None: return page infotext = helpers.get_infotext("start", request.url_rule.rule) set_language_switch_link("index") page = render_template('start.html', title="Svenskt kvinnobiografiskt lexikon", infotext=infotext, description=helpers.get_shorttext(infotext)) return set_cache(page)
def more_women(): page = check_cache("morewoman") if page is not None: return page infotext = helpers.get_infotext("more-women", request.url_rule.rule) set_language_switch_link("more-women") page = render_template('more_women.html', women=static_info.more_women, infotext=infotext, linked_from=request.args.get('linked_from'), title=gettext("More women")) return set_cache(page, name="morewoman", no_hits=len(static_info.more_women))
def compute_place(lang="", cache=True, url=''): set_language_switch_link("place_index", lang=lang) art, lang = getcache('place', lang, cache) if art is not None: return art infotext = helpers.get_infotext("place", request.url_rule.rule) def parse(kw): place = kw.get('key') # May be used to parse names with or without coordinates: # "Lysekil" or "Lysekil|58.275573|11.435558" if '|' in place: name, lat, lon = place.split('|') else: name = place.strip() lat, lon = 0, 0 placename = name if name else '%s, %s' % (lat, lon) return { 'name': placename, 'lat': lat, 'lon': lon, 'count': kw.get('doc_count') } def has_name(kw): name = kw.get('key').split('|')[0] if name and u"(osäker uppgift)" not in name: return name else: return None # To use the coordinates, use 'getplaces' instead of 'getplacenames' data = karp_query('getplacenames', {}) stat_table = [parse(kw) for kw in data['places'] if has_name(kw)] art = render_template('places.html', places=stat_table, title=gettext("Placenames"), infotext=infotext, description=helpers.get_shorttext(infotext), page_url=url) try: with mc_pool.reserve() as client: client.set(cache_name('place', lang), art, time=app.config['CACHE_TIME']) except: # TODO what to do? pass return art
def compute_article(lang="", cache=True, url=''): set_language_switch_link("article_index", lang=lang) art, lang = getcache('article', lang, cache) if art is not None: return art show = ','.join( ['name', 'url', 'undertitel', 'lifespan', 'undertitel_eng']) infotext = helpers.get_infotext("article", request.url_rule.rule) if lang == 'sv': data = karp_query('minientry', { 'q': "extended||and|namn|exists", 'show': show, 'sort': 'sorteringsnamn.sort,sorteringsnamn.init,sorteringsnamn,tilltalsnamn.sort,tilltalsnamn' }, mode="skbllinks") else: data = karp_query('minientry', { 'q': "extended||and|namn|exists", 'show': show, 'sort': 'sorteringsnamn.eng_sort,sorteringsnamn.eng_init,sorteringsnamn,tilltalsnamn.sort,tilltalsnamn' }, mode="skbllinks") art = render_template('list.html', hits=data["hits"], headline=gettext(u'Women A-Z'), alphabetic=True, split_letters=True, infotext=infotext, title='Articles', page_url=url) try: with mc_pool.reserve() as client: client.set(cache_name('article', lang), art, time=app.config['CACHE_TIME']) except: # TODO what to do? pass return art
def compute_organisation(lang="", infotext="", cache=True, url=''): set_language_switch_link("organisation_index", lang=lang) art, lang = getcache('organisation', lang, cache) if art is not None: return art infotext = helpers.get_infotext("organisation", request.url_rule.rule) if lang == "en": data = karp_query( 'minientry', { 'q': 'extended||and|anything|regexp|.*', 'show': 'organisationsnamn,organisationstyp_eng' }) typefield = "type_eng" else: data = karp_query( 'minientry', { 'q': 'extended||and|anything|regexp|.*', 'show': 'organisationsnamn,organisationstyp' }) typefield = "type" nested_obj = {} for hit in data['hits']['hits']: for org in hit['_source'].get('organisation', []): orgtype = helpers.unescape(org.get(typefield, '-')) if orgtype not in nested_obj: nested_obj[orgtype] = defaultdict(set) nested_obj[orgtype][org.get('name', '-')].add(hit['_id']) art = render_template('nestedbucketresults.html', results=nested_obj, title=gettext("Organisations"), infotext=infotext, name='organisation', page_url=url) try: with mc_pool.reserve() as client: client.set(cache_name('organisation', lang), art, time=app.config['CACHE_TIME']) except: # TODO what to do? pass return art
def authors(): infotext = helpers.get_infotext("articleauthor", request.url_rule.rule) set_language_switch_link("articleauthor_index") return set_cache( computeviews.compute_artikelforfattare( infotext=infotext, description=helpers.get_shorttext(infotext)))