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 award_index(): # There are no links to this page, but might be wanted later on # Exists only to support award/<result> below set_language_switch_link("award_index") pagename = 'award' art = check_cache(pagename) if art is not None: return art art = computeviews.bucketcall(queryfield='prisbeskrivning', name='award', title='Award', infotext='') return set_cache(art, name=pagename, no_hits=app.config['CACHE_HIT_LIMIT'])
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 search(): set_language_switch_link("search") search = request.args.get('q', '').encode('utf-8') pagename = 'search' + urllib.quote(search) page = check_cache(pagename) if page is not None: return page advanced_search_text = '' if search: show = ','.join( ['name', 'url', 'undertitel', 'undertitel_eng', 'lifespan']) karp_q = { 'highlight': True, 'size': app.config['SEARCH_RESULT_SIZE'], 'show': show } if '*' in search: search = re.sub('(?<!\.)\*', '.*', search) karp_q['q'] = "extended||and|anything|regexp|%s" % search else: karp_q['q'] = "extended||and|anything|contains|%s" % search data = karp_query('minientry', karp_q, mode='skbl') with app.open_resource("static/pages/advanced-search/%s.html" % (g.language)) as f: advanced_search_text = f.read() karp_url = "https://spraakbanken.gu.se/karp/#?mode=skbl&advanced=false&hpp=25&extended=and%7Cnamn%7Cequals%7C&searchTab=simple&page=1&search=simple%7C%7C" + search.decode( "utf-8") else: data = {"hits": {"total": 0, "hits": []}} karp_url = "" search = u'\u200b'.encode('utf8') t = render_template( 'list.html', headline="", subheadline=gettext('Hits for "%s"') % search.decode("UTF-8"), hits_name=data["hits"], hits=data["hits"], advanced_search_text=advanced_search_text.decode("UTF-8"), search=search.decode("UTF-8"), alphabetic=True, karp_url=karp_url, more=data["hits"]["total"] > app.config["SEARCH_RESULT_SIZE"], show_lang_switch=False) return set_cache(t, name=pagename, no_hits=data["hits"]["total"])
def article(id=None): rule = request.url_rule if 'sv' in rule.rule: lang = "sv" else: lang = "en" pagename = 'article_' + id page = check_cache(pagename, lang=lang) if page is not None: return page data = karp_query('query', {'q': "extended||and|url|equals|%s" % (id)}) if data['hits']['total'] == 0: data = karp_query('query', {'q': "extended||and|id.search|equals|%s" % (id)}) set_language_switch_link("article_index", id) page = show_article(data, lang) return set_cache(page, name=pagename, lang=lang, no_hits=1)
def place(place=None): pagename = urllib.quote('place_' + place.encode('utf8')) art = check_cache(pagename) if art is not None: return art lat = request.args.get('lat') lon = request.args.get('lon') set_language_switch_link("place_index", place) hits = karp_query('query', { 'q': "extended||and|plats.searchraw|equals|%s" % (place.encode('utf-8')) }) no_hits = hits['hits']['total'] if no_hits > 0: page = render_template('placelist.html', title=place, lat=lat, lon=lon, headline=place, hits=hits["hits"]) else: page = render_template('page.html', content=gettext('Contents could not be found!')) return set_cache(page, name=pagename, no_hits=no_hits)
def searchresult(result, name='', searchfield='', imagefolder='', query='', searchtype='equals', title='', authorinfo=False, lang='', show_lang_switch=True, cache=True): set_language_switch_link("%s_index" % name, result) try: result = result.encode("UTF-8") pagename = name + '_' + urllib.quote(result) art = check_cache(pagename, lang) if art is not None: return art show = ','.join( ['name', 'url', 'undertitel', 'lifespan', 'undertitel_eng']) if query: hits = karp_query('minientry', {'q': query, 'show': show}) else: hits = karp_query( 'minientry', { 'q': "extended||and|%s.search|%s|%s" % (searchfield, searchtype, result), 'show': show }) title = title or result.decode("UTF-8") no_hits = hits['hits']['total'] if no_hits > 0: picture = None if os.path.exists(app.config.root_path + '/static/images/%s/%s.jpg' % (imagefolder, result)): picture = '/static/images/%s/%s.jpg' % (imagefolder, result) page = render_template('list.html', picture=picture, alphabetic=True, title=title, headline=title, hits=hits["hits"], authorinfo=authorinfo, show_lang_switch=show_lang_switch) if no_hits >= app.config['CACHE_HIT_LIMIT']: try: with mc_pool.reserve() as client: client.set(cache_name(pagename, lang), page, time=app.config['CACHE_TIME']) except: # TODO what to do? pass return page else: return render_template( 'page.html', content=gettext('Contents could not be found!')) except Exception as e: return render_template( 'page.html', content="%s\n%s: extended||and|%s.search|%s|%s" % (e, app.config['KARP_BACKEND'], searchfield, searchtype, result))