def _memsourceFiles(sessionId): res = "<h2>Memsource projektid/failid</h2>" user = session.getUser(sessionId) token = session.getToken(sessionId) textProjFilter = session.retrieveValue(sessionId, 'textProjFilter') or "" numProjFilter = session.retrieveValue(sessionId, 'numProjFilter') or "" currEngineSpec = session.retrieveValue(sessionId, 'engineSpec') currDom = session.retrieveValue(sessionId, 'domain') #print("DDDDBBBBGGGG", currEngineSpec, currDom) allowedSrcLangs, allowedTgtLangs = getDomLangs(currEngineSpec, currDom) print(allowedSrcLangs, "--", allowedTgtLangs) res += """<p><input type="hidden" name="reqtyp" value="filter"/> <input type="hidden" name="numProjFilter" value=""/> <input type="text" id="textProjFilter" name="textProjFilter" value="{1}" size="90" placeholder="filtreeri projekti nime järgi"/> <input type="submit" value="Filtreeri" name="filterButton"/> </p></form>""".format(numProjFilter, textProjFilter) projects = memsource.getProjects(token, name = textProjFilter, numflt = numProjFilter, srcLangs = allowedSrcLangs, tgtLangs = allowedTgtLangs) #print("DEBUUGGGGG", len(projects['content'])) res += """<form action="/?s={0}" method="post"><input type="hidden" name="reqtyp" value="translate"/>""".format(sessionId) res += """<table border="0" width="800px">""" for p in sorted(projects['content'], key=lambda x: x['internalId']): srcLang = p['sourceLang'] if srcLang in langDesc: srcLang = langDesc[srcLang] jobList = [] if allowedTgtLangs: for tgtLang in _langunion(allowedTgtLangs, p['targetLangs']): fl = memsource.getProjJobs(token, p['uid'], urlext = '&targetLang=' + tgtLang) jobList += fl['content'] else: fl = memsource.getProjJobs(token, p['uid']) jobList = fl['content'] for f in jobList: #print("JOB LOG", f) inId = session.internalFileId(sessionId, p['uid'], f['uid'], [f, p]) if not session.getFileBySKey(sessionId, inId)['mt']: res += "<tr><td width=\"50px\"><input type=\"checkbox\" name=\"cb" + str(inId) + "\"/></td>" tgtLang = f['targetLang'] if tgtLang in langDesc: tgtLang = langDesc[tgtLang] res += "<td><b>" + str(p['internalId']) + "/" + p['name'] + "</b>/" + f['filename'] + " (" + srcLang + "→" + tgtLang + ")</td>" #res += "<td width=\"1\"><a href=\"/viewfile?s={0}&fk={1}\">(MXLF)</a></td>".format(sessionId, inId) res += """</table><input type="submit" value="Tõlgi" name="mtbutton"/></form>""" return res
def _maybeStoreParams(sessionId): if sessionId and 'reqtyp' in request.form and request.form['reqtyp'] == 'filter': oldTr = session.retrieveValue(sessionId, 'translator') for k, v in request.form.items(): if k not in { 'reqtyp', 'filterButton' }: session.storeValue(sessionId, k, v) newTr = session.retrieveValue(sessionId, 'translator') if oldTr != newTr: _reloadDomains(newTr, sessionId)
def translateFileOnBg(sessionId, fileId): f = session.getFileBySKey(sessionId, fileId) f['mt'] = True user = session.getUser(sessionId) translator = session.retrieveValue(sessionId, 'translator') domain = session.retrieveValue(sessionId, 'domain') #this should be impossible to do, but for extra security: if not translator in set(userExtraEngineAccess[user]): raise Exception("AAA, what do we do: " + str(translator) + ", " + str(userExtraEngineAccess[user]) + ".") p = mp.Process(target=translateXml, args=[user, translator, domain, fileId]) p.start()
def _translationEngineSelect(sessionId): username = session.retrieveValue(sessionId, 'username') selectedEngine = session.retrieveValue(sessionId, 'translator') engines = list(enginespecs.userExtraEngineAccess[username]) if len(engines) == 1: return engines[0] + """<input type="hidden" name="translator" value="{0}"/>""".format(engines[0]) else: res = """<select name="translator" id="translator" onchange="fltform.submit()">""" for engine in engines: selectedText = " selected=\"y\"" if engine == selectedEngine else "" res += """<option value="{0}"{1}>{2}</option>""".format(engine, selectedText, _beautifulEngineName(engine)) res += "</select>" return res
def _maybeRenderDomainSelect(sessionId): selectedEngine = session.retrieveValue(sessionId, 'translator') selectedDomain = session.retrieveValue(sessionId, 'domain') spec = session.retrieveValue(sessionId, 'engineSpec') availDomains = spec['domains'] if spec and 'domains' in spec else None if availDomains and selectedDomain: res = """<p>Tekstivaldkond: <select name="domain" id="domain" onchange="fltform.submit()">""" for dom in availDomains: domCode = dom['code'] domName = dom['name'] selTxt = " selected=\"y\"" if domCode == selectedDomain else "" res += """<option value="{0}"{1}>{2}</option>""".format(domCode, selTxt, domName) res += "</select></p>" return res else: return ""