Example #1
0
class VideoParameters(object):
    adapts(IVideo)
    implements(IOrderableSchemaExtender)

    fields = [
        _ExtensionWidthField(
            'width',
            schemata='Video',
            widget=IntegerWidget(
                label=_(u'Width'),
                description=
                _(u'You can override video width detected in video metadata. Leave empty to retreive width from metadata.'
                  ),
                size=6,
            ),
        ),
        _ExtensionHeightField(
            'height',
            schemata='Video',
            widget=IntegerWidget(
                label=_(u'Height'),
                description=
                _(u'You can override video height detected in video metadata. Leave empty to retreive height from metadata.'
                  ),
                size=6,
            ),
        ),
    ]

    def __init__(self, context):
        self.context = context

    def getFields(self):
        return self.fields

    def getOrder(self, order):
        #default = order['default']
        #default.remove('queryParameters')
        #default.insert(default.index('remoteUrl')+1, 'queryParameters')
        return order
Example #2
0
        # Progress Status in percentage. 0% - 100%
        FloatField(
            'xppm_story_progress_percent',
            searchable=False,
            required=False,
            default=0.0,
        ),

        # estimated hours for this task.
        IntegerField(
            'xppm_story_estimated_hours',
            searchable=False,
            required=False,
            widget=IntegerWidget(
                label='Estimated Hours',
                descrpiton='Put here the estimated hours for this task',
            ),
            schemata='Manage',
        ),

        # used hours for this task.
        FloatField(
            'xppm_story_used_hours',
            searchable=False,
            required=False,
            default=0.0,
        ),

        # owner of this task.??? select from membership.
        # getToolByName(self, 'portal_membership')
        LinesField(
Example #3
0
class ECQPointsQuestion(ECQBaseQuestion):
    """ A question that can in some way be graded. The candidate's points 
        or the rating he/she gave, can be retieved via the 
        'getCandidatePoints()' method.
    """

    schema = ECQBaseQuestion.schema.copy() + Schema(
        (
            IntegerField(
                'points',  # See 'description' property of the widget.
                accessor='getPointsPrivate',
                required=True,
                validators=(
                    'isPositiveInt',
                    'clearPointsCache',
                ),
                read_permission=PERMISSION_INTERROGATOR,
                widget=IntegerWidget(
                    label='Points',
                    label_msgid='points_label',
                    description=
                    'The number of points assigned to this question.',
                    description_msgid='points_tool_tip',
                    i18n_domain=I18N_DOMAIN),
                #read_permission=PERMISSION_STUDENT,
                #languageIndependent=True,
            ),
            BooleanField(
                'tutorGraded',
                accessor='isTutorGraded',
                default=False,
                #searchable=False,
                widget=BooleanWidget(
                    label='Tutor-Graded',
                    label_msgid='tutor_graded_label',
                    description=
                    'If answers to this question are graded manually, mark this checkbox.',
                    description_msgid='tutor_graded_tool_tip',
                    i18n_domain=I18N_DOMAIN),
                read_permission=PERMISSION_STUDENT,
                validators=('clearPointsCache', ),
                languageIndependent=True,
            ),
        ), )

    security = ClassSecurityInfo()

    security.declareProtected(PERMISSION_STUDENT, 'getPoints')

    def getPoints(self, *args, **kwargs):
        return self.getPointsPrivate(*args, **kwargs)

    security.declarePrivate('computeCandidatePoints')

    def computeCandidatePoints(self, result):
        """ Return how many points the candidate got for this question.

            @param result The result object of the candidate whose
            points you want to know.

            If a custom evaluation script has been uploaded it will be
            invoked. Otherwise a default method will be used.
        """
        parent = getParent(self)
        customScript = parent.getEvaluationScript(self.portal_type)
        answer = self.getCandidateAnswer(result)
        if not customScript:  # default
            return None
        else:  # use custom script
            return evalFunString(customScript, CUSTOM_EVALUATION_FUNCTION_NAME,
                                 [self, result, answer])

    def getCandidatePoints(self, result):
        if self.isTutorGraded():
            return result.getTutorPoints(self)
        else:
            # Check if we have a tutor-given or a cached value
            retVal = result.getCachedQuestionPoints(self)
            if retVal is None:
                retVal = self.computeCandidatePoints(result)
                result.setCachedQuestionPoints(self, retVal)
            return retVal
                     "under. A forum can exist in multiple categories, "
                     "although using only one category is recommended.",
         description_msgid="help_category",
         condition="object/getCategories",
         label="Category",
         label_msgid="label_category",
         i18n_domain="ploneboard",
       )
 ),
 IntegerField('maxAttachments',
     write_permission=ManageForum,
     default=1,
     widget=IntegerWidget(
          description="Select the maximum number of attachments per comment.",
          description_msgid="help_maxattachments",
          label="Maximum number of attachments",
          label_msgid="label_maxattachments",
          i18n_domain="ploneboard",
     )
 ),
 IntegerField('maxAttachmentSize',
     write_permission=ManageForum,
     vocabulary=AttachmentSizes,
     default=100,
     widget=SelectionWidget(
          description="Select the maximum size for attachments.",
          description_msgid="help_maxattachmentsize",
          label="Maximum attachment size",
          label_msgid="label_maxattachmentsize",
          i18n_domain="ploneboard",
     )
Example #5
0
            description=_(u'Vocabulary to use to render widget items'),
        )),
    StringField('catalog',
                schemata="default",
                vocabulary_factory='eea.faceted.vocabularies.UseCatalog',
                widget=SelectionWidget(
                    format='select',
                    label=_(u'Catalog'),
                    description=_(u"Get unique values from catalog "
                                  u"as an alternative for vocabulary"),
                )),
    IntegerField('maxitems',
                 schemata="display",
                 default=0,
                 widget=IntegerWidget(
                     label=_(u"Maximum items"),
                     description=_(u'Number of items visible in widget'),
                 )),
    BooleanField('sortreversed',
                 schemata="display",
                 widget=BooleanWidget(
                     label=_(u"Reverse options"),
                     description=_(u"Sort options reversed"),
                 )),
    LinesField('default',
               schemata="default",
               widget=LinesWidget(
                   label=_(u'Default value'),
                   description=_(u'Default items (one per line)'),
                   i18n_domain="eea")),
))
Example #6
0
from Products.Archetypes.public import IntegerField
from Products.Archetypes.public import IntegerWidget

from eea.facetednavigation.widgets import ViewPageTemplateFile
from eea.facetednavigation.widgets.widget import Widget as AbstractWidget
from eea.facetednavigation import EEAMessageFactory as _
import logging

logger = logging.getLogger('collective.bibliocustomviews.widgets.resultsrange')

EditSchema = Schema((
    IntegerField('step',
                 schemata="default",
                 default=500,
                 widget=IntegerWidget(label=_(u'Step'),
                                      description=_(u'Results range step'),
                                      i18n_domain="eea")),
    IntegerField('end',
                 schemata="default",
                 default=2000,
                 widget=IntegerWidget(label=_(u'End'),
                                      description=_(u'Last range start value'),
                                      i18n_domain="eea")),
    IntegerField('default',
                 schemata="default",
                 default=0,
                 widget=IntegerWidget(
                     label=_(u'Default value'),
                     description=_(u'Default range start value'),
                     i18n_domain="eea")),
))
Example #7
0
class ECQExtendedTextQuestion(ECQPointsQuestion):
    """A question that allows the candidate to write a text answer."""

    schema = ECQPointsQuestion.schema.copy() + Schema((
        TextField(
            'answerTemplate', # See 'description' property
                              # of the widget.
            searchable=True,
            required=False,
            allowable_content_types=('text/plain',
                                     #'text/structured',
                                     #'text/restructured',
                                     #'text/html',
                                     ),
            default_output_type='text/plain',
            widget=TextAreaWidget(
                label='Answer Template',
                label_msgid='answer_template_label',
                description="You can provide a template for the "
                "candidate's answer.",
                description_msgid='answer_template_tool_tip',
                i18n_domain=I18N_DOMAIN,
                rows=10,
                ),
            validators=('isXML',),
            read_permission=PERMISSION_STUDENT,
            ),
        
        IntegerField('expectedLength',
                required=False,
                default=50,
                validators=('isPositiveInt',),
                widget=IntegerWidget(
                    label='Expected Length',
                    label_msgid='expected_length_label',
                    description="You can set the number of words you "
                    "expect the candidate's answer to have.",
                    description_msgid='expected_length_tool_tip',
                    i18n_domain=I18N_DOMAIN),
                read_permission=PERMISSION_STUDENT,
            ),
        ),)
    # This type of question is always tutor-graded
    schema.delField('tutorGraded')
    # Make "points" appear *after* the "answerTemplate"
    schema.moveField('points', 1)
    schema.moveField('points', 1)
        
    allowed_content_types = ()
    filter_content_types = True # Otherwise allowed_content_types == ()
                                # means 'allow everything'
    
    meta_type = 'ECQExtendedTextQuestion'     # zope type name
    portal_type = meta_type                   # plone type name
    archetype_name = 'Extended Text Question' # friendly type name

    # Use the portal_factory for this type.  The portal_factory tool
    # allows users to initiate the creation objects in a such a way
    # that if they do not complete an edit form, no object is created
    # in the ZODB.
    #
    # This attribute is evaluated by the Extensions/Install.py script.
    use_portal_factory = True

    typeDescription = "A question that allows the candidate to write " \
                      "a text answer."
    typeDescMsgId = 'description_edit_extextquestion'

    security = ClassSecurityInfo()

    security.declarePublic('isTutorGraded')
    def isTutorGraded(self, *args, **kwargs):
        return True
Example #8
0
 UIDReferenceField("Supervisor",
                   required=0,
                   allowed_types=("LabContact", ),
                   vocabulary="_getLabContacts",
                   write_permission=ManageBika,
                   accessor="getSupervisorUID",
                   widget=SelectionWidget(
                       format="select",
                       label=_("Supervisor"),
                       description=_("Supervisor of the Lab"))),
 IntegerField(
     "Confidence",
     schemata="Accreditation",
     widget=IntegerWidget(
         label=_("Confidence Level %"),
         description=_("This value is reported at the bottom of all "
                       "published results"),
     ),
 ),
 BooleanField(
     "LaboratoryAccredited",
     default=False,
     schemata="Accreditation",
     write_permission=ManageBika,
     widget=BooleanWidget(
         label=_("Laboratory Accredited"),
         description=_("Check this box if your laboratory is accredited"),
     ),
 ),
 StringField(
     "AccreditationBody",
class ECQSelectionQuestion(ECQBaseQuestion):
    """ A question that allows the candidate to select one or more of the 
        predefined answers contained in the question (ECQBaseQuestion is
        derived from 'BaseFolder').
    """

    schema = ECQBaseQuestion.schema + Schema(
        (
            BooleanField(
                'allowMultipleSelection',
                # If 'allowMultipleSelection' is True, this is a
                # multiple answer question, i.e. one where more than
                # one answer can be true. Otherwise it is a multiple
                # choice question, i.e. exactly only one answer is
                # correct.  The question_view template is designed to
                # support this. When 'allowMultipleSelection' is True,
                # radio buttons will be generated.  If not, check
                # boxes will be shown.  See also 'description'
                # property of the widget.
                accessor='isAllowMultipleSelection',
                default=1,
                searchable=False,
                widget=BooleanWidget(
                    label='Allow Multiple Selection',
                    label_msgid='allow_multiple_selection_label',
                    description=
                    'If the selection of multiple answers should be possible, mark this checkbox.',
                    description_msgid='allow_multiple_selection_tool_tip',
                    i18n_domain=I18N_DOMAIN),
                read_permission=PERMISSION_STUDENT,
                languageIndependent=True,
            ),
            BooleanField(
                "randomOrder",  # See 'description' property
                # of the widget.
                accessor='isRandomOrder',
                required=False,
                default=1,
                read_permission=PERMISSION_INTERROGATOR,
                widget=BooleanWidget(
                    label='Randomize Answer Order',
                    label_msgid='randomize_answer_order_label',
                    description='Check this box if you want the answers '
                    'to this question to appear in a different, random '
                    'order for each candidate. Otherwise the '
                    'same order as in the "contents"-view will '
                    'be used.',
                    description_msgid='randomize_answer_order_tool_tip',
                    i18n_domain=I18N_DOMAIN),
                #read_permission=PERMISSION_STUDENT,
                languageIndependent=True,
            ),
            IntegerField(
                "numberOfRandomAnswers",  # See 'description'
                # property of the
                # widget.
                default=-1,
                read_permission=PERMISSION_INTERROGATOR,
                widget=IntegerWidget(
                    label='Number of Random Answers',
                    label_msgid='number_of_random_answers_label',
                    description='The number of answers which are randomly '
                    'selected when a new quiz is generated for a candidate. '
                    '(This only works if "Randomize Answer Order" '
                    'is checked.)  A value <= 0 means that all answers '
                    'will be used.',
                    description_msgid='number_of_random_answers_tool_tip',
                    i18n_domain=I18N_DOMAIN),
                #read_permission=PERMISSION_STUDENT,
                languageIndependent=True,
            ),
        ), )

    security = ClassSecurityInfo()

    security.declarePrivate('makeNewTest')

    def makeNewTest(self, candidateResult, suMode):
        """generate a new quiz"""
        allAnswers = self.contentValues()
        if self.isRandomOrder() and (not suMode):
            # use random order
            numRnd = min(len(allAnswers), self.getNumberOfRandomAnswers())
            if numRnd > 0:
                # Separate the correct answers
                correctAnswers = [a for a in allAnswers if a.isCorrect()]
                # Determine how many correct answers and how many
                # other answers to show
                maxNumCorrect = min(len(correctAnswers), numRnd)
                numCorrect = random.randint(1, maxNumCorrect)
                numOther = numRnd - numCorrect
                # Get the randomized correct answers
                rndCorrectAnswers = random.sample(correctAnswers, numCorrect)
                # Now choose numOther-many answers out of the ones
                # that are not in rndCorrectAnswers
                otherAnswers = [
                    a for a in allAnswers if a not in rndCorrectAnswers
                ]
                rndOtherAnswers = random.sample(otherAnswers, numOther)

                suggestedAnswers = rndCorrectAnswers + rndOtherAnswers
            else:
                suggestedAnswers = allAnswers
            # Randomize the answers
            suggestedAnswers = random.sample(suggestedAnswers,
                                             len(suggestedAnswers))
        else:
            # Use the order in the "contents"-view
            suggestedAnswers = allAnswers
        suggestedAnswerIds = [answer.getId() for answer in suggestedAnswers]

        # Store the new suggested answer ids in the results object
        candidateResult.setSuggestedAnswer(self, suggestedAnswerIds)

    security.declareProtected(PERMISSION_STUDENT, 'getSuggestedAnswerIds')

    def getSuggestedAnswerIds(self, result):
        """Return a list with the IDs of the answer objects that were
        presented to the candidate.
        
        @param result The candidate's result object.
        """
        return result.getSuggestedAnswer(self)

    security.declareProtected(PERMISSION_STUDENT, 'getSuggestedAnswers')

    def getSuggestedAnswers(self, result):
        """Return a list with the actual answer objects that were
        presented to the candidate with ID candidateId.
        
        @param result The candidate's result object.
        """

        allAnswers = self.contentValues()
        suggestedAnswerIds = result.getSuggestedAnswer(self)
        retVal = filterById(suggestedAnswerIds, allAnswers)

        return retVal
Example #10
0
from ZODB.POSException import ConflictError

from Products.XPointContactManagement.config import PROJECTNAME

XPointAddressBookSchema = ATFolderSchema.copy() + Schema((

    # the unique sequence will serve contact, contact group, and contact
    # metadata.
    IntegerField(
        'xpcm_unique_sequence',
        default=0,
        # hide for view mode.
        widget=IntegerWidget(
            label='Unique Sequence',
            description=
            'This sequence will generate unique ids for this address book',
        ),
    ), ))

# Plone 3 will re-organize all fields' shemata by using this method.
finalizeATCTSchema(XPointAddressBookSchema)

# customizing the schema: set visible and location of fields.


# here comes the class.
class XPointAddressBook(ATFolder):
    """XPointAddressBook will be the folder for contact information.
    """
Example #11
0
from Products.Archetypes.public import Schema
from Products.Archetypes.public import IntegerField
from Products.Archetypes.public import IntegerWidget

from eea.facetednavigation.widgets import ViewPageTemplateFile
from eea.facetednavigation.widgets.widget import Widget as AbstractWidget
from eea.facetednavigation import EEAMessageFactory as _

logger = logging.getLogger('eea.facetednavigation.widgets.resultsperpage')

EditSchema = Schema((
    IntegerField('start',
                 schemata="display",
                 default=0,
                 widget=IntegerWidget(
                     label=_(u'Start'),
                     description=_(u'Results per page starting value'),
                     i18n_domain="eea")),
    IntegerField('end',
                 schemata="display",
                 default=50,
                 widget=IntegerWidget(
                     label=_(u'End'),
                     description=_(u'Results per page ending value'),
                     i18n_domain="eea")),
    IntegerField('step',
                 schemata="display",
                 default=5,
                 widget=IntegerWidget(label=_(u'Step'),
                                      description=_(u'Results per page step'),
                                      i18n_domain="eea")),
    IntegerField('default',
     storage=AnnotationStorage(),
     widget=DecimalWidget(
         description=_(u''),
         label=_(u'Risk Rate'),
     ),
     default=0.0,
 ),
 IntegerField(
     name='min_delivery_days',
     required=True,
     searchable=False,
     languageIndependent=True,
     storage=AnnotationStorage(),
     widget=IntegerWidget(
         label=_(u'Minimum Delivery Days'),
         size='2',
         maxlength='2',
     ),
 ),
 IntegerField(
     name='max_delivery_days',
     required=True,
     searchable=False,
     languageIndependent=True,
     storage=AnnotationStorage(),
     widget=IntegerWidget(
         label=_(u'Maximum Delivery Days'),
         size='2',
         maxlength='2',
     ),
 ),
Example #13
0
         description=_(
             u'Select Incremental or Random for Cart ID Numbering.'),
     ),
     vocabulary=('Incremental', 'Random'),
     enforceVocabulary=True,
     default='Incremental',
 ),
 IntegerField(
     name='next_incremental_cart_id',
     required=False,
     searchable=False,
     languageIndependent=True,
     storage=AnnotationStorage(),
     widget=IntegerWidget(
         label=_(u'Next Incremental Cart ID'),
         description=
         _(u'If Incrementanl Cart ID is seleceted, give interger number here.'
           ),
     ),
     default=1,
 ),
 IntegerField(
     name='random_digits_cart_id',
     required=False,
     searchable=False,
     languageIndependent=True,
     storage=AnnotationStorage(),
     widget=IntegerWidget(
         label=_(u'Random Digits Cart ID'),
         description=_(
             u'If Random Cart ID is selected, give integer digits here.'),
     ),
Example #14
0
             ),
 ),
 StringField('Unit',
             schemata="Description",
             widget=StringWidget(
                 label=_("Unit"),
                 description=_(
                     "The measurement units for this analysis service' results, "
                     "e.g. mg/l, ppm, dB, mV, etc."),
             ),
 ),
 IntegerField('Precision',
              schemata="Analysis",
              widget=IntegerWidget(
                  label=_("Precision as number of decimals"),
                  description=_(
                      "Define the number of decimals to be used for this result."),
              ),
 ),
 IntegerField('ExponentialFormatPrecision',
              schemata="Analysis",
              default = 7,
              widget=IntegerWidget(
                  label=_("Exponential format precision"),
                  description=_(
                      "Define the precision when converting values to exponent notation."),
              ),
 ),
 IntegerField('ExponentialFormatPrecision',
              schemata="Analysis",
              default = 7,
            required = True,
            default = ('Expense', 'Income'),
            widget = LinesWidget(
                label = 'Transaction Types',
                description = 'Please specify the transaction types, one per line',
                cols = 40,
                ),
            ),

        # the unique sequence will serve
        IntegerField(
            'bk_unique_sequence',
            default = 0,
            # hide for view mode.
            widget = IntegerWidget(
                label = 'Unique Sequence',
                description = 'This sequence will generate unique ids for all artifacts in this folder.',
                ),
            ),

        # this is a field to save the transaction categories.
        # TODO: this field should be invisable!
        LinesField(
            'bk_transaction_categories',
            accessor = 'transactionCategories',
            searchable = False,
            required = True,
            default = ('Income:ConsultingIncome', 'Income:ServiceIncome', 
                'Expense:Gas', 'Expense:Parking', 'Expense:Lunch',
                'Expense:Internet', 'Expense:OfficeSupply'
                ),
            widget = LinesWidget(
Example #16
0
         i18n_domain="eea")),
 StringField('catalog',
             schemata="default",
             vocabulary_factory='eea.faceted.vocabularies.UseCatalog',
             widget=SelectionWidget(
                 format='select',
                 label=_(u'Catalog'),
                 description=_(
                     u'Get unique values from catalog as an alternative '
                     u'for vocabulary'),
                 i18n_domain="eea")),
 IntegerField('maxitems',
              schemata="display",
              default=50,
              widget=IntegerWidget(
                  label=_(u'Maximum items'),
                  description=_(u'Number of items visible in widget'),
                  i18n_domain="eea")),
 IntegerField('maxchars',
              schemata="display",
              default=0,
              widget=IntegerWidget(
                  label=_(u'Maximum characters'),
                  description=_(
                      u'Cut long phrases to provided number of characters'),
                  i18n_domain="eea")),
 StringField('colormin',
             schemata="display",
             default="A1BE7E",
             widget=StringWidget(
                 label='Minimum color',
                 label_msgid='faceted_criteria_colormin',
Example #17
0
                        u'for vocabulary'),
                    i18n_domain="eea")),
    BooleanField('hidealloption',
                 schemata="default",
                 default=False,
                 widget=BooleanWidget(
                     label=_(u"Hide 'All' option"),
                     description=_(
                         u'If this checkbox is checked, hides the All '
                         u'option'),
                     i18n_domain="eea")),
    IntegerField('maxitems',
                 schemata="display",
                 default=0,
                 widget=IntegerWidget(
                     label=_(u'Maximum items'),
                     description=_(u'Number of items visible in widget'),
                     i18n_domain="eea")),
    BooleanField('sortreversed',
                 schemata="display",
                 widget=BooleanWidget(label=_(u'Reverse options'),
                                      description=_(u'Sort options reversed'),
                                      i18n_domain="eea")),
    StringField('default',
                schemata="default",
                widget=StringWidget(size=25,
                                    label=_(u'Default value'),
                                    description=_(u'Default selected item'),
                                    i18n_domain="eea")),
))

Example #18
0
                    description_msgid='help_top_entry_count_setting',
                    i18n_domain='plone',
                    ),
        vocabulary=IntDisplayList((
                    (1, 'In days', 'label_show_entry_in_days'),
                    (2, 'In entry count', 'label_show_entry_in_count'),
                    )),
        schemata='cbsettings_display',
        ),

    IntegerField('top_entry_count',
        searchable=0,
        default = zconf.coreblog2.top_entry_count_default,
        widget=IntegerWidget(label='Entries count',
                    description='',
                    label_msgid='label_top_entry_count',
                    description_msgid='help_top_entry_count',
                    i18n_domain='plone',
                    ),
        schemata='cbsettings_display',
        ),

    IntegerField('portlet_item_count',
        searchable=0,
        default = zconf.coreblog2.portlet_item_count_default,
        widget=IntegerWidget(label='Items per portlet',
                    description='',
                    label_msgid='label_portlet_item_count',
                    description_msgid='help_portlet_item_count',
                    i18n_domain='plone',
                    ),
        schemata='cbsettings_display',
Example #19
0
class QuizResult(ATFolder):
    """Keeps together all the questions results for a specific student from a quiz in a specific lecture."""
   
    
    
    schema = ATFolderSchema.copy() + Schema((
        
        StringField('title',
                required=True,
                searchable=0,
                default='Quiz result',
                widget=StringWidget(
                    label='Title',
                    description='The main title of the tutorial.',
                    i18n_domain='plone'),
               
            ),
        BooleanField('openquest',
                     default=0,
                      widget=BooleanWidget(visible={'edit':'invisible', 'view':'invisible'}, ),),
        BooleanField('haveanswer',
                     default=0,
                      widget=BooleanWidget(visible={'edit':'invisible', 'view':'invisible'}, ),
                  ),
                     
        ImageField('CurrentQuestionImage',
                   #original_size=(600,600),
                   #max_size=(600,600),
                   sizes={ 'mini' : (80,80),
                           'normal' : (200,200),
                            'big' : (100,100),
                            'maxi' : (500,500),
                           },
                   widget=ImageWidget(label='quis question image',
                                      description='Image for the current question, displayed to the right of main text of the slide. Possible formats for uploaded images are: png, gif and jpeg.', 
                                      #macro='tutorwebimage',
                             # condition ='object/isImageFormat',
                                       )),
        ReferenceField('StudentQuestions',
                    #vocabulary="getAvailableCourses",
                    widget=ReferenceWidget(
                           label="quiz question",
                           description='A question student has been asked',
                           destination=".",
                           #destination_types=("QuestionResult",),
                           #visible={'edit':'invisible'},
                           
                           ),
                       multiValued=True,
                       relationship='hasQuestion',
                       allowed_types= ("InvisibleQuestion",),
                        
                   ),  

        ReferenceField('CurrentQuestion',
                    #vocabulary="getAvailableCourses",
                    widget=ReferenceWidget(
                           label="quiz question which is open",
                           description='A question student is being asked',
                           destination=".",
                           #destination_types=("QuestionResult",),
                           #visible={'edit':'invisible'},
                           
                           ),
                       multiValued=False,
                       relationship='hasOpenQuiz',
                       allowed_types= ("InvisibleQuestion",),
                        
                   ),  
        ComputedField('grade',
                  expression='context.computeGrade()',
                  widget=StringWidget(visible={'edit':'invisible','view':'invisible' },),
          
            ),
        IntegerField('totalattempts',
                     default='0',
                     widget=IntegerWidget(description='Number of times students has submitted a questions to quiz.', 
                                         visible={'edit':'invisible','view':'invisible'}, ),
                  ),
         IntegerField('correctattempts',
                        default='0',
                     widget=IntegerWidget(description='Number of times students has submitted a questions to quiz.', 
                                         visible={'edit':'invisible', 'view':'invisible'}, ),
                  ),
         FloatField('totscore',
                     default=0.0,
                     widget=IntegerWidget(description='total score so far.', 
                                       visible={'edit':'invisible','view':'invisible' },   ),
                  ),
           StringField('lasteightgrades',
                       default='[]',
                     widget=StringWidget(description='Number of times students has submitted a questions to quiz.', 
                                         visible={'edit':'invisible','view':'invisible' }, ),),
         StringField('studentRandId',
                       default='',
                     widget=StringWidget(description='random generated id to identify student.', 
                                         visible={'edit':'invisible','view':'invisible' }, ),
        ),
        StringField('studentId',
                       default='',
                     widget=StringWidget(description='login id of student.', 
                                         visible={'edit':'invisible','view':'invisible' }, ),                   
       ),

          #StringField('chosenquestid',
          #             default='',
          #           widget=StringWidget(description='Number of times students has submitted a questions to quiz.', 
          #                               visible={'view':'invisible', 'edit':'invisible'}, ),
          #        ),

       #StringField('chosenquestpath',
       #                default='',
       #              widget=StringWidget(description='Number of times students has submitted a questions to quiz.', 
        #                                 visible={'view': 'invisible', 'edit':'invisible'}, ),
         #         ),
       
     ))
    __implements__ = (ATFolder.__implements__)
    
    global_allow = False
    meta_type = 'QuizResult'          # zope type name
    portal_type = meta_type          # plone type name
    archetype_name = 'QuizResult' # friendly type name
    #_at_rename_after_creation = True  #automatically create id
    security = ClassSecurityInfo()
    
    # ATT: Make sure this work when create from twmigrate.py
    changed = True
    studentgrade = atapi.ATFieldProperty('grade')
    totalscore = atapi.ATFieldProperty('totscore')
    scoresofar = []
    # REMEMBER check if reversed or not when displayed????????
    lasteight = atapi.ATFieldProperty('lasteightgrades')
    quizattempts = atapi.ATFieldProperty('totalattempts')
    correctquizattempts = atapi.ATFieldProperty('correctattempts')
    chosenquestionid = atapi.ATFieldProperty('chosenquestid')
    chosenquestionpath = atapi.ATFieldProperty('chosenquestpath')
    #openquestion = atapi.ATFieldProperty('openquest')
    
    def __init__(self, oid=None, **kwargs):
        self.changed = True
        ATFolder.__init__(self, oid, **kwargs)
    
    # Must add:

    # getVocabulary is now in Lecture.py
    # returns the answers
    # getSelectedItem() in Lecture.py
    # questionIsInline in Lecture.py
    # isCorrect(item) in Lecture.py
    #
    # get chosen question already here
    #   then must transformR(True)
    #   then transformquizquestion
    #   getQuestionData()
    #   inlineAnswer()
    #  getQuestImg and getQuestionImageTag
    #
    def getQuestionResultForQuestion(self, question):
        qresults = question.getFolderContents(contentFilter={"portal_type": "QuestionResult"})
        return qresults[0].getObject()
    def getVocabulary(self):
        """return the possible answers formatted as vocabulary"""
        question = self.getCurrentQuestion()
        if (question):
            qr = self.getQuestionResultForQuestion(question)
            suggestedAnswerIds = (qr.getSuggestedAnswer())
            idl = DisplayList()
            ans = question.getAnswerDisplay().values()
       
            for id in suggestedAnswerIds:
                idl.add(id, ans[int(id)])
            return Vocabulary(idl, self, None)
        else:
            '''bad error no open question'''
            return ''
        
    def isCorrect(self, item):
        question = self.getCurrentQuestion()
        if (question):
            answers = question.getAnswerList()
            for row in answers:
                if (row['answerid'] == str(item)):
                    if (row['correct'] == '1'):
                        return True
            return False
        else:
            return False
    def startQuiz(self):
        '''student has asked for a question in quiz'''
        parent = aq_parent(self)
        lec = aq_parent(parent)
        if (DEBUG):
            tmpout = tempfile.mkdtemp()
            tex_fd, tex_absname = tempfile.mkstemp(dir=tmpout, suffix='.startQuiz')
            os.write(tex_fd, 'Starting selection of quiz question\n')
        
        hasq = self.openQuiz()
        msg = []
        msg.append(True)
        # taken care of that - set no answer and written to log
        # close that question
        if (hasq):
            msg.append('question replaced')
        else:
            msg.append('A question has been saved to quiz')
        msg.append(self.Creator())
        #parent = aq_parent(self)
        if (DEBUG):
            usable_question = lec.getQuizQuestion(tex_fd, True)
        else:
            usable_question = lec.getQuizQuestion()
        if (usable_question[0] == -1):
            '''no questions available'''
            msg[0] = False
            msg[1] = 'Sorry but no questions available in Lecture ' + usable_question[1] + '. Please contact your instructor if you believe you have found an error in the system, including the given error message'
            return msg
        elif(usable_question[0] == False):
            '''False could not create result for student'''
            msg[0] = False
            msg[1] = 'Fatal error could not start quiz in Lecture ' + usable_question[1] + '. Please contact your instructor if you believe you have found an error in the system, including the error message'
            return msg
        elif (usable_question[0] == -2):
            '''no answers set for the question'''
            msg[0] = False
            msg[1] = 'Sorry but no answers have been set for the selected question: ' + usable_question[2] + ' located in ' + usable_question[3] + '. Please try again or contact your instructor if you believe you have found and error in the system, including this message'
            return msg
        elif (usable_question[0] == -3):
            '''no answer set as correct in question'''
            msg[0] = False
            msg[1] = 'Sorry but no correct answer has been set to the selected question: ' + usable_question[2] + ' located in ' + usable_question[3] + '. Please try again or contact your instructor if you believe you have found an error in the system, including this error message'
            return msg
                
        else:
            '''have a valid question'''
            origquest = usable_question[0]
            if (DEBUG):
                os.write(tex_fd, '###########################\n')
                os.write(tex_fd, 'question used in quiz\n')
                os.write(tex_fd, str(origquest.getId()) + '\n')
                os.write(tex_fd, str(origquest.getRawQuestion()) + '\n')
        
            # set as invisble question with questionresult
            newq = self.createQuestion()
            qr = newq.createQuestionResult()
            # this info is repeated, but leave for now
            # FIXME
            if (len(self.getStudentRandId()) > 0):
                qr.setStudentId(self.getStudentRandId())
            else:
                # find from other location
                quiz = aq_parent(self)
                lec = aq_parent(quiz)
                tut = aq_parent(lec)
                dep = aq_parent(tut)
                mysite = aq_parent(dep)
                studentlistobj = mysite.getFolderContents(contentFilter={"portal_type": "StudentList"})
                if (len(studentlistobj) > 0):
                    studentlist = studentlistobj[0].getObject()
                    studentlist.addStudent(self.Creator())
                    randid = studentlist.getStudentIdNumber(self.Creator())
                    self.setStudentRandId(randid)
                    qr.setStudentId(randid)
            qr.setLecPath(lec.getPhysicalPath())
            # have created a quiz question with corresponding questuionresults
            # now set information from original question to quiz question
            # I probably don't need all the info but lets start by that
            questiontext = origquest.getRawQuestion()
            texttype = origquest.question.getContentType()
            mutated = origquest.getAnswerList()
            answertype = origquest.getAnswerFormat()
            newq.setQuestionText(questiontext, mimetype=texttype)
            newq.setAnswerList(mutated)
            newq.setAnswerFormat(answertype)
        
            # if its r or r/latex questions then need to be updated
            if (texttype == 'text/r' or texttype == 'text/r-latex'):
                newq.initializeObject()
               
            else:    
                newq.ans = origquest.ans
                newq.NOTAinQuestion = origquest.NOTAinQuestion
                newq.inlineanswer = origquest.inlineanswer
                newq.transformrquestion = origquest.transformrquestion
                newq.setQuizQuestion(origquest.getRawQuizQuestion(), mimetype=origquest.quizQuestion.getContentType())
                # add the image if any
                # ATT
                # asuming r-images do not contain image
                # would be generated within the r code itself?
                # HMMMMM
                img = origquest.getQuestionImage()
                newq.setQuestionImage(img)
            # add image url if any
            imgurl = origquest.getImageUrl()
            if (len(imgurl) > 0):
                newq.setImageUrl(imgurl)
            newq.numcorrect = origquest.numcorrect
            newq.numaskedfor = origquest.numaskedfor
            # need additionally to set:
            # quisQuestion
            
            
            newq.setQuizQuestionExplanation(origquest.getRawQuizQuestionExplanation(), mimetype='text/html')
           
           
            newq.setOriginalQuestion(origquest)
            
            # instead of using original question
            # use the invisible question
            suggestedanswers = newq.makeNewTest()
            grid = newq.getWrappedField('AnswerList')
            correctAnswerIds = []
            rowcorrect = grid.search(newq, correct='1')
            for row in rowcorrect:
                correctAnswerIds.append(row['answerid'])
            
            qr.setNewQuestion(suggestedanswers, correctAnswerIds, origquest.getPhysicalPath(), origquest.UID())
            
            
            if (len(suggestedanswers) > 0):
                '''set the first element in value as selected
                answer, anything will do'''
                qr.setSelectedAnswer(suggestedanswers[0])
                 
            else:
                '''what to do bad error'''
                msg[0] == False
                msg[1] = 'Fatal error'
                return msg
            qr.reindexObject()
            newq.reindexObject()
            self.reindexObject()
            if (DEBUG):
                os.write(tex_fd, str(newq.getId()) + '\n')
                os.write(tex_fd, str(newq.getRawQuestion()) + '\n')
                os.close(tex_fd)
            
            return msg
        
    def setTotalscore(self, val):
        self.setTotscore(val)
        #self.totalscore = val
    def setLastEightList(self, val):
        tmp = []
        for s in val:
            tmp.append(int(s))
        self.scoresofar = tmp
        tmpstr0 = str(val)
        tmpstr1 = tmpstr0.replace(',', '')
        self.setLasteightgrades(tmpstr1)
    def setLastEight(self, val):
        # value is a string
       
        tmpstr0 = val.replace(',', '')
        tmpstr1 = tmpstr0.replace('[', '')
        tmpstr2 = tmpstr1.replace(']','')
        scorelist = tmpstr2.split()
       
        tmp = []
        for s in scorelist:
            if (len(s) > 0):
                tmp.append(int(s))
        self.scoresofar = tmp
        self.setLasteightgrades(tmpstr0)
    def setScoresofar(self, val):
        self.scoresofar = val
    def getCreator(self):
        return self.Creator()
    def getSelectedAnswerToQuestion(self, question):
        #qr =  self.getStudentQuestionResult() 
        qr = self.getQuestionResultForQuestion(question)
        value = qr.getSelectedAnswer()
        #value = qr.getCandidateAnswer()
       
        answerdisplay = question.getAnswerDisplay()
        #index = int(value[0])
       
        return answerdisplay.getValue(value)
    def getSelectedItem(self):
        question = self.getCurrentQuestion()
        qr = self.getQuestionResultForQuestion(question)
        return qr.getSelectedAnswer()
    def questionIsInline(self):
        question = self.getCurrentQuestion()
        if (question > 0):
            return question.inlineAnswer()
        else:
            return False
    def getCandidateAnswerInTest(self):
        
        question = self.getCurrentQuestion()
        if (question):
            qr = self.getQuestionResultForQuestion(question)
            return (qr.getCandidateAnswer())
    security.declareProtected(PERMISSION_STUDENT, 'getOriginalQuestion')
    def getOriginalQuestion(self, quest):
        return quest.getOriginalQuestion()
        
    security.declareProtected(PERMISSION_STUDENT, 'getChosenQuestion')
    def getChosenQuestion(self):
        # always assume we are dealing with the last question
        question = self.getCurrentQuestion()
        if (question):
            return question
        else:
            return False
       
       
    def computeGrade(self):
        return float(self.getTotscore())
    def getSuggestedAnswerInTest(self):
        qr = self.getQuestionResultForQuestion(question)
        return (qr.getSuggestedAnswer())
    def setSelectedAnswerInTest(self, value):
        question = self.getCurrentQuestion()
        if (question):
            qr = self.getQuestionResultForQuestion(question)
            qr.setSelectedAnswer(value)
            qr.reindexObject()
    def unsetCandidateAnswerToQuestion(self):
        #qr =  self.getStudentQuestionResult()
        #qresults = self.getFolderContents(contentFilter={"portal_type": "QuestionResult"})
        #qr = qresults[0].getObject()
        question = self.getCurrentQuestion()
        if (question):
            qr = self.getQuestionResultForQuestion(question)
            qr.unsetCandidateAnswer()
            qr.reindexObject()
    def setCandidateAnswerToQuestion(self, value):
        question = self.getCurrentQuestion()
        if (question):
            qr = self.getQuestionResultForQuestion(question)               
            qr.gotAnswer()
            origquestion = question.getOriginalQuestion()
            qr.setCandidateAnswer([value], origquestion)
            qr.writetolog()
            correctans = qr.getCorrectAnswer()
            l = qr.getSuggestedans().split('\t')
            v = l[int(value)-1]
            if v in correctans:
                # this can lead ot database conflict error   
                origquestion.numcorrect = origquestion.numcorrect + 1
                correct = 1
            else:
                correct = 0
                #qr.gotAnswer()
            self.setScore(correct)
            qr.reindexObject()
    def computeAverageGrade(self):
        '''return average grade of student'''
        # compute the average grade of the student for this lecture
        # Average grade is at the moment computed according to points given
        # for the last eight answers:
        # Correct answer gives +1 points
        # Wrong answer gives -0.5 points
        # no answers given or all answers incorrect, grade starts at -0.5
        # Highest average grade is +1, all answers correct       
        # r = number correct answers of last m= 8 answers
        # average grade = ((-0.5)*(m-r)+r)/m
        # later more complex methods of computing grades need to be specified.
    
        numcorrect = 0
        for i in self.scoresofar:
            if float(i) > 0.0:
                numcorrect = numcorrect + 1
        # average grade is computed from the last 8 answers
        m = 8.0
        return ((-0.5)*(m-float(numcorrect))+float(numcorrect))/m
    def computeGrade1(self, remove):
        #tmpout = tempfile.mkdtemp()
        #tex_fd, tex_absname = tempfile.mkstemp(dir=tmpout, suffix='.computegradae1')
        #os.write(tex_fd, 'computegrade1\n')

        #tmp1 = self.getTotscore()
        #tmp = float(tmp1)
        #if (remove == 0):
        #    tmp = tmp + 0.5
        #else:
        #    tmp = tmp - 1.0
        #lastscore = self.scoresofar[0]
        #if (lastscore == 0):
        #    tmp = tmp - 0.5
        #else:
        #    tmp = tmp + 1.0
        
        total = 0.0
        for i in self.scoresofar:
            if float(i) == 0.0:
                total = total - 0.5
            else:
                total = total + 1
        self.setTotscore(total)
        
        #questions = self.getStudentQuestions()
        #portal_catalog = getToolByName(self, 'portal_catalog')
        ##questions = self.portal_catalog.searchResults(
        ##    portal_type = "InvisibleQuestion",
        ##    sort_on="Date",
        ##    path='/'.join(self.getPhysicalPath()),
        ##    )
        ##total = 0.0
        ##self.scoresofar = []
        ##for q in questions:
         ##   qr = self.getQuestionResultForQuestion(q.getObject())
         ##   if (qr.candidateAnswer == qr.correct):
          ##      total = total + 1.0
           ##     self.scoresofar.insert(0,1)
          ##  else:
          ##      total = total - 0.5
          ##      self.scoresofar.insert(0,0)
        ##self.setLasteightgrades(str(self.scoresofar))    
        ##self.setTotscore(total)
        self.reindexObject()
        #os.write(tex_fd, str(self.scoresofar) + '\n')
        #os.write(tex_fd, str(total) + '\n')
        #os.write(tex_fd, str(self.getPhysicalPath()) + '\n')
        #bla = '/'.join(self.getPhysicalPath())
        #os.write(tex_fd, str(bla) + '\n')
        #os.write(tex_fd, str(len(questions)) + '\n')
        
        return self.getLasteightgrades()    
    def getLastPoint(self):
        if (len(self.scoresofar) > 0):
            return self.scoresofar[0]
        else:
            return None
    security.declarePublic('setScore')
    def setScore(self, s):
        numinscore = 8
        if (len(self.scoresofar) == numinscore):
            tmp = self.scoresofar[numinscore-1]
            self.scoresofar = self.scoresofar[:numinscore-1]
            #self.scoresofar = self.scoresofar + [s]
            self.scoresofar.insert(0, s)
            self.setLasteightgrades(str(self.scoresofar))
            self.computeGrade1(tmp)
            #self.setLasteightgrades(str(self.scoresofar))
        else:
            tmp = float(self.getTotscore())
            if (s is 0):
                tmp = tmp - 0.5
            else:
                tmp = tmp + 1.0
            self.setTotscore(tmp)
            #tmp = 0           
            #self.computeGrade1(tmp)
            #self.scoresofar = self.scoresofar + [s]
            self.scoresofar.insert(0, s)
            self.setLasteightgrades(str(self.scoresofar))
            #self.computeGrade1(tmp)
        temp = self.getTotalattempts()
        temp = temp + 1
        self.setTotalattempts(temp)
        if (s is not 0):
            temp = self.getCorrectattempts()
            temp = temp + 1
            self.setCorrectattempts(temp)
        self.reindexObject()
    def closedQuiz(self):
        msg = []                                  
        question = self.getCurrentQuestion()
        if (question):
            qr = self.getQuestionResultForQuestion(question)
            if (not qr.hasSubmittedQuestion()):
                '''this could only happen if double click on button'''
                # what to do, student want to submit the same answer twice
                # no don't allow that
                msg.append(True)
                msg.append('Already answered')
                return msg
            else:
                msg.append(False)
                msg.append('Your answer has been saved.') 
                return msg
    def openQuiz(self):
        #qr = self.getStudentQuestionResult()
        # get the last question
        question = self.getCurrentQuestion()
        if (question):
            qr = self.getQuestionResultForQuestion(question)
            if (qr.hasSubmittedQuestion()):       
                #Set this question as false
                # For the moment the result is not restored
                # should print out results for wrong question
                 
                #self.setCandidateAnswerToQuestion('no answer')
                value = 'no answer'
                qr.setCandidateAnswer([value], question.getOriginalQuestion())
                correctans = qr.getCorrectAnswer()
                if value in correctans:
                    origquestion = question.getOriginalQuestion()
                    # this can lead to database conflict error
                    # WHAT TO DO????
                    #qobj = question[0].getObject()
                    origquestion.numcorrect = origquestion.numcorrect + 1
                    correct = 1
                else:
                    correct = 0
                qr.gotAnswer()
                self.setScore(correct)
                qr.reindexObject()
            #quizquestionstring = qr.getQuizInfo()
                self.writetolog(qr)       
                return True
            else:
                return False
        else:
            '''no question set yet'''
            return False
    security.declareProtected(PERMISSION_STUDENT, 'writetolog')
    def writetolog(self, qr):
        # FIXME !!!!
        # add code to check if dir exists and then create..
        logdir = productdir + '/log'
        if (not (os.path.exists(logdir))):
            os.mkdir(logdir)
        f = open(logdir+'/questionandanswer.txt','a')
        #qr = self.getStudentQuestionResult()
        #qresults = self.getFolderContents(contentFilter={"portal_type": "QuestionResult"})
        #qr = qresults[0].getObject()
        text = qr.getQuizInfo()
        text = text + str(datetime.now()) + "\n"
        f.write(text)
        f.close()
        #os.system('echo ' + text + ' >> /tmp/twquiz/questionandanswer.txt')
    
    def setNewQuestionInTest(self, suggestedanswer, correctids, questpath, qid):
        
        #notify(NewQuizQuestionEvent(self, suggestedanswer, correctids, questpath, qid))
        question = self.getCurrentQuestion()
        if (question):
            qr = self.getQuestionResultForQuestion(question)
        #qresults = self.getFolderContents(contentFilter={"portal_type": "QuestionResult"})
        #qr = qresults[0].getObject()
        #self.manage_delObjects(qresults)
        ##randid = qr.getStudid()
        ##lecpath = qr.getLecturepath()
        ##ids = self.objectIds() # Plone 3 or older
        #ids = folder.keys()      # Plone 4 or newer
        
        #ids = []
        ##if len(ids) > 0:
            #manage_delObject will mutate the list
            # so we cannot give it tuple returned by objectIds()
         ##   ids = list(ids)
         ##   self.manage_delObjects(ids)
        ##qr = self.createQuestionResult()
        ##qr.setStudentId(self.Creator())
        
        #parent = aq_parent(self)
        #lecpath = parent.getPhyisicalPath()
        ##qr.setLecturepath(lecpath)
        ##self.setStudentQuestionResult(qr)
        
        ##transaction.begin()

            qr.setNewQuestion(suggestedanswer, correctids, questpath, qid)
        ##qr._p_changed = True
        ##self._p_changed = True
        ##transaction.commit()
        #portal_catalog = getToolByName(self, 'portal_catalog')
        #students = portal_catalog.unrestrictedSearchResults({'portal_type' : 'StudentList'})
        #if (len(students) > 0):
        #    numlists = str(len(students))
            
        #    objid = students[0].getObject()
            #objid.addStudent(candidateId)
        #    randid = objid.getStudentIdNumber(self.Creator())
            
        ##qr.setStudentId(randid)
            qr.reindexObject()
    # This method is only called once after object creation.
    #security.declarePrivate('at_post_create_script')
    #def at_post_create_script(self):
    #    self.tryWorkflowAction("publish", ignoreErrors=True)
        
    def at_post_edit_script(self):
        '''function called after edit in the main edit view of the tutorial.'''
    #    self.changed = True
   
        #qresults = self.getFolderContents(contentFilter={"portal_type": "QuestionResult"})
        #if (len(qresults) > 0):
        #    qr = qresults[0].getObject()
        #    self.setStudentQuestionResult(qr) 
    #security.declarePrivate('tryWorkflowAction')
    #def tryWorkflowAction(self, action, ignoreErrors=False, comment=None):
    #    wtool = self.portal_workflow
    #    wf = wtool.getWorkflowsFor(self)[0]
    #    if wf.isActionSupported(self, action):
    #        if comment is None:
    #            #userId = getSecurityManager().getUser().getId()
    #            comment = 'State changed' 
    #        wtool.doActionFor(self, action, comment=comment)
    #    elif not ignoreErrors:
    #        raise TypeError('Unsupported workflow action %s for object %s.'
    #                        % (repr(action), repr(self)))
    #def getError(self):
    #    self.portal_factory.doCr()
    #def createQuestionResult(self):
    #    """Create a new questionresult object for student and initialize it."""
    #    typeName = 'QuestionResult'
    #    id=self.generateUniqueId(typeName)
    #    if self.portal_factory.getFactoryTypes().has_key(typeName):
    #        o = self.restrictedTraverse('portal_factory/' + typeName + '/' + id)
    #    else:
    #        newId = self.invokeFactory(id=id, type_name=typeName)
    #        if newId is None or newId == '':
    #            newId = id
    #        o=getattr(self, newId, None)
    
    #    if o is None:
    #        raise Exception
    #    o = self.portal_factory.doCreate(o, id)
    #    o.setTitle('Question result')
    #    o.reindexObject()
    #    return o
    def removeQuestion(self):
        portal_catalog = getToolByName(self, 'portal_catalog')
        questions = self.portal_catalog.searchResults(
            portal_type = "InvisibleQuestion",
            sort_on="Date",
            path='/'.join(self.getPhysicalPath()),
            )

        
        if (len(questions) > 7):
            '''should removes the oldest one'''
            self.manage_delObjects([questions[0].getId])

    def createQuestion(self):
        """Create a new questionresult object for student and initialize it."""
        # if neede delete a question
        # only keep 8 questons going
        typeName = 'InvisibleQuestion'
        self.removeQuestion()
        id=self.generateUniqueId(typeName)
        if self.portal_factory.getFactoryTypes().has_key(typeName):
            o = self.restrictedTraverse('portal_factory/' + typeName + '/' + id)
        else:
            newId = self.invokeFactory(id=id, type_name=typeName)
            if newId is None or newId == '':
                newId = id
            o=getattr(self, newId, None)
    
        if o is None:
            raise Exception
        o = self.portal_factory.doCreate(o, id)
        #o.setTitle('Question result')
        
        invquest = self.getStudentQuestions()
        invquest.append(o)
        self.setStudentQuestions(invquest)
        self.setCurrentQuestion(o)
        
        return o   
Example #20
0
from AccessControl import ClassSecurityInfo
from Products.CMFCore.permissions import View,ModifyPortalContent
from Products.CMFCore.utils import getToolByName

from zope.interface import implements
from actions_proxy import updateAliases, base_aliases

COREBlogCategorySchema = ATContentTypeSchema.copy() +  Schema((

    IntegerField('internal_id',
        searchable=False,
        isMetadata=True,
        mutator="setInternal_id",
        widget=IntegerWidget(label='Internal ID',
            description='',
            visible={'view':'invisible','edit':'hidden'},
            ),
        ),

    ImageField('category_image',
        widget=ImageWidget(label='Category image',
            description='',
            label_msgid='label_category_image',
            description_msgid='help_category_image',
            i18n_domain='plone',
            ),
        sizes={ 'icon':(16,16)},
        ),

    ),
    marshall=PrimaryFieldMarshaller(),
Example #21
0
#$Id: PersonSQL.py,v 1.2 2004/06/07 20:08:48 andy Exp $
#Copyright: ClearWind Consulting Ltd
#License: http://www.clearwind.ca/license

from Products.Archetypes.public import Schema
from Products.Archetypes.public import IntegerField, StringField
from Products.Archetypes.public import IntegerWidget, StringField
from Products.Archetypes.SQLStorage import PostgreSQLStorage
from config import PROJECT_NAME

schema = BaseSchema + Schema((
    IntegerField(
        'age',
        validators=(("isInt", )),
        storage=SQLStorage(),
        widget=IntegerWidget(label="Your age"),
    ),
    StringField('email',
                validators=('isEmail', ),
                index="TextIndex",
                storage=SQLStorage(),
                widget=StringWidget(label='Email', )),
))


class PersonSQL(BaseContent):
    """Our person object"""
    schema = schema


registerType(PersonSQL, PROJECT_NAME)