Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes
plone.app.controlpanel.types.TypesControlPanel Class Reference
Inheritance diagram for plone.app.controlpanel.types.TypesControlPanel:
Inheritance graph
[legend]
Collaboration diagram for plone.app.controlpanel.types.TypesControlPanel:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def type_id
def fti
def __call__
def versioning_policies
def selectable_types
def selected_type_title
def selected_type_description
def is_addable
def is_discussion_allowed
def current_versioning_policy
def is_searchable
def current_workflow
def available_workflows
def new_workflow
def have_new_workflow
def default_workflow
def real_workflow
def new_workflow_is_different
def new_workflow_is_none
def new_workflow_description
def new_workflow_available_states
def suggested_state_map

Public Attributes

 type_id

Static Public Attributes

tuple template = ViewPageTemplateFile('types.pt')

Detailed Description

Definition at line 41 of file types.py.


Member Function Documentation

Perform the update and redirect if necessary, or render the page

Definition at line 62 of file types.py.

00062 
00063     def __call__(self):
00064         """Perform the update and redirect if necessary, or render the page
00065         """
00066         postback = True
00067         context = aq_inner(self.context)
00068 
00069         form = self.request.form
00070         submitted = form.get('form.submitted', False)
00071         save_button = form.get('form.button.Save', None) is not None
00072         cancel_button = form.get('form.button.Cancel', None) is not None
00073         type_id = form.get('old_type_id', None)
00074 
00075         if submitted and not cancel_button:
00076             if type_id:
00077                 portal_types = getToolByName(self.context, 'portal_types')
00078                 portal_repository = getToolByName(self.context,
00079                                                   'portal_repository')
00080                 portal_properties = getToolByName(self.context,
00081                                                   'portal_properties')
00082                 site_properties = getattr(portal_properties, 'site_properties')
00083 
00084                 fti = getattr(portal_types, type_id)
00085 
00086                 # Set FTI properties
00087 
00088                 addable = form.get('addable', False)
00089                 allow_discussion = form.get('allow_discussion', False)
00090 
00091                 fti.manage_changeProperties(global_allow = bool(addable),
00092                                             allow_discussion = bool(allow_discussion))
00093 
00094                 version_policy = form.get('versionpolicy', "off")
00095                 if version_policy!=self.current_versioning_policy():
00096                     newpolicy=[p for p in VERSION_POLICIES if p["id"]==version_policy][0]
00097 
00098 
00099                     versionable_types = list(portal_repository.getVersionableContentTypes())
00100                     if not newpolicy["policy"]:
00101                         if type_id in versionable_types:
00102                             versionable_types.remove(type_id)
00103                     else:
00104                         if type_id not in versionable_types:
00105                             versionable_types.append(type_id)
00106 
00107                     for policy in portal_repository.listPolicies():
00108                         policy_id = policy.getId()
00109                         if policy_id in newpolicy["policy"]:
00110                             portal_repository.addPolicyForContentType(type_id, policy_id)
00111                         else:
00112                             portal_repository.removePolicyFromContentType(type_id, policy_id)
00113 
00114                     portal_repository.setVersionableContentTypes(versionable_types)
00115 
00116                 searchable = form.get('searchable', False)
00117                 blacklisted = list(site_properties.getProperty('types_not_searched'))
00118                 if searchable and type_id in blacklisted:
00119                     blacklisted.remove(type_id)
00120                 elif not searchable and type_id not in blacklisted:
00121                     blacklisted.append(type_id)
00122                 site_properties.manage_changeProperties(types_not_searched = \
00123                                                         blacklisted)
00124 
00125             # Update workflow
00126             if self.have_new_workflow() and \
00127                form.get('form.workflow.submitted', False) and \
00128                save_button:
00129                 if self.new_workflow_is_different():
00130                     new_wf = self.new_workflow()
00131                     if new_wf == '[none]':
00132                         chain = ()
00133                     elif new_wf == '(Default)':
00134                         chain = new_wf
00135                     else:
00136                         chain = (new_wf,)
00137                     state_map = dict([(s['old_state'], s['new_state']) for s in \
00138                                       form.get('new_wfstates', [])])
00139                     if state_map.has_key('[none]'):
00140                         state_map[None] = state_map['[none]']
00141                         del state_map['[none]']
00142                     if type_id:
00143                         type_ids=(type_id,)
00144                     else:
00145                         wt = getToolByName(self.context, 'portal_workflow')
00146                         tt = getToolByName(self.context, 'portal_types')
00147                         nondefault = [info[0] for info in wt.listChainOverrides()]
00148                         type_ids = [type for type in tt.listContentTypes() if type not in nondefault]
00149                         wt.setDefaultChain(','.join(chain))
00150                         chain='(Default)'
00151 
00152                     remap_workflow(context, type_ids=type_ids, chain=chain,
00153                                    state_map=state_map)
00154                 else:
00155                     portal_workflow = getToolByName(context, 'portal_workflow')
00156                     if self.new_workflow()=='(Default)':
00157                         # The WorkflowTool API can not handle this sanely
00158                         cbt=portal_workflow._chains_by_type
00159                         if cbt.has_key(type_id):
00160                             del cbt[type_id]
00161                     else:
00162                         portal_workflow.setChainForPortalTypes((type_id,),
00163                                 self.new_workflow())
00164 
00165                 self.request.response.redirect('%s/@@types-controlpanel?\
00166 type_id=%s' % (context.absolute_url() , type_id))
00167                 postback = False
00168 
00169         elif cancel_button:
00170             self.request.response.redirect(self.context.absolute_url() + \
00171                                            '/plone_control_panel')
00172             postback = False
00173 
00174         if postback:
00175             return self.template()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 258 of file types.py.

00258 
00259     def available_workflows(self):
00260         vocab_factory = getUtility(IVocabularyFactory,
00261                                    name="plone.app.vocabularies.Workflows")
00262         workflows = []
00263         for v in vocab_factory(self.context):
00264             if v.title:
00265                 title = translate(v.title, context=self.request)
00266             else:
00267                 title = translate(v.token, domain='plone', context=self.request)
00268             workflows.append(dict(id=v.value, title=title) )
00269         def _key(v):
00270             return v['title']
00271         workflows.sort(key=_key)
00272         if self.type_id:
00273             # Only offer a default workflow option on a real type
00274             default_workflow = self.default_workflow(False)
00275             default_title = translate(default_workflow.title,
00276                                       domain='plone', context=self.request)
00277             workflows.insert(0, dict(id='(Default)',
00278                     title=_(u"label_default_workflow_title",
00279                             default=u"Default workflow (${title})",
00280                             mapping=dict(title=default_title)),
00281                     description=format_description(default_workflow.description, self.request)))
00282 
00283         return workflows

Here is the call graph for this function:

Definition at line 209 of file types.py.

00209 
00210     def current_versioning_policy(self):
00211         portal_repository = getToolByName(self.context, 'portal_repository')
00212         if self.type_id not in portal_repository.getVersionableContentTypes():
00213             return "off"
00214         policy = set(portal_repository.getPolicyMap().get(self.type_id, ()))
00215         for info in VERSION_POLICIES:
00216             if set(info["policy"]) == policy:
00217                 return info["id"]
00218         return None

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 226 of file types.py.

00226 
00227     def current_workflow(self):
00228         context = aq_inner(self.context)
00229         portal_workflow = getToolByName(context, 'portal_workflow')
00230         try:
00231             nondefault = [info[0] for info in portal_workflow.listChainOverrides()]
00232             if self.type_id in nondefault:
00233                 wf_id = portal_workflow.getChainForPortalType(self.type_id)[0]
00234             else:
00235                 default_workflow = self.default_workflow(False)
00236                 default_title = translate(default_workflow.title,
00237                                           domain='plone',
00238                                           context=self.request)
00239                 return dict(id='(Default)',
00240                         title=_(u"label_default_workflow_title",
00241                                 default=u"Default workflow (${title})",
00242                                 mapping=dict(title=default_title)),
00243                         description=format_description(default_workflow.description, self.request))
00244         except IndexError:
00245             return dict(id='[none]',
00246                     title=_(u"label_no_workflow",
00247                         default=u"No workflow"),
00248                     description=[
00249                         _(u"description_no_workflow",
00250                         default=u"This type has no workflow. The visibilty of "
00251                                 u"items of this type is determined by the "
00252                                 u"folder they are in.")])
00253         wf = getattr(portal_workflow, wf_id)
00254         title = translate(wf.title,
00255                           domain='plone',
00256                           context=self.request)        
00257         return dict(id=wf.id, title=title, description=format_description(wf.description, self.request))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 302 of file types.py.

00302 
00303     def default_workflow(self, id_only=True):
00304         portal_workflow = getToolByName(self.context, 'portal_workflow')
00305         id = portal_workflow.getDefaultChain()[0]
00306         if id_only:
00307             return id
00308         else:
00309             return portal_workflow.getWorkflowById(id)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 57 of file types.py.

00057 
00058     def fti(self):
00059         type_id = self.type_id
00060         portal_types = getToolByName(self.context, 'portal_types')
00061         return getattr(portal_types, type_id)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 298 of file types.py.

00298 
00299     def have_new_workflow(self):
00300         return self.current_workflow()['id'] != self.new_workflow()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 203 of file types.py.

00203 
00204     def is_addable(self):
00205         return self.fti.getProperty('global_allow', False)

Definition at line 206 of file types.py.

00206 
00207     def is_discussion_allowed(self):
00208         return self.fti.getProperty('allow_discussion', False)

Definition at line 219 of file types.py.

00219 
00220     def is_searchable(self):
00221         context = aq_inner(self.context)
00222         portal_properties = getToolByName(context, 'portal_properties')
00223         blacklisted = portal_properties.site_properties.types_not_searched
00224         return (self.type_id not in blacklisted)

Here is the call graph for this function:

Definition at line 285 of file types.py.

00285 
00286     def new_workflow(self):
00287         current_workflow = self.current_workflow()['id']
00288         if self.type_id=='':
00289             # If we are looking at the default workflow we need to show
00290             # the real workflow
00291             current_workflow=self.real_workflow(current_workflow)
00292         old_type_id = self.request.form.get('old_type_id', self.type_id)
00293         if old_type_id != self.type_id:
00294             return current_workflow
00295         else:
00296             return self.request.form.get('new_workflow', current_workflow)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 346 of file types.py.

00346 
00347     def new_workflow_available_states(self):
00348         current_workflow = self.current_workflow()['id']
00349         if self.new_workflow_is_different():
00350             new_workflow = self.real_workflow(self.new_workflow())
00351             portal_workflow = getToolByName(self.context, 'portal_workflow')
00352             wf = getattr(portal_workflow, new_workflow)
00353             states = []
00354             for s in wf.states.objectValues():
00355                 title = translate(s.title, domain='plone', context=self.request)
00356                 states.append(dict(id=s.id, title=title))
00357             return states
00358         else:
00359             return []

Here is the call graph for this function:

Definition at line 328 of file types.py.

00328 
00329     def new_workflow_description(self):
00330         portal_workflow = getToolByName(self.context, 'portal_workflow')
00331         current_workflow = self.current_workflow()['id']
00332         new_workflow = self.new_workflow()
00333 
00334         if self.new_workflow_is_different():
00335             if self.new_workflow_is_none():
00336                 return [_(u"description_no_workflow",
00337                     default=u"This type has no workflow. The visibilty of "
00338                             u"items of this type is determined by the "
00339                             u"folder they are in.")]
00340             new_workflow = self.real_workflow(self.new_workflow())
00341             wf = getattr(portal_workflow, new_workflow)
00342             return format_description(wf.description, self.request)
00343 
00344         return None
00345 

Here is the call graph for this function:

Definition at line 318 of file types.py.

00318 
00319     def new_workflow_is_different(self):
00320         new_workflow = self.new_workflow()
00321         current_workflow = self.current_workflow()['id']
00322 
00323         return self.real_workflow(new_workflow)!=self.real_workflow(current_workflow)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 325 of file types.py.

00325 
00326     def new_workflow_is_none(self):
00327         return self.new_workflow() == '[none]'

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 311 of file types.py.

00311 
00312     def real_workflow(self, wf):
00313         if wf=='(Default)':
00314             return self.default_workflow()
00315         else:
00316             return wf

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 182 of file types.py.

00182 
00183     def selectable_types(self):
00184         vocab_factory = getUtility(IVocabularyFactory,
00185                                    name="plone.app.vocabularies.ReallyUserFriendlyTypes")
00186         types = []
00187         for v in vocab_factory(self.context):
00188             if v.title:
00189                 title = translate(v.title, context=self.request)
00190             else:
00191                 title = translate(v.token, domain='plone', context=self.request)
00192             types.append(dict(id=v.value, title=title) )
00193         def _key(v):
00194             return v['title']
00195         types.sort(key=_key)
00196         return types

Here is the call graph for this function:

Definition at line 200 of file types.py.

00200 
00201     def selected_type_description(self):
00202         return self.fti.Description()

Definition at line 197 of file types.py.

00197 
00198     def selected_type_title(self):
00199         return self.fti.Title()

Definition at line 360 of file types.py.

00360 
00361     def suggested_state_map(self):
00362         current_workflow = self.real_workflow(self.current_workflow()['id'])
00363         new_workflow = self.real_workflow(self.new_workflow())
00364 
00365         portal_workflow = getToolByName(self.context, 'portal_workflow')
00366 
00367         if current_workflow == '[none]':
00368             new_wf = getattr(portal_workflow, new_workflow)
00369             default_state = new_wf.initial_state
00370             return [dict(old_id = '[none]',
00371                          old_title = _(u"No workflow"),
00372                          suggested_id = default_state)]
00373 
00374         elif self.new_workflow_is_different():
00375             old_wf = getattr(portal_workflow, current_workflow)
00376             new_wf = getattr(portal_workflow, new_workflow)
00377 
00378             new_states = set([s.id for s in new_wf.states.objectValues()])
00379             default_state = new_wf.initial_state
00380 
00381             states = []
00382             for old in old_wf.states.objectValues():
00383                 title = translate(old.title, domain='plone', context=self.request)
00384                 states.append(
00385                     dict(old_id = old.id,
00386                          old_title = title,
00387                          suggested_id = (old.id in new_states and \
00388                                          old.id or default_state)))
00389             return states
00390         else:
00391             return []

Here is the call graph for this function:

Definition at line 49 of file types.py.

00049 
00050     def type_id(self):
00051         type_id = self.request.get('type_id', None)
00052         if type_id is None:
00053             type_id=''
00054         return type_id

Definition at line 178 of file types.py.

00178 
00179     def versioning_policies(self):
00180         return VERSION_POLICIES


Member Data Documentation

tuple plone.app.controlpanel.types.TypesControlPanel.template = ViewPageTemplateFile('types.pt') [static]

Definition at line 45 of file types.py.

Definition at line 287 of file types.py.


The documentation for this class was generated from the following file: