本文整理汇总了Python中girder.models.model_base.Model类的典型用法代码示例。如果您正苦于以下问题:Python Model类的具体用法?Python Model怎么用?Python Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Model类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testInclusionProjDict
def testInclusionProjDict(self, doc, inclusionProjDict):
Model._removeSupplementalFields(doc, inclusionProjDict)
assert doc == {
'_id': '1234',
'public': True,
'access': True,
'email': '[email protected]',
'login': 'login'}
示例2: testExclusionProjDict
def testExclusionProjDict(self, doc, exclusionProjDict):
Model._removeSupplementalFields(doc, exclusionProjDict)
assert doc == {
'_id': '1234',
'password': 'password1',
'admin': False,
'firstName': 'first',
'lastName': 'last'}
示例3: validate
def validate(self, doc):
if doc.get('score') is not None and doc.get('overallScore') is None:
scoring.computeAverageScores(doc['score'])
phase = self.model('phase', 'challenge').load(
doc['phaseId'], force=True)
doc['overallScore'] = scoring.computeOverallScore(doc, phase)
doc['latest'] = True
Model.update(self, query={
'phaseId': doc['phaseId'],
'creatorId': doc['creatorId'],
'latest': True
}, update={
'$set': {'latest': False}
})
return doc
示例4: testInclusionProjDictNewValue
def testInclusionProjDictNewValue(self, inclusionProjDict):
retval = Model._supplementFields(inclusionProjDict, {'newValue'})
assert retval == {
'public': True,
'access': True,
'email': True,
'login': True,
'newValue': True
}
示例5: testFlaseInclusionEdgeCase
def testFlaseInclusionEdgeCase(self):
doc = {
'_id': 'id',
'login': 'login',
'email': '[email protected]',
'firstName': 'fname',
'lastName': 'lname'
}
fields = {
'_id': False,
'login': True,
'email': True,
'firstName': True,
'lastName': True
}
Model._removeSupplementalFields(doc, fields)
assert doc == {
'login': 'login',
'email': '[email protected]',
'firstName': 'fname',
'lastName': 'lname'}
示例6: validate
def validate(self, doc):
if doc.get('created'):
doc['created'] = validateDate(doc.get('created'), 'created')
if doc.get('approach') in {'default', ''}:
del doc['approach']
if doc.get('score') is not None and doc.get('overallScore') is None:
scoring.computeAverageScores(doc['score'])
phase = Phase().load(
doc['phaseId'], force=True)
doc['overallScore'] = scoring.computeOverallScore(doc, phase)
doc['latest'] = True
Model.update(self, query={
'phaseId': doc['phaseId'],
'creatorId': doc['creatorId'],
'approach': doc.get('approach'),
'latest': True
}, update={
'$set': {'latest': False}
})
return doc
示例7: testFalseInclusionEdgeCase
def testFalseInclusionEdgeCase(self):
fields = {
'_id': False,
'login': True,
'email': True,
'firstName': True,
'lastName': True
}
overwrittenFields = {
'_id': True,
'login': True,
'email': True,
'firstName': True,
'lastName': True
}
overwrite = {'_id', 'login'}
retval = Model._supplementFields(fields, overwrite)
assert retval == overwrittenFields
示例8: testNoneEdgeCase
def testNoneEdgeCase(self):
# Test None edge cases
retval = Model._supplementFields(None, {'access', 'public'})
assert retval is None
示例9: testExclusionProjDictOverride
def testExclusionProjDictOverride(self, exclusionProjDict, overrideFields):
retval = Model._supplementFields(exclusionProjDict, overrideFields)
assert retval == {'email': False, 'login': False}
示例10: testExclusionProjDictNewValue
def testExclusionProjDictNewValue(self, exclusionProjDict):
retval = Model._supplementFields(exclusionProjDict, {'newValue'})
assert retval == exclusionProjDict
示例11: testInclusionProjListOverride
def testInclusionProjListOverride(self, inclusionProjList, overrideFields):
retval = Model._supplementFields(inclusionProjList, overrideFields)
assert set(retval) == set(inclusionProjList)
示例12: testInclusionProjectDictOverride
def testInclusionProjectDictOverride(self, inclusionProjDict, overrideFields):
copy = dict(inclusionProjDict)
retval = Model._supplementFields(inclusionProjDict, overrideFields)
assert retval == inclusionProjDict
assert inclusionProjDict == copy
示例13: testProjectionUtils
def testProjectionUtils(self):
def assertItemsEqual(a, b):
self.assertEqual(len(a), len(b))
self.assertEqual(sorted(a), sorted(b))
inclusionProjDict = {
'public': True,
'access': True,
'email': True,
'login': True
}
inclusionProjList = ['public', 'access', 'email', 'login']
exclusionProjDict = {
'public': False,
'access': False,
'email': False,
'login': False
}
overrideFields = {'access', 'public'}
copy = dict(inclusionProjDict)
retval = Model._overwriteFields(inclusionProjDict, overrideFields)
assertItemsEqual(retval, inclusionProjDict)
assertItemsEqual(inclusionProjDict, copy)
retval = Model._overwriteFields(inclusionProjList, overrideFields)
assertItemsEqual(retval, inclusionProjList)
retval = Model._overwriteFields(exclusionProjDict, {'newValue'})
assertItemsEqual(retval, exclusionProjDict)
retval = Model._overwriteFields(inclusionProjDict, {'newValue'})
assertItemsEqual(retval, {
'public': True,
'access': True,
'email': True,
'login': True,
'newValue': True
})
retval = Model._overwriteFields(exclusionProjDict, overrideFields)
assertItemsEqual(retval, {'email': False, 'login': False})
doc = {
'public': True,
'access': True,
'email': '[email protected]',
'login': 'login',
'password': 'password1',
'admin': False,
'firstName': 'first',
'lastName': 'last'
}
Model._removeOverwrittenFields(doc, exclusionProjDict)
assertItemsEqual(doc, {
'password': 'password1',
'admin': False,
'firstName': 'first',
'lastName': 'last'})
doc = {
'public': True,
'access': True,
'email': '[email protected]',
'login': 'login',
'password': 'password1',
'admin': False,
'firstName': 'first',
'lastName': 'last'
}
Model._removeOverwrittenFields(doc, inclusionProjList)
assertItemsEqual(doc, {
'public': True,
'access': True,
'email': '[email protected]',
'login': 'login'})
doc = {
'public': True,
'access': True,
'email': '[email protected]',
'login': 'login',
'password': 'password1',
'admin': False,
'firstName': 'first',
'lastName': 'last'
}
Model._removeOverwrittenFields(doc, inclusionProjDict)
assertItemsEqual(doc, {
'public': True,
'access': True,
'email': '[email protected]',
'login': 'login'})
# Test None edge cases
retval = Model._overwriteFields(None, {'access', 'public'})
self.assertIsNone(retval)
copy = dict(doc)
Model._removeOverwrittenFields(doc, None)
assertItemsEqual(copy, doc)
# Test '_id': False inclusion edge case
fields = {
'_id': False,
#.........这里部分代码省略.........
示例14: remove
def remove(self, doc, progress=noProgress):
folder = self.model('folder').load(doc['folderId'], force=True)
if folder:
self.model('folder').remove(folder)
Model.remove(self, doc, progress=progress)
示例15: testEmptyDict
def testEmptyDict(self):
assert Model._isInclusionProjection({}) is True