Exemplo n.º 1
0
 def save(self):
     """Update OLD Keyword with newly altered data."""
     # Check whether the user is updating a keyword to have a
     #  name that is the same as another keyword and redisplay
     #  the form with an error message if so.  This should be
     #  done by the Schema, but I couldn't figure out how.
     otherKeywordsWithSameName = meta.Session.query(model.Keyword).filter(
         model.Keyword.id != self.form_result['ID']).filter(
             model.Keyword.name == self.form_result['name']).all()
     if otherKeywordsWithSameName:
         c.keyword = meta.Session.query(model.Keyword).get(
             int(self.form_result['ID']))
         html = render('/derived/tag/keyword/edit.html')
         errors = {'name': 'Sorry, that name is already taken'}
         values = {
             'ID': self.form_result['ID'],
             'name': self.form_result['name'],
             'description': self.form_result['description']
         }
         return htmlfill.render(html, defaults=values, errors=errors)
     keyword_q = meta.Session.query(model.Keyword)
     keyword = keyword_q.get(int(self.form_result['ID']))
     keyword.name = h.NFD(self.form_result['name'])
     keyword.description = h.NFD(self.form_result['description'])
     # Update the data
     meta.Session.commit()
     # Update the keywords variable in app_globals
     tags = h.getSecondaryObjects(['keywords'])
     app_globals.keywords = tags['keywords']
     # Issue an HTTP redirect
     response.status_int = 302
     response.headers['location'] = url(controller='key',
                                        action='view',
                                        id=keyword.id)
     return "Moved temporarily"
Exemplo n.º 2
0
 def create(self):
     """Insert new Source data into database."""
     source = model.Source()
     source.authorFirstName = h.NFD(self.form_result['authorFirstName'])
     source.authorLastName = h.NFD(self.form_result['authorLastName'])
     source.title = h.NFD(self.form_result['title'])
     source.year = self.form_result['year']
     source.fullReference = h.NFD(self.form_result['fullReference'])
     fileID = self.form_result['file_id']
     if fileID:
         file = meta.Session.query(model.File).get(int(fileID))
         if file:
             source.file = file
         else:
             html = render('/derived/source/add.html')
             values = self.form_result
             errors = {'file_id': 'There is no file with ID %s' % fileID}
             return htmlfill.render(html, defaults=values, errors=errors)
     # Enter the data
     meta.Session.add(source)
     meta.Session.commit()
     # Update the users variable in app_globals
     tags = h.getSecondaryObjects(['sources'])
     app_globals.sources = tags['sources']
     # Issue an HTTP redirect
     response.status_int = 302
     response.headers['location'] = url(controller='source',
                                        action='view',
                                        id=source.id)
     return "Moved temporarily"
Exemplo n.º 3
0
def getResearcherAttributes(researcher, result, createOrSave):
    researcher.username = h.NFD(result['username'])
    researcher.firstName = h.NFD(result['firstName'])
    researcher.lastName = h.NFD(result['lastName'])
    researcher.email = result['email']
    researcher.affiliation = h.NFD(result['affiliation'])
    researcher.personalPageContent = h.NFD(result['personalPageContent'])
    researcher.role = result['role']

    # Only update the password if something was added
    if result['password']:
        researcher.password = hashlib.sha224(result['password']).hexdigest()
Exemplo n.º 4
0
def getCollectionAttributes(collection, result, createOrSave):
    """Given a (SQLAlchemy) Collection object and a result dictionary populated
    by user-entered data, this function populates the appropriate attributes
    with the appropriate values.  This function is called by both create and
    save actions.
    
    """

    # User-entered Data
    collection.title = h.NFD(result['title'])
    collection.type = h.NFD(result['type'])
    collection.url = h.NFD(result['url'])
    collection.description = h.NFD(result['description'])
    if result['speaker']:
        collection.speaker = meta.Session.query(model.Speaker).get(
            int(result['speaker']))
    if result['elicitor']:
        collection.elicitor = meta.Session.query(model.User).get(
            int(result['elicitor']))
    if result['source']:
        collection.source = meta.Session.query(model.Source).get(
            int(result['source']))
    if result['dateElicited']:
        collection.dateElicited = result['dateElicited']

    # OLD-generated Data
    now = datetime.datetime.utcnow()
    collection.datetimeModified = now

    if createOrSave == 'create':
        collection.datetimeEntered = now
        # Add the Enterer as the current user
        collection.enterer = meta.Session.query(model.User).get(
            int(session['user_id']))

    # Extract component Forms from the collection objects contents field and
    #  append them to collection.forms
    collection.forms = []
    collection.contents = h.NFD(result['contents'])
    patt = re.compile('[Ff]orm\[([0-9]+)\]')
    formIDs = patt.findall(collection.contents)
    for formID in formIDs:
        form = meta.Session.query(model.Form).get(int(formID))
        if form:
            collection.forms.append(form)

    return collection
Exemplo n.º 5
0
 def create(self):
     """Insert new Keyword data into database."""
     keyword = model.Keyword()
     keyword.name = h.NFD(self.form_result['name'])
     keyword.description = h.NFD(self.form_result['description'])
     # Enter the data
     meta.Session.add(keyword)
     meta.Session.commit()
     # Update the keywords variable in app_globals
     tags = h.getSecondaryObjects(['keywords'])
     app_globals.keywords = tags['keywords']
     # Issue an HTTP redirect
     response.status_int = 302
     response.headers['location'] = url(controller='key',
                                        action='view',
                                        id=keyword.id)
     return "Moved temporarily"
Exemplo n.º 6
0
 def create(self):
     """Insert new ElicitationMethod data into database."""
     elicitationMethod = model.ElicitationMethod()
     elicitationMethod.name = h.NFD(self.form_result['name'])
     elicitationMethod.description = h.NFD(self.form_result['description'])
     # Enter the data
     meta.Session.add(elicitationMethod)
     meta.Session.commit()
     # Update the syncats variable in app_globals
     tags = h.getSecondaryObjects(['elicitationMethods'])
     app_globals.elicitationMethods = tags['elicitationMethods']
     # Issue an HTTP redirect
     response.status_int = 302
     response.headers['location'] = url(controller='method',
                                        action='view',
                                        id=elicitationMethod.id)
     return "Moved temporarily"
Exemplo n.º 7
0
 def create(self):
     """Insert new Speaker data into database."""
     speaker = model.Speaker()
     speaker.firstName = h.NFD(self.form_result['firstName'])
     speaker.lastName = h.NFD(self.form_result['lastName'])
     speaker.dialect = h.NFD(self.form_result['dialect'])
     speaker.speakerPageContent = h.NFD(self.form_result['speakerPageContent'])
     # Enter the data
     meta.Session.add(speaker)
     meta.Session.commit()
     # Update the speaker variable in app_globals
     tags = h.getSecondaryObjects(['speakers'])
     app_globals.speakers = tags['speakers']
     # Issue an HTTP redirect
     response.status_int = 302
     response.headers['location'] = url(controller='speaker', action='view', id=speaker.id)
     return "Moved temporarily"           
Exemplo n.º 8
0
 def save(self):
     """Update OLD Speaker with newly altered data."""
     speaker_q = meta.Session.query(model.Speaker)
     speaker = speaker_q.get(int(self.form_result['ID']))        
     speaker.firstName = h.NFD(self.form_result['firstName'])
     speaker.lastName = h.NFD(self.form_result['lastName'])
     speaker.dialect = h.NFD(self.form_result['dialect'])
     speaker.speakerPageContent = h.NFD(self.form_result['speakerPageContent'])
     # Update the data
     meta.Session.commit()
     # Update the speaker variable in app_globals
     tags = h.getSecondaryObjects(['speakers'])
     app_globals.speakers = tags['speakers']
     # Issue an HTTP redirect
     response.status_int = 302
     response.headers['location'] = url(controller='speaker', action='view', id=speaker.id)
     return "Moved temporarily"    
Exemplo n.º 9
0
    def create(self):
        """Insert new Category data into database.

        """

        category = model.SyntacticCategory()
        category.name = h.NFD(self.form_result['name'])
        category.description = h.NFD(self.form_result['description'])
        # Enter the data
        meta.Session.add(category)
        meta.Session.commit()
        # Update the syncats variable in app_globals
        tags = h.getSecondaryObjects(['syncats'])
        app_globals.syncats = tags['syncats']
        # Issue an HTTP redirect
        response.status_int = 302
        response.headers['location'] = url(controller='category',
                                           action='view',
                                           id=category.id)
        return "Moved temporarily"
Exemplo n.º 10
0
def getFileAttributes(file, result, fileSize, fileName, createOrSave):
    """Given a (SQLAlchemy) File object, a result dictionary populated by
    user-entered data and a fileSize calculated in the create action, this
    function populates the appropriate attributes with the appropriate values.
    Function called by both create and save actions.
    
    """

    # User-entered Data
    file.description = h.NFD(result['description'])
    # Recording-only Data
    if result['speaker']:
        file.speaker = meta.Session.query(model.Speaker).get(
            int(result['speaker']))
    else:
        file.speaker = None
    if result['elicitor']:
        file.elicitor = meta.Session.query(model.User).get(
            int(result['elicitor']))
    else:
        file.elicitor = None
    file.dateElicited = result['dateElicited']
    file.utteranceType = result['utteranceType']
    if createOrSave == 'create':
        # Data extracted from uploaded file
        fileData = request.POST['fileData']
        file.MIMEtype = guess_type(fileData.filename)[0]
        file.size = fileSize
        file.name = h.NFD(fileName).replace("'", "").replace('"', '')
        file.pathName = os.path.join(config['app_conf']['permanent_store'],
                                     fileName)
        # Add the Enterer as the current user
        file.enterer = meta.Session.query(model.User).get(
            int(session['user_id']))
    # OLD-generated Data
    now = datetime.datetime.utcnow()
    if createOrSave == 'create':
        file.datetimeEntered = now
    file.datetimeModified = now
    return file
Exemplo n.º 11
0
    def save(self):
        """Update OLD Home Page with newly altered data.
        
        """

        # Get the homepage from the model
        homepage_q = meta.Session.query(model.Page).filter(
            model.Page.name==u'home')
        homepage = homepage_q.first()
        if homepage is None:
            abort(404)
            
        homepage.name = h.NFD(self.form_result['name'])
        homepage.heading = h.NFD(self.form_result['heading'])
        homepage.content = h.NFD(self.form_result['content'])
        
        # Update the data
        meta.Session.commit()

        # Issue an HTTP redirect
        response.status_int = 302
        response.headers['location'] = url(controller='home', action='index')
        return "Moved temporarily"
Exemplo n.º 12
0
    def translate(self):
        """Take a string (input) and translate it from the inputOrthography to
        the output orthography.  This action is called asynchronously when the
        'Translate' button is clicked on the /settings/orthography page.

        """

        # Get the GET values
        values = dict(request.params)
        inputOrthography = values['inputOrthography']
        outputOrthography = values['outputOrthography']
        input = h.NFD(values['input'])

        # Create the translator object
        inputOrthography = app_globals.OLOrthographies[inputOrthography][1]
        outputOrthography = app_globals.OLOrthographies[outputOrthography][1]

        try:
            translator = h.OrthographyTranslator(inputOrthography,
                                                 outputOrthography)
            return translator.translate(input)
        except h.OrthographyCompatibilityError:
            return """Sorry, there is a problem with the selected orthographies.
Exemplo n.º 13
0
    def normalizeNFDEverything(self):
        """NFD normalize all relevant data in the database.

        """

        response.headers['Content-Type'] = 'application/json'

        saveState('normalizeNFDEverythingStatus', {
            'statusMsg': 'Normalization has begun.',
            'complete': False
        })

        forms = meta.Session.query(model.Form).all()

        for i in range(len(forms)):
            form = forms[i]
            form.transcription = h.NFD(form.transcription)
            try:
                form.phoneticTranscription = h.NFD(form.phoneticTranscription)
            except TypeError:
                pass
            try:
                form.narrowPhoneticTranscription = h.NFD(
                    form.narrowPhoneticTranscription)
            except TypeError:
                pass
            form.morphemeBreak = h.NFD(form.morphemeBreak)
            form.morphemeGloss = h.NFD(form.morphemeGloss)
            form.comments = h.NFD(form.comments)
            form.speakerComments = h.NFD(form.speakerComments)
            form.context = h.NFD(form.context)
            try:
                form.syntacticCategoryString = h.NFD(
                    form.syntacticCategoryString)
            except TypeError:
                pass
            try:
                form.morphemeBreakIDs = h.NFD(form.morphemeBreakIDs)
            except TypeError:
                pass
            try:
                form.morphemeGlossIDs = h.NFD(form.morphemeGlossIDs)
            except TypeError:
                pass
            try:
                form.breakGlossCategory = h.NFD(form.breakGlossCategory)
            except TypeError:
                pass
            for gloss in form.glosses:
                gloss.gloss = h.NFD(gloss.gloss)

            if i != 0 and i % 100 == 0:
                saveState('normalizeNFDEverythingStatus', {
                    'statusMsg': '%d forms normalized.' % i,
                    'complete': False
                })
                meta.Session.commit()

        meta.Session.commit()

        files = meta.Session.query(model.File).all()

        for i in range(len(files)):
            file = files[i]
            file.name = h.NFD(file.name)
            file.description = h.NFD(file.description)
            if i != 0 and i % 100 == 0:
                saveState('normalizeNFDEverythingStatus', {
                    'statusMsg': '%d files normalized.' % i,
                    'complete': False
                })
                meta.Session.commit()

        meta.Session.commit()

        collections = meta.Session.query(model.Collection).all()

        for i in range(len(collections)):
            collection = collections[i]
            collection.title = h.NFD(collection.title)
            collection.type = h.NFD(collection.type)
            if collection.url:
                collection.url = h.NFD(collection.url)
            collection.description = h.NFD(collection.description)
            collection.contents = h.NFD(collection.contents)

            if i != 0 and i % 100 == 0:
                saveState(
                    'normalizeNFDEverythingStatus', {
                        'statusMsg': '%d collections normalized.' % i,
                        'complete': False
                    })
                meta.Session.commit()

        meta.Session.commit()

        saveState(
            'normalizeNFDEverythingStatus', {
                'statusMsg': 'All forms, files and collections normalized.',
                'complete': True
            })
Exemplo n.º 14
0
 def NFDFixes(string, regex):
     string = h.NFD(string)
     patt = re.compile(regex)
     if patt.match(string):
         return True
     return False
Exemplo n.º 15
0
    def testvalidation(self):
        response.headers['Content-Type'] = 'application/json'
        validationId = dict(request.params)['validationId']

        appSettings = meta.Session.query(model.ApplicationSettings).order_by(
            desc(model.ApplicationSettings.id)).first()

        # Get the appropriate Inventory object for validation from app_globals
        #  These objects are saved by functions/applicationSettingsToAppGlobals
        #  when the application settings are saved
        if validationId == u'testOrthographicValidation':
            inventory = app_globals.orthTranscrInvObj
            fieldName = u'transcription'
        elif validationId == u'testNarrPhonValidation':
            inventory = app_globals.narrPhonInvObj
            fieldName = u'narrowPhoneticTranscription'
        elif validationId == u'testBroadPhonValidation':
            inventory = app_globals.broadPhonInvObj
            fieldName = u'phoneticTranscription'
        elif validationId in [
                u'testMorphophonValidation', u'testOrthographicMBValidation'
        ]:
            inventory = app_globals.morphBreakInvObj
            fieldName = u'morphemeBreak'

        # regex is the regular expression that valid fields will match
        regex = inventory.getRegexValidator()

        # NFDFixes returns True if unicode canonical decompositional
        #  normalization makes the data valid
        def NFDFixes(string, regex):
            string = h.NFD(string)
            patt = re.compile(regex)
            if patt.match(string):
                return True
            return False

        # Count the forms in the db
        formCount = meta.Session.query(model.Form).count()

        # Get the invalid forms using regex and SQLAlchemy
        invalidForms = meta.Session.query(model.Form).filter(
            not_(getattr(model.Form, fieldName).op('regexp')(regex))).all()

        # Build the result to return to the user
        result = {
            'formCount': formCount,
            'invalidCount': len(invalidForms),
            'NFDFixes': 0,
            'invalid': [],
            'validationInventory': inventory.inputList
        }

        for f in invalidForms:
            if NFDFixes(getattr(f, fieldName), regex):
                result['NFDFixes'] += 1
            else:
                result['invalid'].append([
                    f.id,
                    h.NFD(getattr(f, fieldName)),
                    h.getUnicodeCodePoints(h.NFD(getattr(f, fieldName)))
                ])

        return json.dumps(result)
Exemplo n.º 16
0
 def getCharacterCodesAndNames(self):
     input = h.NFD(dict(request.params)['input'])
     response.headers['Content-Type'] = 'application/json'
     return json.dumps(
         (h.getUnicodeCodePoints(input), h.getUnicodeNames(input)))
Exemplo n.º 17
0
                result = getattr(form_result, propertyName, None)
                if not result:
                    return u'Orthography 1'
                return orthId

            appSet.storageOrthography = assignOrthographyIfDefined(
                self.form_result['storageOrthography'], self.form_result)
            appSet.defaultInputOrthography = assignOrthographyIfDefined(
                self.form_result['defaultInputOrthography'], self.form_result)
            appSet.defaultOutputOrthography = assignOrthographyIfDefined(
                self.form_result['defaultOutputOrthography'], self.form_result)

            appSet.objectLanguageOrthography1Name = self.form_result[
                'objectLanguageOrthography1Name']
            appSet.objectLanguageOrthography1 = h.NFD(
                h.removeAllWhiteSpace(
                    self.form_result['objectLanguageOrthography1'])
            ) or defaultOrthography

            appSet.OLO1Lowercase = self.form_result['OLO1Lowercase']
            appSet.OLO1InitialGlottalStops = self.form_result[
                'OLO1InitialGlottalStops']

            appSet.objectLanguageOrthography2Name = self.form_result[
                'objectLanguageOrthography2Name']
            appSet.objectLanguageOrthography2 = h.NFD(
                h.removeAllWhiteSpace(
                    self.form_result['objectLanguageOrthography2']))
            appSet.OLO2Lowercase = self.form_result['OLO2Lowercase']
            appSet.OLO2InitialGlottalStops = self.form_result[
                'OLO2InitialGlottalStops']