def add_or_update_tu(self, tm_id, source, target, allow_multiple=False, overwrite_with_new=True):
     """Adds or updates a source text/target text pair to the specified translation memory."""
     #typeconvert for booleans passed as strings
     allow_multiple = True if str.lower(str(allow_multiple))=='true' else False
     overwrite_with_new = True if str.lower(str(overwrite_with_new))=='true' else False
     user = get_current_username()
     return cherrypy.session.get('tm_provider').add_or_update_tu(tm_id, source, target, user, allow_multiple, overwrite_with_new)
 def save_in_memory_tms_to_db(self, tm_name, sourcelang=None, targetlang=None):
     """Saves all the translation units currently in memory, from all TMs in memory,
         to one new translation memory in the DB."""
     provider = cherrypy.session.get('tm_provider')
     if len(provider.data)==0:
         return {'status' : 'no data currently in memory'}
     owner = get_current_username()
     return provider.create_tm_from_memory(tm_name, sourcelang, targetlang, owner, data)
    def import_file(self, file, tm_name, **kwargs):
        """Starts an upload of a TMX file and then imports its info and translation units
           to the DB.  Runs DB import asynchronously in a background thread and returns immediately after 
           file upload is complete, indicating the status of 'currently loading'"""

        #TODO: validate for empty strings...here and elsewhere
        owner = get_current_username()
        self.bgtask.put(cherrypy.session.get('tm_provider').import_tmx_file, file, tm_name, owner)
        logging.info("importing TMX and loading to DB in subthread")
        status="parsing TMX and loading to DB"
        info = {'filename' : file.filename, 'content-type' : file.content_type.value, 'status' : status}
        return info
 def list_tms(self, **kwargs):
     """Lists the translation memory documents (TMX files) that have been imported into the database
        and are available for loading into memory and searching."""
     user = get_current_username()
     results = cherrypy.session.get('tm_provider').list_tms(user)
     return results