From e4c7a3c06751e1fe6866a86eae843786dfbf732e Mon Sep 17 00:00:00 2001 From: amir-zeldes Date: Mon, 10 Jun 2019 16:24:16 -0400 Subject: [PATCH 01/12] Add paging for >100 results * Closes #1 --- css/coptic_dictionary.css | 3 +- results.cgi | 63 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/css/coptic_dictionary.css b/css/coptic_dictionary.css index 5540081..c7954ee 100644 --- a/css/coptic_dictionary.css +++ b/css/coptic_dictionary.css @@ -331,4 +331,5 @@ padding:2px } .orth_table_header > th{font-family: antinoouRegular; padding-left:5px} -.dialect{text-align:center} \ No newline at end of file +.dialect{text-align:center} +.btn-page{margin:10px} \ No newline at end of file diff --git a/results.cgi b/results.cgi index c5141cb..2c31de1 100755 --- a/results.cgi +++ b/results.cgi @@ -8,6 +8,7 @@ import os, platform from helper import wrap, lemma_exists, get_lemmas_for_word from helper import separate_coptic, strip_hyphens from operator import itemgetter +from math import ceil cgitb.enable() print "Content-type: text/html\n" @@ -126,7 +127,9 @@ def retrieve_related(word): return tablestring -def retrieve_entries(word, dialect, pos, definition, def_search_type, def_lang, search_desc=""): +def retrieve_entries(word, dialect, pos, definition, def_search_type, def_lang, search_desc="", params=None): + if params is None: + params = {} sql_command = 'SELECT * FROM entries WHERE ' constraints = [] parameters = [] @@ -229,8 +232,43 @@ def retrieve_entries(word, dialect, pos, definition, def_search_type, def_lang, #return '' return '' elif len(rows) > 100: - tablestring += 'Search had ' + str(len(rows)) + ' results - showing first 100' - rows = rows[:100] + page = 1 if "page" not in params else int(params["page"]) + start = (page-1)*100 + prev_url = next_url = first_url = last_url = "results.cgi?" + args = [] + for param in params: + if params[param] == "" or param == "page": + continue + elif params[param] == "any": + if param in ["pos","dialect","def_lang"]: + continue + elif (param == "related" and str(params[param])=="false") or (param == "def_search_type" and params[param]=="exact sequence") or \ + (param == "def_search_type" and params[param]=="all words"): + continue + args.append(param + "=" + str(params[param])) + last_page = int(ceil(len(rows)/100.0)) + next_url += "&".join(sorted(args + ["page=" + str(page+1)])) + first_url += "&".join(sorted(args + ["page=1"])) + last_url += "&".join(sorted(args + ["page=" + str(last_page)])) + prev_url += "&".join(sorted(args + ["page=" + str(page-1)])) + + if start > 1: + prev_button = ''' Previous''' + first_button = ''' First''' + else: + first_button = ''' First''' + prev_button = ''' Previous''' + if start+100 < len(rows): + end = start+100 + next_button = '''Next ''' + last_button = '''Last ''' + else: + end = len(rows) + last_button = '''Last ''' + next_button = '''Next ''' + tablestring += 'Search had ' + str(len(rows)) + ' results - showing results ' + str(start+1) + ' to ' + str(end) + rows = rows[start:end] + tablestring +="
" + first_button + prev_button + next_button + last_button + "
\n" elif len(rows) == 0 and len(word) > 0: # no matches found tablestring += str(len(rows)) + ' results for ' + word.encode("utf8") + "\n" if lemma_exists(word.encode("utf8")): @@ -279,11 +317,13 @@ def retrieve_entries(word, dialect, pos, definition, def_search_type, def_lang, tablestring += "" tablestring += "\n\n" + return tablestring if __name__ == "__main__": form = cgi.FieldStorage() + params = {} word = cgi.escape(form.getvalue("coptic", "")).replace("(","").replace(")","").replace("=","") dialect = cgi.escape(form.getvalue("dialect", "any")).replace("(","").replace(")","").replace("=","") pos = cgi.escape(form.getvalue("pos", "any")).replace("(","").replace(")","").replace("=","") @@ -292,6 +332,21 @@ if __name__ == "__main__": def_lang = cgi.escape(form.getvalue("lang", "any")).replace("(","").replace(")","").replace("=","") related = cgi.escape(form.getvalue("related", "false")).replace("(","").replace(")","").replace("=","") quick_string = cgi.escape(form.getvalue("quick_search", "")).replace("(","").replace(")","").replace("=","") + page = 1 + page = cgi.escape(form.getvalue("page", "1")).replace("(","").replace(")","").replace("=","") + params["coptic"] = word + params["dialect"] = dialect + params["pos"] = pos + params["definition"] = definition + params["def_search_type"] = def_search_type + params["def_lang"] = def_lang + params["related"] = related + params["quick_search"] = quick_string + try: + page = abs(int(page)) + except: + page = 1 + params["page"] = page if quick_string != "": separated = separate_coptic(quick_string) def_search_type = "all words" @@ -306,7 +361,7 @@ if __name__ == "__main__": definition_desc = " definitions matching " + definition + " in language " + def_lang + "" if len(definition) > 0 else "" pos_desc = " restricted to POS tag " + pos if pos != "any" else "" search_desc = "You searched " + word_desc + dialect_desc + definition_desc + pos_desc - results_page = retrieve_entries(word, dialect, pos, definition, def_search_type, def_lang, search_desc) + results_page = retrieve_entries(word, dialect, pos, definition, def_search_type, def_lang, search_desc,params=params) ### related entry stuff if word != "": # nothing to do if no coptic word searched? From 9fdb8a32de758f1ef19ddb524a4380483bcf66f4 Mon Sep 17 00:00:00 2001 From: amir-zeldes Date: Tue, 11 Jun 2019 13:21:51 -0400 Subject: [PATCH 02/12] Entry layout improvements --- css/coptic_dictionary.css | 48 ++++++++++++++++++++++++++++++++++---- entry.cgi | 15 +++++++----- img/scriptorium.png | Bin 0 -> 762 bytes 3 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 img/scriptorium.png diff --git a/css/coptic_dictionary.css b/css/coptic_dictionary.css index c7954ee..1a93296 100644 --- a/css/coptic_dictionary.css +++ b/css/coptic_dictionary.css @@ -26,7 +26,7 @@ body{ } .anti{font-family: antinoouRegular, sans-serif;} -#orths td{font-family: antinoouRegular, sans-serif;} +#orths td{font-family: antinoouRegular, sans-serif; vertical-align: top;} #results td{font-family: antinoouRegular, sans-serif;} #senses td{font-family: antinoouRegular, sans-serif;} .entrylist td{font-family: antinoouRegular, sans-serif;} @@ -102,7 +102,7 @@ ol{margin: 0px !important} .icon-annis:before { content: "\e608"; font-family: 'annistools'; - color: #6d2020; + color: #AE2124; } @@ -141,9 +141,9 @@ ol{margin: 0px !important} border: 1px solid gray; } -.freq_icon{color: #6d2020; +.freq_icon{color: #AE2124; position: relative; -top: -3px; +top: 6px; } @@ -323,6 +323,8 @@ padding:2px } .annis_link { + vertical-align:top; + text-align:right; color:#9e6a43; } @@ -332,4 +334,40 @@ padding:2px .orth_table_header > th{font-family: antinoouRegular; padding-left:5px} .dialect{text-align:center} -.btn-page{margin:10px} \ No newline at end of file +.btn-page{margin:10px} + +th.annis_link, th.tla_orth_id{color:#333} +table a i.freq-icon{color:#AE2124;} + +td.colloc{text-align:left} + + +.fa-rotate-45 { + top:11px; + font-size:73%; + text-align:left; + color:#AE2124 !important; + -webkit-transform: rotate(45deg); + -moz-transform: rotate(45deg); + -ms-transform: rotate(45deg); + -o-transform: rotate(45deg); + transform: rotate(45deg); +} + +.fa-rotate-315 { + top:-9px; + font-size:73%; + text-align:left; + color:#AE2124 !important; + -webkit-transform: rotate(-45deg); + -moz-transform: rotate(-45deg); + -ms-transform: rotate(-45deg); + -o-transform: rotate(-45deg); + transform: rotate(-45deg); +} + +.scriptorium_logo{height:16px; + width:16px; + top: -2px; + position: relative; + } \ No newline at end of file diff --git a/entry.cgi b/entry.cgi index ad4d282..010b898 100755 --- a/entry.cgi +++ b/entry.cgi @@ -59,7 +59,7 @@ def process_orthstring(orthstring, orefstring, cursor, cs_pos=None): forms = orthstring.split("|||") orefs = orefstring.split("|||") orth_html = '' - orth_html += '' + orth_html += '' for i, form in enumerate(forms): parts = form.split("\n") @@ -82,7 +82,7 @@ def process_orthstring(orthstring, orefstring, cursor, cs_pos=None): geo_string.encode("utf8") + '' + '" target="_new">' freq_data = get_freqs(distinct_orth) freq_info = """
FormDial.TLA form IDPOS ANNIS
FormDial.TLA IDPOS Attestation
' + \ form_id.encode("utf8") + '' + \ gramstring.encode("utf8") + '