Changeset 3437 in products for quintagroup.plonetabs/trunk/quintagroup/plonetabs/browser/plonetabs.py
- Timestamp:
- Apr 20, 2012 10:04:56 AM (12 years ago)
- Location:
- quintagroup.plonetabs/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.plonetabs/trunk
- Property svn:mergeinfo
-
old new 1 1 /quintagroup.plonetabs/branches/plone4:3076-3243 2 /quintagroup.plonetabs/branches/tests:3394-3436
-
- Property svn:mergeinfo
-
quintagroup.plonetabs/trunk/quintagroup/plonetabs/browser/plonetabs.py
r3244 r3437 24 24 from Products.statusmessages.interfaces import IStatusMessage 25 25 26 from quintagroup.plonetabs.config import *26 from quintagroup.plonetabs.config import PROPERTY_SHEET, FIELD_NAME 27 27 from quintagroup.plonetabs import messageFactory as _ 28 28 from interfaces import IPloneTabsControlPanel … … 39 39 cookie_name = 'ploneTabsMode' 40 40 41 41 42 class PloneTabsControlPanel(PloneKSSView): 42 43 … … 60 61 postback = True 61 62 errors = {} 62 context = aq_inner(self.context)63 63 64 64 form = self.request.form 65 action = form.get("action", "")66 65 submitted = form.get('form.submitted', False) 67 66 … … 148 147 IStatusMessage(self.request).addStatusMessage( 149 148 _(u"'${id}' action successfully added.", 150 mapping={'id': action.id}), type="info")149 mapping={'id': action.id}), type="info") 151 150 self.redirect(search="category=%s" % cat_name) 152 151 return False … … 179 178 else: 180 179 errs.update(self.processErrors(errors, 181 sufix='_%s' % id)) # add edit form sufix to error ids180 sufix='_%s' % id)) # add edit form sufix to error ids 182 181 IStatusMessage(self.request).addStatusMessage( 183 182 _(u"Please correct the indicated errors."), type="error") … … 214 213 self.moveAction(id, cat_name, steps=1) 215 214 IStatusMessage(self.request).addStatusMessage( 216 215 _(u"'${id}' action moved up.", mapping={'id': id}), type="info") 217 216 self.redirect(search="category=%s" % cat_name) 218 217 return False … … 247 246 """Redirect to @@plonetabs-controlpanel configlet""" 248 247 if not url: 249 portal_url = 248 portal_url = getMultiAdapter((self.context, self.request), 250 249 name=u"plone_portal_state").portal_url() 251 250 url = '%s/%s' % (portal_url, "@@plonetabs-controlpanel") … … 302 301 """See interface""" 303 302 tool = getToolByName(self.context, "portal_actions") 304 return len(tool.listActions(categories=[category, ])) > 0303 return len(tool.listActions(categories=[category, ])) > 0 305 304 306 305 def getPortalActions(self, category="portal_tabs"): … … 322 321 site_properties = getToolByName(self.context, 323 322 "portal_properties").site_properties 324 return not site_properties.getProperty("disable_folder_sections", False) 323 return not site_properties.getProperty("disable_folder_sections", 324 False) 325 325 326 326 def isNotFoldersGenerated(self): … … 364 364 query = {} 365 365 rootPath = getNavigationRoot(context) 366 query['path'] = {'query' : rootPath, 'depth': 1}366 query['path'] = {'query': rootPath, 'depth': 1} 367 367 query['portal_type'] = utils.typesToList(context) 368 368 … … 388 388 excludedIds = {} 389 389 for id in idsNotToList: 390 excludedIds[id] =1390 excludedIds[id] = 1 391 391 392 392 rawresult = portal_catalog.searchResults(**query) … … 396 396 if not excludedIds.has_key(item.getId): 397 397 id, item_url = get_view_url(item) 398 data = {'name' 399 'id' 400 'url' 398 data = {'name': utils.pretty_title_or_id(context, item), 399 'id': id, 400 'url': item_url, 401 401 'description': item.Description, 402 'exclude_from_nav' 402 'exclude_from_nav': item.exclude_from_nav} 403 403 result.append(data) 404 404 … … 426 426 def portal_tabs(self): 427 427 """See global-sections viewlet""" 428 actions = context_state = getMultiAdapter((self.context, self.request), 429 name=u"plone_context_state").actions() 428 actions = getMultiAdapter((self.context, self.request), 429 name=u'plone_context_state').actions() 430 actions_tabs = [] 431 try: 432 # Plone 4 and higher 433 import plone.app.upgrade 434 plone.app.upgrade # pyflakes 435 except ImportError: 436 actions_tabs = actions 437 if not actions_tabs and 'portal_tabs' in actions: 438 actions_tabs = actions['portal_tabs'] 439 430 440 portal_tabs_view = getMultiAdapter((self.context, self.request), 431 441 name="portal_tabs_view") 432 if 'portal_tabs' in actions:433 actions_tabs = actions['portal_tabs']434 else:435 actions_tabs = []436 442 return portal_tabs_view.topLevelTabs(actions=actions_tabs) 437 443 … … 513 519 ksscore = self.getCommandSet("core") 514 520 content = self.getGeneratedTabs() 515 ksscore.replaceInnerHTML(ksscore.getHtmlIdSelector('roottabs'), content) 521 ksscore.replaceInnerHTML(ksscore.getHtmlIdSelector('roottabs'), 522 content) 516 523 517 524 # update global-sections viewlet … … 531 538 532 539 if obj_id not in portal.objectIds(): 533 raise KSSExplicitError, \ 534 _(u"Object with '${id}' id doesn't exist in portal root.", 535 mapping={'id': obj_id}) 540 raise KSSExplicitError("Object with %s id doesn't" +\ 541 " exist in portal root." % obj_id) 536 542 537 543 if checked == '1': … … 548 554 value="invisible") 549 555 message = _(u"'${id}' object was included into navigation.", 550 mapping={'id': obj_id})556 mapping={'id': obj_id}) 551 557 else: 552 558 ksscore.addClass(ksscore.getHtmlIdSelector(id), value="invisible") 553 559 message = _(u"'${id}' object was excluded from navigation.", 554 mapping={'id': obj_id})560 mapping={'id': obj_id}) 555 561 556 562 # update global-sections viewlet … … 574 580 value="invisible") 575 581 message = _(u"'${id}' action is now visible.", 576 mapping={'id': act_id})582 mapping={'id': act_id}) 577 583 else: 578 584 ksscore.addClass(ksscore.getHtmlIdSelector(id), value="invisible") 579 585 message = _(u"'${id}' action is now invisible.", 580 mapping={'id': act_id})586 mapping={'id': act_id}) 581 587 self.updatePage(cat_name) 582 588 … … 602 608 # issue portal status message 603 609 self.kss_issueMessage(_(u"'${id}' action successfully removed.", 604 mapping={'id': act_id}))610 mapping={'id': act_id})) 605 611 606 612 @kssaction … … 615 621 # if not errors find (or create) category and set action to it 616 622 ksscore = self.getCommandSet('core') 617 kssplone = self.getCommandSet('plone')618 623 if not errors: 619 624 action = self.addAction(cat_name, data) … … 621 626 # update client 622 627 # add one more action to actions list 623 content = self.getActionsList(category=cat_name, tabs=[action,]) 624 ksscore.insertHTMLAsLastChild(ksscore.getHtmlIdSelector('tabslist'), 625 content) 628 content = self.getActionsList(category=cat_name, tabs=[action, ]) 629 ksscore.insertHTMLAsLastChild( 630 ksscore.getHtmlIdSelector('tabslist'), 631 content) 626 632 627 633 # update reorder controls … … 646 652 647 653 message = _(u"'${id}' action successfully added.", 648 mapping={'id': action.id})654 mapping={'id': action.id}) 649 655 msgtype = "info" 650 656 … … 655 661 if errors.has_key('id') or errors.has_key('available_expr'): 656 662 self.kss_toggleCollapsible( 657 658 663 ksscore.getCssSelector('form[name=addaction_form] ' 664 '.headerAdvanced'), collapse='false') 659 665 660 666 message = _(u"Please correct the indicated errors.") … … 678 684 # collapse advanced section 679 685 self.kss_toggleCollapsible( 680 681 collapse='true')686 ksscore.getCssSelector('form[name=addaction_form] .headerAdvanced'), 687 collapse='true') 682 688 683 689 # reset form inputs … … 705 711 # update client 706 712 ksscore = self.getCommandSet("core") 707 content = self.getActionsList(category=cat_name, tabs=[action_info, ])713 content = self.getActionsList(category=cat_name, tabs=[action_info, ]) 708 714 ksscore.replaceHTML(ksscore.getHtmlIdSelector(id), content) 709 715 … … 722 728 # update client 723 729 ksscore = self.getCommandSet("core") 724 content = self.getActionsList(category=cat_name, tabs=[action, ])730 content = self.getActionsList(category=cat_name, tabs=[action, ]) 725 731 ksscore.replaceHTML(ksscore.getHtmlIdSelector(id), content) 726 732 … … 743 749 html_id = '%s%s%s' % (self.prefix, id, self.sufix) 744 750 ksscore = self.getCommandSet('core') 745 kssplone = self.getCommandSet('plone')746 751 if not errors: 747 752 action = self.updateAction(id, cat_name, data) … … 749 754 # update client 750 755 # replace action item with updated one 751 content = self.getActionsList(category=cat_name, tabs=[action, ])756 content = self.getActionsList(category=cat_name, tabs=[action, ]) 752 757 ksscore.replaceHTML(ksscore.getHtmlIdSelector(html_id), content) 753 758 754 759 message = _(u"'${id}' action successfully updated.", 755 mapping={'id': action.id})760 mapping={'id': action.id}) 756 761 msgtype = "info" 757 762 … … 820 825 def copyAction(self, action): 821 826 """Copy action to dictionary""" 822 action_info = {'description': action.description}827 action_info = {'description': action.description} 823 828 for attr in ACTION_ATTRS: 824 829 action_info[attr] = getattr(action, attr) … … 842 847 chooser.checkName(data['id'], self.context) 843 848 except Exception, e: 844 errors['id'] = self._formatError(e, **{'id': data['id']})849 errors['id'] = self._formatError(e, **{'id': data['id']}) 845 850 846 851 # validate action name … … 968 973 category = self.getActionCategory(cat_name) 969 974 except Exception: 970 raise KSSExplicitError, \ 971 _(u"'${cat_name}' action category does not exist.", 972 mapping={'cat_name': cat_name}) 975 raise KSSExplicitError(u"%s action category does not exist." %\ 976 cat_name) 973 977 974 978 # extract action id from given list item id on client … … 978 982 action = category[action_id] 979 983 except Exception: 980 raise KSSExplicitError, \ 981 _(u"No '${id}' action in '${cat_name}' category.", 982 mapping={'id': action_id, 'cat_name': cat_name}) 984 raise KSSExplicitError("No %s action in %s category." %\ 985 (action_id, cat_name)) 983 986 984 987 return (action_id, category, action) … … 1001 1004 '.error-container' % (id, UI_ATTRS.get(name, name))) 1002 1005 else: 1003 field_selector = ksscore.getCssSelector('form[name=addaction_form] ' 1006 field_selector = ksscore.getCssSelector('form' +\ 1007 '[name=addaction_form] ' 1004 1008 '.field-%s' % UI_ATTRS.get(name, name)) 1005 1009 field_error_selector = ksscore.getCssSelector('form[name=' … … 1023 1027 selector) 1024 1028 if collapsed is not None: 1025 data =command.addParam('collapsed', collapsed)1029 command.addParam('collapsed', collapsed) 1026 1030 if expanded is not None: 1027 data =command.addParam('expanded', expanded)1031 command.addParam('expanded', expanded) 1028 1032 if collapse is not None: 1029 data =command.addParam('collapse', collapse)1033 command.addParam('collapse', collapse) 1030 1034 1031 1035 def kss_resetForm(self, selector): 1032 1036 """KSS Server command to reset form on client""" 1033 command = self.commands.addCommand('plonetabs-resetForm', selector)1034 1037 1035 1038 def kss_blur(self, selector): 1036 1039 """KSS Server command to remove focus from input""" 1037 command =self.commands.addCommand('plonetabs-blur', selector)1040 self.commands.addCommand('plonetabs-blur', selector) 1038 1041 1039 1042 def kss_replaceOrInsert(self, selector, parentSelector, html, … … 1044 1047 command = self.commands.addCommand('plonetabs-replaceOrInsert', 1045 1048 selector) 1046 data =command.addParam('selector', parentSelector)1047 data =command.addHtmlParam('html', html)1048 data =command.addParam('withKssSetup', withKssSetup)1049 command.addParam('selector', parentSelector) 1050 command.addHtmlParam('html', html) 1051 command.addParam('withKssSetup', withKssSetup) 1049 1052 if alternativeHTML: 1050 data =command.addHtmlParam('alternativeHTML', alternativeHTML)1053 command.addHtmlParam('alternativeHTML', alternativeHTML) 1051 1054 if selectorType: 1052 data =command.addParam('selectorType', selectorType)1055 command.addParam('selectorType', selectorType) 1053 1056 if position: 1054 data =command.addParam('position', position)1057 command.addParam('position', position) 1055 1058 if positionSelector: 1056 data =command.addParam('positionSelector', positionSelector)1059 command.addParam('positionSelector', positionSelector) 1057 1060 if positionSelectorType: 1058 data =command.addParam('positionSelectorType',1059 1061 command.addParam('positionSelectorType', 1062 positionSelectorType) 1060 1063 1061 1064 def kss_issueMessage(self, message, msgtype="info"): 1062 1065 """"Issues portal status message and removes it afte 10 seconds""" 1063 1066 ksscore = self.getCommandSet('core') 1064 self.getCommandSet('plone').issuePortalMessage(message, msgtype=msgtype) 1067 self.getCommandSet('plone').issuePortalMessage(message, 1068 msgtype=msgtype) 1065 1069 self.kss_timeout( 1066 1070 ksscore.getHtmlIdSelector('kssPortalMessage'), … … 1071 1075 def kss_timeout(self, selector, **kw): 1072 1076 """KSS Server command to execute plonetabs-timeout client action""" 1073 command =self.commands.addCommand('plonetabs-timeout', selector, **kw)1077 self.commands.addCommand('plonetabs-timeout', selector, **kw) 1074 1078 1075 1079 def renderViewlet(self, manager, name): … … 1117 1121 """Delete action with given id from given category""" 1118 1122 category = self.getActionCategory(cat_name) 1119 category.manage_delObjects(ids=[id, ])1123 category.manage_delObjects(ids=[id, ]) 1120 1124 return True 1121 1125 … … 1125 1129 category = self.getActionCategory(cat_name) 1126 1130 if steps > 0: 1127 category.moveObjectsUp([id, ], steps)1131 category.moveObjectsUp([id, ], steps) 1128 1132 else: 1129 category.moveObjectsDown([id, ], abs(steps))1133 category.moveObjectsDown([id, ], abs(steps)) 1130 1134 return True 1131 1135 return False … … 1170 1174 #ksszope = self.getCommandSet("zope") 1171 1175 #ksszope.refreshViewlet( 1172 1173 1174 1176 #self.getCommandSet("core").getHtmlIdSelector("portal-siteactions"), 1177 #"plone.portalheader", 1178 #"plone.site_actions") 1175 1179 1176 1180 def updateUserPageSection(self): … … 1183 1187 "plone.personal_bar") 1184 1188 1189 1185 1190 class PloneTabsMode(BrowserView): 1186 1191
Note: See TracChangeset
for help on using the changeset viewer.