|
| 1 | +--- |
| 2 | +html_meta: |
| 3 | + "description": "Global functions defined in CMFPlone and plone.app.layout." |
| 4 | + "property=og:description": "Global functions defined in CMFPlone and plone.app.layout." |
| 5 | + "property=og:title": "Global utils and helpers" |
| 6 | + "keywords": "global variables,portal_state,context_state,plone_view,portal_url,helper methods" |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +# Global utils and helpers |
| 11 | + |
| 12 | +Global functions defined in CMFPlone and plone.app.layout. |
| 13 | + |
| 14 | +- portal_state |
| 15 | +- context_state |
| 16 | +- plone_view |
| 17 | + |
| 18 | + |
| 19 | +(backend-global-utils-plone-view-label)= |
| 20 | + |
| 21 | +## plone_view |
| 22 | + |
| 23 | +```python |
| 24 | +def getCurrentUrl(): |
| 25 | + """ Returns the actual url plus the query string. """ |
| 26 | + |
| 27 | +def uniqueItemIndex(pos=0): |
| 28 | + """Return an index iterator.""" |
| 29 | + |
| 30 | +def toLocalizedTime(time, long_format=None, time_only=None): |
| 31 | + """ The time parameter must be either a string that is suitable for |
| 32 | + initializing a DateTime or a DateTime object. Returns a localized |
| 33 | + string. |
| 34 | + """ |
| 35 | + |
| 36 | +def toLocalizedSize(size): |
| 37 | + """ Convert an integer to a localized size string |
| 38 | + 3322 -> 3KB in english, 3Ko in french |
| 39 | + """ |
| 40 | + |
| 41 | +def normalizeString(text): |
| 42 | + """Normalizes a title to an id. |
| 43 | + """ |
| 44 | + |
| 45 | +def isDefaultPageInFolder(): |
| 46 | + """ Returns a boolean indicating whether the current context is the |
| 47 | + default page of its parent folder. |
| 48 | + """ |
| 49 | + |
| 50 | +def isStructuralFolder(): |
| 51 | + """Checks if a given object is a "structural folder". |
| 52 | +
|
| 53 | + That is, a folderish item which does not explicitly implement |
| 54 | + INonStructuralFolder to declare that it doesn't wish to be treated |
| 55 | + as a folder by the navtree, the tab generation etc. |
| 56 | + """ |
| 57 | + |
| 58 | +def navigationRootPath(): |
| 59 | + """Get the current navigation root path |
| 60 | + """ |
| 61 | + |
| 62 | +def navigationRootUrl(): |
| 63 | + """Get the url to the current navigation root |
| 64 | + """ |
| 65 | + |
| 66 | +def getParentObject(): |
| 67 | + """Returns the parent of the current object, equivalent to |
| 68 | + aq_inner(aq_parent(context)), or context.aq_inner.getParentNode() |
| 69 | + """ |
| 70 | + |
| 71 | +def getCurrentFolder(): |
| 72 | + """If the context is the default page of a folder or is not itself a |
| 73 | + folder, the parent is returned, otherwise the object itself is |
| 74 | + returned. This is useful for providing a context for methods |
| 75 | + which wish to act on what is considered the current folder in the |
| 76 | + ui. |
| 77 | + """ |
| 78 | + |
| 79 | +def getCurrentFolderUrl(): |
| 80 | + """Returns the URL of the current folder as determined by |
| 81 | + self.getCurrentFolder(), used heavily in actions. |
| 82 | + """ |
| 83 | + |
| 84 | +def getCurrentObjectUrl(): |
| 85 | + """Returns the URL of the current object unless that object is a |
| 86 | + folder default page, in which case it returns the parent. |
| 87 | + """ |
| 88 | + |
| 89 | +def isFolderOrFolderDefaultPage(): |
| 90 | + """Returns true only if the current object is either a folder (as |
| 91 | + determined by isStructuralFolder) or the default page in context. |
| 92 | + """ |
| 93 | + |
| 94 | +def isPortalOrPortalDefaultPage(): |
| 95 | + """Returns true only if the current object is either the portal object |
| 96 | + or the default page of the portal. |
| 97 | + """ |
| 98 | + |
| 99 | +def getViewTemplateId(): |
| 100 | + """Returns the template Id corresponding to the default view method of |
| 101 | + the context object. |
| 102 | + """ |
| 103 | + |
| 104 | +def showToolbar(): |
| 105 | + """Returns true if the editable border should be shown |
| 106 | + """ |
| 107 | + |
| 108 | +def cropText(text, length, ellipsis): |
| 109 | + """ Crop text on a word boundary """ |
| 110 | + |
| 111 | +def site_encoding(): |
| 112 | + """ returns site encoding """ |
| 113 | + |
| 114 | +def patterns_settings(): |
| 115 | + """ returns mockup pattern settings """ |
| 116 | +``` |
| 117 | + |
| 118 | +(backend-global-utils-portal-state-label)= |
| 119 | + |
| 120 | +## portal_state |
| 121 | + |
| 122 | +```python |
| 123 | +def portal(): |
| 124 | + """The portal object""" |
| 125 | + |
| 126 | +def portal_title(): |
| 127 | + """The title of the portal object""" |
| 128 | + |
| 129 | +def portal_url(): |
| 130 | + """The URL of the portal object""" |
| 131 | + |
| 132 | +def navigation_root(): |
| 133 | + """The navigation root object""" |
| 134 | + |
| 135 | +def navigation_root_title(): |
| 136 | + """The title of the navigation root object""" |
| 137 | + |
| 138 | +def navigation_root_path(): |
| 139 | + """path of the navigation root""" |
| 140 | + |
| 141 | +def navigation_root_url(): |
| 142 | + """The URL of the navigation root""" |
| 143 | + |
| 144 | +def default_language(): |
| 145 | + """The default language in the portal""" |
| 146 | + |
| 147 | +def language(): |
| 148 | + """The current language""" |
| 149 | + |
| 150 | +def locale(): |
| 151 | + """Get the current locale""" |
| 152 | + |
| 153 | +def is_rtl(): |
| 154 | + """Whether or not the portal is being viewed in an RTL language""" |
| 155 | + |
| 156 | +def member(): |
| 157 | + """The current authenticated member""" |
| 158 | + |
| 159 | +def anonymous(): |
| 160 | + """Whether or not the current member is Anonymous""" |
| 161 | + |
| 162 | +def friendly_types(): |
| 163 | + """Get a list of portal types considered "end user" types""" |
| 164 | +``` |
| 165 | + |
| 166 | +(backend-global-utils-context-state-label)= |
| 167 | + |
| 168 | +## context_state |
| 169 | + |
| 170 | +```python |
| 171 | +def current_page_url(): |
| 172 | + """The URL to the current page, including template and query string.""" |
| 173 | + |
| 174 | +def current_base_url(): |
| 175 | + """The current "actual" URL from the request, excluding the query |
| 176 | + string. |
| 177 | + """ |
| 178 | + |
| 179 | +def canonical_object(): |
| 180 | + """The current "canonical" object. |
| 181 | +
|
| 182 | + That is, the current object unless this object is the default page |
| 183 | + in its folder, in which case the folder is returned. |
| 184 | + """ |
| 185 | + |
| 186 | +def canonical_object_url(): |
| 187 | + """The URL to the current "canonical" object. |
| 188 | +
|
| 189 | + That is, the current object unless this object is the default page |
| 190 | + in its folder, in which case the folder is returned. |
| 191 | + """ |
| 192 | + |
| 193 | +def view_url(): |
| 194 | + """URL to use for viewing |
| 195 | +
|
| 196 | + Files and Images get downloaded when they are directly |
| 197 | + called, instead of with /view appended. We want to avoid that. |
| 198 | + """ |
| 199 | + |
| 200 | +def view_template_id(): |
| 201 | + """The id of the view template of the context""" |
| 202 | + |
| 203 | +def is_view_template(): |
| 204 | + """Return True if the currentl URL (in the request) refers to the |
| 205 | + standard "view" of the context (i.e. the "view" tab). |
| 206 | + """ |
| 207 | + |
| 208 | +def object_url(): |
| 209 | + """The URL of the current object""" |
| 210 | + |
| 211 | +def object_title(): |
| 212 | + """The prettified title of the current object""" |
| 213 | + |
| 214 | +def workflow_state(): |
| 215 | + """The workflow state of the current object""" |
| 216 | + |
| 217 | +def parent(): |
| 218 | + """The direct parent of the current object""" |
| 219 | + |
| 220 | +def folder(): |
| 221 | + """The current canonical folder""" |
| 222 | + |
| 223 | +def is_folderish(): |
| 224 | + """True if this is a folderish object, structural or not""" |
| 225 | + |
| 226 | +def is_structural_folder(): |
| 227 | + """True if this is a structural folder""" |
| 228 | + |
| 229 | +def is_default_page(): |
| 230 | + """True if this is the default page of its folder""" |
| 231 | + |
| 232 | +def is_portal_root(): |
| 233 | + """True if this is the portal or the default page in the portal""" |
| 234 | + |
| 235 | +def is_editable(): |
| 236 | + """Whether or not the current object is editable""" |
| 237 | + |
| 238 | +def is_locked(): |
| 239 | + """Whether or not the current object is locked""" |
| 240 | + |
| 241 | +def is_toolbar_visible(): |
| 242 | + """Wether toolbar is visible or not in the actual context""" |
| 243 | + |
| 244 | +def actions(category): |
| 245 | + """The filtered actions in the context. You can restrict the actions |
| 246 | + to just one category. |
| 247 | + """ |
| 248 | + |
| 249 | +def portlet_assignable(): |
| 250 | + """Whether or not the context is capable of having locally assigned |
| 251 | + portlets. |
| 252 | + """ |
| 253 | +``` |
0 commit comments