Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.28 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from plone.app.textfield import RichText
  3. from plone.autoform import directives
  4. from plone.dexterity.content import Container
  5. from plone.namedfile import field as namedfile
  6. from plone.supermodel import model
  7. from plone.supermodel.directives import fieldset
  8. from z3c.form.browser.radio import RadioFieldWidget
  9. from zope import schema
  10. from zope.interface import implementer
  11. from yc.courseschedule import _
  12. from AccessControl import ClassSecurityInfo
  13. from plone import api
  14. # needed for vocabulary in Choice
  15. from z3c.form.browser.radio import RadioFieldWidget
  16. from zope.schema.vocabulary import SimpleVocabulary
  17. from zope.schema.vocabulary import SimpleTerm
  18.  
  19. sessionVocabulary = SimpleVocabulary(
  20.     [SimpleTerm(value=u'F', title=_(u'Fall')),
  21.      SimpleTerm(value=u'S', title=_(u'Spring')),
  22.      SimpleTerm(value=u'4w1', title=_(u'4 weeks summer session 1')),
  23.      SimpleTerm(value=u'4w2', title=_(u'4 weeks summer session 2')),
  24.      SimpleTerm(value=u'7w1', title=_(u'7 weeks summer session 1')),
  25.      SimpleTerm(value=u'7w2', title=_(u'7 weeks summer session 2')),
  26.      SimpleTerm(value=u'Win', title=_(u'Winter'))]
  27.     )
  28.  
  29. class ICsDepartment(model.Schema):
  30.     """ Marker interface and Dexterity Python Schema for CsDepartment
  31.    """
  32.     directives.read_permission(school='cmf.ManagePortal')
  33.     directives.write_permission(school='cmf.ManagePortal')
  34.     school = schema.TextLine(
  35.         title=_(u'School'),
  36.     )
  37.     directives.read_permission(croACAD_ORG='cmf.ManagePortal')
  38.     directives.write_permission(croACAD_ORG='cmf.ManagePortal')
  39.     croACAD_ORG = schema.TextLine(
  40.         title=_(u'Academic Organization'),
  41.         description=_(u'eg. EARTH-YRK'),
  42.     )
  43.     directives.read_permission(cssSTRM='cmf.ManagePortal')
  44.     directives.write_permission(cssSTRM='cmf.ManagePortal')
  45.     cssSTRM = schema.TextLine(
  46.         title=_(u'Semester Code'),
  47.         description=_(u'eg. 1189, 1186, 1182'),
  48.     )
  49.     directives.read_permission(cssSession='cmf.ManagePortal')
  50.     directives.write_permission(cssSession='cmf.ManagePortal')
  51.     directives.widget(cssSession=RadioFieldWidget)
  52.     cssSession = schema.Choice(
  53.         title=_(u'Session'),
  54.         vocabulary=sessionVocabulary,
  55.         required=True
  56.     )
  57.  
  58.  
  59.  
  60. @implementer(ICsDepartment)
  61. class CsDepartment(Container):
  62. # Create Title based on Fields
  63.     def setTitle(self,value,**kwargs):
  64.         self.title = self.computeFullname()
  65.  
  66.     def Title(self):
  67.         return self.computeFullname()
  68.  
  69.     def computeFullname(self):
  70.         return str(self.croACAD_ORG.split('-', 1)[0]) + ' - ' + str(self.cssSTRM) + ' - ' + str(self.cssSession)
  71.  
  72. # Create Description based on Fields
  73.     def setDescription(self,value,**kwargs):
  74.         self.description = self.computeDescription()
  75.  
  76.     def Description(self):
  77.         return self.computeDescription()
  78.  
  79.     def computeDescription(self):
  80.         return  str(self.school) + ', ' + str(self.croACAD_ORG) + ' ( '+ str(self.cssSTRM) + ' - ' + str(self.cssSession) + ' )'
  81.  
  82. # permissions
  83.     def setManagers(self,value,**kwargs):
  84.         deptGroup = 'cs-'+ str(self.croACAD_ORG) + '-grp'
  85.         # self.manage_setLocalRoles('deptGroup', ['Contributor','Reader'])
  86.         api.group.grant_roles(groupname='deptGroup',roles=['Contributor', 'Editor'], obj=self)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement