def test_marks_behavior(self): fti = queryUtility(IDexterityFTI, name='upfront.assessmentitem.content.assessmentitem') factory = fti.factory new_assessmentitem = createObject(factory) self.failUnless(IAssessmentItem.providedBy(new_assessmentitem)) fti = queryUtility(IDexterityFTI, name='upfront.assessmentitem.content.answer') factory = fti.factory new_answer = createObject(factory) self.failUnless(IAnswer.providedBy(new_answer)) marks_behavior = getUtility(IBehavior, name = 'upfront.assessmentitem.behaviors.IMarks') # We expect this behavior to be a form field provider. Let's verify that self.failUnless( IFormFieldProvider.providedBy(marks_behavior.interface) ) # assert that you cannot add this behavior to a non-dexterity # content type doc = Document('doc') marks_adapter = IMarks(doc, None) self.assertEquals(False, marks_adapter is not None) # assert that new_assessmentitem object implements the behavior marks_adapter2 = IMarks(new_assessmentitem, None) self.assertEquals(True, marks_adapter2 is not None) # assert that new_answer object does not implements the behavior marks_adapter3 = IMarks(new_answer, None) self.assertEquals(False, marks_adapter3 is not None)
def test_assessmentitem_factory(self): fti = queryUtility( IDexterityFTI, name='upfront.assessmentitem.content.assessmentitem') factory = fti.factory new_object = createObject(factory) self.failUnless( IAssessmentItem.providedBy(new_object), 'assessmentitem provides wrong interface.')
def chooseName(self, name, object): # AssessmentItem if IAssessmentItem.providedBy(object): normalizer = getUtility(IURLNormalizer) # check if admin user specified a custom item_id if hasattr(object, 'item_id'): if object.item_id is not None: return normalizer.normalize(str(object.item_id)) # otherwise generate a name using ItemVersion utilty utility = getUtility(IItemVersion) if not name: # first check if object has an id name = getattr(aq_base(object), 'id', None) if not name: name = 'Q%03d' % utility.next_version() return normalizer.normalize(name) # EvaluationSheet elif IEvaluationSheet.providedBy(object): normalizer = getUtility(IURLNormalizer) if not name: # first check if object has an id name = getattr(aq_base(object), 'id', None) if not name: name = 'evaluationsheet-%s-%s' %\ (object.assessment.to_object.id, object.classlist.to_object.id) name = self._findUniqueName(name,object) return normalizer.normalize(name) elif IAssessment.providedBy(object): normalizer = getUtility(IURLNormalizer) if not name: # first check if object has an id name = getattr(aq_base(object), 'id', None) if not name: name = 'assessment' name = self._findUniqueName(name,object) return normalizer.normalize(name) # All other objects else: return super(AssessmentItemNameChooser, self).chooseName( name, object)
from zope.i18nmessageid import MessageFactory from plone.i18n.locales.languages import _languagelist # Set up the i18n message factory for our package MessageFactory = MessageFactory('tarmii.theme') from zope.interface import Interface from upfront.assessmentitem.content.assessmentitem import IAssessmentItem from plone.autoform.interfaces import OMITTED_KEY IAssessmentItem.setTaggedValue(OMITTED_KEY, [(Interface, 'introduction', 'true'), (Interface, 'question', 'true'), (Interface, 'answers', 'true')]) _languagelist[u'x-nso'] = {u'native' : 'Sepedi', u'name' : 'Northern Sotho'}