Example #1
0
def validate_coursebuilder(form, action, data):
    """ Validate the course builder form. """

    division = form.request.form['form.division']
    newdivision = form.request.form['form.newdivision']
    if not division and not newdivision:
        dw = form.widgets.get('division')
        dw._error = WidgetInputError(form.context.__name__, dw.label, _(u'Missing division.'))
        return dw._error

    if newdivision:
        brains = form.context.portal_catalog.searchResults(Type='Division')
        if brains:
            if newdivision in [x.Title.decode('utf-8') for x in brains]:
                dw = form.widgets.get('division')
                dw._error = WidgetInputError(form.context.__name__, 
                                             dw.label, 
                                             _(u'Division with the same title already exists.'))
                return dw._error

    coursename = form.request.form['form.coursename']
    if not coursename:
        cnw = form.widgets.get('coursename')
        cnw._error = WidgetInputError(form.context.__name__, cnw.label, _(u'Missing course name.'))
        return cnw._error
Example #2
0
 def changeAccessibility(self, value):
     """ Provides annotation to placeless script """
     context = self.context
     message = ''        
     if IAccessibilityCompliantable.providedBy(context):
         anno = IAnnotations(context)
         if value == 'True':
             anno['eduCommons.accessible'] = True
             message=_(u'Accessibility Compliant set to True')
         elif value == 'False':
             anno['eduCommons.accessible'] = False
             message=_(u'Accessibility Compliant set to False')
     return message
Example #3
0
 def changeCopyright(self, value):
     """ Provides annotation to placeless script """
     context = self.context
     message = ''        
     if IClearCopyrightable.providedBy(context):
         anno = IAnnotations(context)
         if value == 'True':
             anno['eduCommons.clearcopyright'] = True
             message= _(u'Copyright Cleared')
         elif value == 'False':
             anno['eduCommons.clearcopyright'] = False
             message= _(u'Copyright Revoked')
     return message
Example #4
0
    def action_submit(self, action, data):
        # Convert post variables into email fields

        router = {'Membership' : '*****@*****.**',
                  'Partnership' : '*****@*****.**',
                  'Internship' : '*****@*****.**',
                  'Program' : '*****@*****.**',
                  'Courses' : '*****@*****.**',
                  'Website' : '*****@*****.**', 
                  'Donations'  : '*****@*****.**',
                  'Other' : '*****@*****.**'
                }

        subject = data['subject']
        message = data['body']

        mto = router[subject]

        if data.has_key('email') and data['email']:
            mfrom='%s<%s>' % (data['name'], data['email'].encode('ascii'))
        else:
            # If no return email is provided, use the TO address.
            # Do this so that the from field will pass validation.
            mfrom = mto
        # Post the message
        try:
            self.context.MailHost.secureSend(message, mto=mto, mfrom=mfrom, subject=subject, charset='utf8')
        except MailHostError, e:
            IStatusMessage(self.request).addStatusMessage(_('Feedback request failed.'), type='error')
            url = getMultiAdapter((self.context, self.request), name='absolute_url')()
            self.request.response.redirect(url)
            return ''
Example #5
0
 def action_submit(self, action, data):
     # Convert post variables into email fields
     message = ''
     mto = self.context.email_from_address
     if data.has_key('email') and data['email']:
         mfrom='%s' %data['email'].encode('ascii')
     else:
         # If no return email is provided, use the TO address.
         # Do this so that the from field will pass validation.
         mfrom = mto
     if data['name'] != None:
         name = data['name']
         message += '%s has reported the following content as inappropriate, please review: \n\n' % name
     else:
         message += 'The following content has been reported as inappropriate, please review: \n\n'
     subject = 'Content Reported as Inappropriate'
     message += '\t %s \n\n' % self.context.absolute_url()
     message += data['body']
     # Post the message
     try:
         self.context.MailHost.secureSend(message, mto=mto, mfrom=mfrom, subject=subject, charset='utf8')
     except MailHostError, e:
         IStatusMessage(self.request).addStatusMessage(_('Report Content request failed.'), type='error')
         url = getMultiAdapter((self.context, self.request), name='absolute_url')()
         self.request.response.redirect(url)
         return ''
Example #6
0
    def __call__(self):
        value = ''
        contents = []
        have_results = False

        # Render the Drop Down
        contents.append(self._div('formHelp', _(u'Select from below:'))) 
        contents.append(self._div('value', self.renderValue(value) ) )

        # Render the edit box
        contents.append(self._div('formHelp', _(u'If not found, type in the name below to create a new one:')))
        contents.append(self._div('value', renderElement('input',
                                                         type='text',
                                                         name='form.newdivision',
                                                         id='form.division.textfield')))
                                                      
        contents.append(self._emptyMarker())

        return self._div(self.cssClass, "\n".join(contents))
Example #7
0
def validate_feedback(form, action, data):
    """ Validate the from email address, if it exists. """
    errors = form.validate(action, data)
    if errors:
        return errors
    if data.has_key('email') and data['email']:
        email = data['email'].encode('ascii')
        if not form.context.MailHost.validateSingleEmailAddress(email):
            ew = form.widgets.get('email')
            ew._error = WidgetInputError(form.context.__name__, ew.label, _('Invalid email address'))
            return ew._error
Example #8
0
def remotedivisionsvocab(context):
    """ Get the list of current divisions from OpenOCW and return it as a vocabulary """
    ecprops = context.portal_url.portal_properties.educommons_properties
    remote_url = ecprops.reusecourse_instance
    remote = xmlrpclib.Server(remote_url)
    try:
        terms = remote.retrieveDivisions()
        return SimpleVocabulary([SimpleTerm(x[0], x[1]) for x in terms])
    except xmlrpclib.Fault:
        message = _('The remote site is unavailable of configured incorrectly. Please contact an administrator.')
        url = '%s/folder_contents' % context.absolute_url()
        context.plone_utils.addPortalMessage(message)
        context.request.response.redirect(url)
Example #9
0
File: menu.py Project: dtgit/dtedu
    def getMenuItems(self, context, request):
        """Return menu item entries in a TAL-friendly form."""
        results = []
        context = aq_inner(context)
        
        wf_tool = getToolByName(context, "portal_workflow")
        workflowActions = wf_tool.listActionInfos(object=context)

        for action in workflowActions:
            if action['category'] != 'workflow':
                continue

        locking_info = getMultiAdapter((context, request), name='plone_lock_info')
        if locking_info and locking_info.is_locked_for_current_user():
            return []

        for action in workflowActions:
            if action['category'] != 'workflow':
                continue
            
            actionUrl = action['url']
            if actionUrl == "":
                actionUrl = '%s/content_status_modify?workflow_action=%s' % (context.absolute_url(), action['id'])

            description = ''
            
            transition = action.get('transition', None)
            if transition is not None:
                description = transition.description
            
            for bogus in self.BOGUS_WORKFLOW_ACTIONS:
                if actionUrl.endswith(bogus):
                    if getattr(context, bogus, None) is None:
                        actionUrl = '%s/content_status_modify?workflow_action=%s' % (context.absolute_url(), action['id'],)
                    break

            if action['allowed']:
                results.append({ 'title'        : action['title'],
                                 'description'  : description,
                                 'action'       : actionUrl,
                                 'selected'     : False,
                                 'icon'         : None,
                                 'extra'        : {'id' : 'workflow-transition-%s' % action['id'], 'separator' : None, 'class' : 'kssIgnore'},
                                 'submenu'      : None,
                                 })
        
        url = context.absolute_url()
        
        if len(results) > 0:
            results.append({ 'title'         : _(u'Advanced...'),
                             'description'   : '',
                             'action'        : url + '/content_status_history',
                             'selected'      : False,
                             'icon'          : None,
                             'extra'         : {'id' : '_advanced', 'separator' : 'actionSeparator', 'class' : 'kssIgnore'},
                             'submenu'       : None,
                            })

        if getToolByName(context, 'portal_placeful_workflow', None) is not None:
            results.append({ 'title'         : PloneMessageFactory(u'workflow_policy',default=u'Policy...'),
                             'description'   : '',
                             'action'        : url + '/placeful_workflow_configuration',
                             'selected'      : False,
                             'icon'          : None,
                             'extra'         : {'id' : '_policy', 'separator' : None, 'class' : 'kssIgnore'},
                             'submenu'       : None,
                            })

        return results
Example #10
0


CourseSchema = ATFolderSchema.copy() + Schema((
        
    TextField('text',
              required=False,
              searchable=True,
              primary=True,
              storage = AnnotationStorage(migrate=True),
              validators = ('isTidyHtmlWithCleanup',),
              #validators = ('isTidyHtml',),
              default_output_type = 'text/x-html-safe',
              widget = RichWidget(
                        description = '',
                        label = _(u'Body Text'),
                        rows = 25,
                        allow_file_upload = zconf.ATDocument.allow_document_upload),
             ),

    StringField('courseId',
                required=False,
                widget=StringWidget(label=_(u'Course ID'),
                                    label_msgid='label_course_id',
                        	    description=_(u'The course identifier or catalog number. Also can be used to sequence courses (1.0, 2.0, etc).'),
                                    description_msgid='help_course_id',
                                    ),
                ),

    StringField('term',
                required=False,
Example #11
0
 def getDescriptor(self):
     ecprops = self.context.portal_url.portal_properties.educommons_properties
     if self.isCourseObject():
         return ecprops.course_descriptor + ' ' + _(u'Contents')
     else:
         return ecprops.division_descriptor
Example #12
0
from Products.eduCommons import eduCommonsMessageFactory as _


DivisionSchema = ATFolderSchema.copy() + Schema((
    TextField('text',
              required=False,
              searchable=True,
              primary=True,
              storage = AnnotationStorage(migrate=True),
              validators = ('isTidyHtmlWithCleanup',),
              #validators = ('isTidyHtml',),
              default_output_type = 'text/x-html-safe',
              widget = RichWidget(
                        description = '',
                        label = _(u'Body Text'),
                        rows = 25,
                        allow_file_upload = zconf.ATDocument.allow_document_upload),
              ),
    ),
    marshall=RFC822Marshaller()
    )

finalizeATCTSchema(DivisionSchema)
        


class Division(ATFolder):
    """ The Department/Division content object. """

    implements(IDivision)
Example #13
0
    def action_submit(self, action, data): 
        """ Create a course. """

        # Get existing division, or create a new one
        divname = self.request.form['form.division']
        newdivision = self.request.form['form.newdivision']
        if newdivision:
            portal = self.context.portal_url
            division = self.createObject(portal, 'Division', newdivision.encode('utf-8'), 'division_view')
        else:
            division = None
            path = {'query':('/'), }
            brains = self.context.portal_catalog.searchResults(path=path, id=divname)
            if brains and len(brains) > 0:
                division = brains[0].getObject()

        if not division:
            self.status = _(u'Could not create/find existing division.')
            return

        # Create a new course
        course = self.createObject(division, 
                                   'Course', 
                                   self.request.form['form.coursename'],
                                   'course_view',
                                   courseId=self.request.form['form.courseid'],
                                   term=self.request.form['form.courseterm'])

        if not course:
            self.status = _(u'Could not create course.')
            return

        # Create default templates
        templates = ''
        if self.request.form.has_key('form.templates'):
            templates = self.request.form['form.templates']

        #Determine if a singular or multiple templates are returned
        if type(templates) == type(u''):
            self.createObject(course, 'Document', self.templates[templates], templates)
        elif type(templates) == type([]):            
            for x in self.request.form['form.templates']:
                self.createObject(course, 'Document', self.templates[x], x)

        filename = ''
        packagetype = ''

        if self.request.form.has_key('form.filename'):
            filename = self.request.form['form.filename']

        if self.request.form.has_key('form.packagetype'):
            packagetype = self.request.form['form.packagetype']

            
        if filename != '' and packagetype != '':
            imsvocab = getUtility(IVocabularyFactory, name='imsvocab')(self.context)
            package_xform = imsvocab.getTermByToken(packagetype).value
            self.ims_util.importZipfile(course,filename,package_xform,rtype='eduCommons')            

        # Redirect to the course edit page
        self.request.RESPONSE.redirect(course.absolute_url() + '/edit')