def Create(cls, parentID=None, groupName='New Folder', isReadOnly=None, wordTypeID=None): if not groupName: raise AuthoringValidationError('You must specify a group name.') messageGroupTable = bsdWrappers.GetTable(MessageGroup.__primaryTable__) if groupName: groupName = MessageGroup.GenerateUniqueName(parentID, groupName) if parentID is not None and MessageGroup.Get(parentID) is None: raise AuthoringValidationError( 'Parent(%s) was not found. Can not create this group. groupName : %s ' % (parentID, groupName)) newGroup = bsdWrappers.BaseWrapper._Create(cls, parentID=parentID, groupName=groupName, isReadOnly=isReadOnly, wordTypeID=wordTypeID) if parentID is not None: projectList = locProject.Project.GetProjectsForGroup(parentID) for aProject in projectList: aProject.AddGroupToProject(newGroup.groupID) if MessageGroup.Get(parentID).important: newGroup.important = MessageGroup.Get(parentID).important return newGroup
def Create(cls, messageID, languageID=LOCALE_SHORT_ENGLISH, text='', sourceDataID=None): primaryTable = bsdWrappers.GetTable(MessageText.__primaryTable__) dbLocaleID = GetNumericLanguageIDFromLanguageID(languageID) if dbLocaleID is None: raise RuntimeError( 'LanguageID %s could not be mapped to a locale ID.' % languageID) import message if not message.Message.Get(messageID): raise RuntimeError( 'Message ID %d does not exist! Message text not created for language %s' % (messageID, languageID)) statusID = None if languageID != LOCALE_SHORT_ENGLISH: englishText = MessageText.GetMessageTextByMessageID( messageID, LOCALE_SHORT_ENGLISH) if englishText: if sourceDataID is None: sourceDataID = englishText.dataID if MessageText._ValidateChangeToReview(None, sourceDataID, englishText.dataID): statusID = localizationBSDConst.TEXT_STATUS_REVIEW return bsdWrappers.BaseWrapper._Create(cls, messageID, dbLocaleID, text=text, sourceDataID=sourceDataID, statusID=statusID)
def GetMessageTextByMessageID(messageID, languageID): primaryTable = bsdWrappers.GetTable(MessageText.__primaryTable__) dbLocaleID = GetNumericLanguageIDFromLanguageID(languageID) return primaryTable.GetRowByKey(_wrapperClass=MessageText, keyId1=messageID, keyId2=dbLocaleID, _getDeleted=False)
def GetMessageTextsByMessageID(messageID): """ Returns text strings for all languages associated with this messageID. parameters: messageID - requested message ID """ primaryTable = bsdWrappers.GetTable(MessageText.__primaryTable__) return primaryTable.GetRows(_wrapperClass=MessageText, messageID=messageID, _getDeleted=False)
def GetMessageTextByMessageID(messageID, languageID): """ Returns text strings for language associated with this messageID. parameters: messageID - requested message ID """ primaryTable = bsdWrappers.GetTable(MessageText.__primaryTable__) dbLocaleID = GetNumericLanguageIDFromLanguageID(languageID) return primaryTable.GetRowByKey(_wrapperClass=MessageText, keyId1=messageID, keyId2=dbLocaleID, _getDeleted=False)
def _TransactionAwareCreate(cls, label, groupID, languageID, text, context, wordTypeID=None, transactionBundle=None): inheritedWordTypeID = Message._GetWordTypeID(groupID) if wordTypeID is None: wordTypeID = inheritedWordTypeID Message._ValidateCreationOfMessage(label, groupID, wordTypeID, transactionBundle=transactionBundle) dbLocaleID = GetNumericLanguageIDFromLanguageID(languageID) if dbLocaleID is None: raise AuthoringValidationError('Didnt find language (%s).' % languageID) reservedActionID = bsdWrappers.BaseWrapper._Create( cls, label=label, groupID=groupID, context=context, wordTypeID=wordTypeID) if transactionBundle: tupleActionID = (reservedActionID, 'messageID') transactionBundle[localizationBSDConst. BUNDLE_MESSAGE][tupleActionID] = util.KeyVal({ 'label': label, 'groupID': groupID, 'context': context, 'wordTypeID': wordTypeID }) messageTextTable = bsdWrappers.GetTable( locMessageText.MessageText.__primaryTable__) messageTextTable.AddRow((reservedActionID, 'messageID'), dbLocaleID, text=text) if type(reservedActionID) == int: return {'reservedMessageID': reservedActionID} raise AuthoringValidationError( 'Unexpected error. Possibly incorrect use of transactions. Expected actionID but instead got : %s ' % str(reservedActionID))
def _CheckLabelUniqueness(originalLabel, groupID, transactionBundle=None, returnUnique=False, _appendWord=None): """ Check or get unique label (if returnUnique is set to True) return: tuple: (if label is unique, unique label string) """ isOriginalLabelUnique = True if originalLabel is None: return (isOriginalLabelUnique, None) primaryTable = bsdWrappers.GetTable(Message.__primaryTable__) newLabel = originalLabel while True: labels = primaryTable.GetRows(label=newLabel, groupID=groupID, _getDeleted=True) atLeastOneMatch = False if transactionBundle: for key, aLabel in transactionBundle[ localizationBSDConst.BUNDLE_MESSAGE].iteritems(): if aLabel.label == newLabel and aLabel.groupID == groupID: atLeastOneMatch = True break if labels and len(labels) or atLeastOneMatch: isOriginalLabelUnique = False if returnUnique: newLabel = newLabel + (Message._APPEND_NEW if not _appendWord else _appendWord) else: break else: break if returnUnique: return (isOriginalLabelUnique, newLabel) else: return (isOriginalLabelUnique, None)
def GetMessageByID(messageID): primaryTable = bsdWrappers.GetTable(Message.__primaryTable__) return primaryTable.GetRowByKey(_wrapperClass=Message, keyId1=messageID, _getDeleted=False)
def _TransactionAwareCreate(cls, label, groupID, languageID, text, context, wordTypeID=None, transactionBundle=None): """ Worker function for transaction-aware portion of the create code. parameters: label - label of the message. Must be unique groupID - destination group. Must match the wordType of this message languageID - id for text entry text - text entry context - description for this message entry wordTypeID - type of the message transactionBundle - cache containing entries of messages to be added within transaction. It is required for validations within transactions. See CreateMessageDataBundle() Returns: reserved actionID dictionary for the message, that will be added when transaction is done. The return is formated as: {"reservedMessageID": INTEGER} pre-req: always meant to run in transaction """ inheritedWordTypeID = Message._GetWordTypeID(groupID) if wordTypeID is None: wordTypeID = inheritedWordTypeID Message._ValidateCreationOfMessage(label, groupID, wordTypeID, transactionBundle=transactionBundle) dbLocaleID = GetNumericLanguageIDFromLanguageID(languageID) if dbLocaleID is None: raise AuthoringValidationError('Didnt find language (%s).' % languageID) reservedActionID = bsdWrappers.BaseWrapper._Create( cls, label=label, groupID=groupID, context=context, wordTypeID=wordTypeID) if transactionBundle: tupleActionID = (reservedActionID, 'messageID') transactionBundle[localizationBSDConst. BUNDLE_MESSAGE][tupleActionID] = util.KeyVal({ 'label': label, 'groupID': groupID, 'context': context, 'wordTypeID': wordTypeID }) messageTextTable = bsdWrappers.GetTable( locMessageText.MessageText.__primaryTable__) messageTextTable.AddRow((reservedActionID, 'messageID'), dbLocaleID, text=text) if type(reservedActionID) == int: return {'reservedMessageID': reservedActionID} raise AuthoringValidationError( 'Unexpected error. Possibly incorrect use of transactions. Expected actionID but instead got : %s ' % str(reservedActionID))
def GetMessageTextsByMessageID(messageID): primaryTable = bsdWrappers.GetTable(MessageText.__primaryTable__) return primaryTable.GetRows(_wrapperClass=MessageText, messageID=messageID, _getDeleted=False)