[3521] | 1 | ## |
---|
| 2 | ## interfaces.py |
---|
[4789] | 3 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
| 4 | from zope.component import getUtility |
---|
[4882] | 5 | from zope.component.interfaces import IObjectEvent |
---|
[5056] | 6 | try: |
---|
| 7 | from zope.catalog.interfaces import ICatalog |
---|
| 8 | except ImportError: |
---|
| 9 | # BBB |
---|
| 10 | from zope.app.catalog.interfaces import ICatalog |
---|
[5955] | 11 | from zope.interface import Interface, Attribute, implements |
---|
[3521] | 12 | from zope import schema |
---|
[4789] | 13 | from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
---|
[4920] | 14 | from waeup.sirp.permissions import RoleSource |
---|
[3521] | 15 | |
---|
[5955] | 16 | |
---|
[4858] | 17 | class FatalCSVError(Exception): |
---|
| 18 | """Some row could not be processed. |
---|
| 19 | """ |
---|
| 20 | pass |
---|
| 21 | |
---|
[4789] | 22 | def SimpleWAeUPVocabulary(*terms): |
---|
| 23 | """A well-buildt vocabulary provides terms with a value, token and |
---|
| 24 | title for each term |
---|
| 25 | """ |
---|
| 26 | return SimpleVocabulary([ |
---|
| 27 | SimpleTerm(value, value, title) for title, value in terms]) |
---|
| 28 | |
---|
| 29 | class IWAeUPObject(Interface): |
---|
| 30 | """A WAeUP object. |
---|
[5663] | 31 | |
---|
| 32 | This is merely a marker interface. |
---|
[4789] | 33 | """ |
---|
| 34 | |
---|
| 35 | class IUniversity(IWAeUPObject): |
---|
[3521] | 36 | """Representation of a university. |
---|
| 37 | """ |
---|
| 38 | name = schema.TextLine( |
---|
| 39 | title = u'Name of University', |
---|
| 40 | default = u'Unnamed', |
---|
| 41 | required = True, |
---|
| 42 | ) |
---|
[5955] | 43 | |
---|
[6065] | 44 | title = schema.TextLine( |
---|
| 45 | title = u'Title of frontpage', |
---|
| 46 | default = u'No Title', |
---|
| 47 | required = False, |
---|
| 48 | ) |
---|
| 49 | |
---|
[5407] | 50 | skin = schema.Choice( |
---|
| 51 | title = u'Skin', |
---|
| 52 | default = u'waeuptheme-gray1.css', |
---|
[5968] | 53 | vocabulary = 'waeup.sirp.browser.theming.ThemesVocabulary', |
---|
[5407] | 54 | required = True, |
---|
| 55 | ) |
---|
[6065] | 56 | |
---|
| 57 | frontpage = schema.Text( |
---|
| 58 | title = u'Human readable frontpage in reST format', |
---|
| 59 | required = False, |
---|
| 60 | default = u'This is the SIRP frontpage.' |
---|
| 61 | ) |
---|
[4789] | 62 | |
---|
| 63 | faculties = Attribute("A container for faculties.") |
---|
| 64 | students = Attribute("A container for students.") |
---|
| 65 | hostels = Attribute("A container for hostels.") |
---|
| 66 | |
---|
| 67 | class IWAeUPContainer(IWAeUPObject): |
---|
| 68 | """A container for WAeUP objects. |
---|
| 69 | """ |
---|
| 70 | |
---|
| 71 | class IWAeUPContained(IWAeUPObject): |
---|
| 72 | """An item contained in an IWAeUPContainer. |
---|
| 73 | """ |
---|
| 74 | |
---|
| 75 | class IStudentContainer(IWAeUPContainer): |
---|
| 76 | """A container for StudentObjects. |
---|
| 77 | """ |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | class IHostelContainer(IWAeUPContainer): |
---|
| 81 | """A container for hostels. |
---|
| 82 | """ |
---|
| 83 | def addHostel(hostel): |
---|
| 84 | """Add an IHostel object. |
---|
| 85 | |
---|
| 86 | Returns the key, under which the object was stored. |
---|
| 87 | """ |
---|
| 88 | |
---|
| 89 | class IHostel(IWAeUPObject): |
---|
| 90 | """Representation of a hostel. |
---|
| 91 | """ |
---|
| 92 | name = schema.TextLine( |
---|
| 93 | title = u'Name of Hostel', |
---|
| 94 | default = u'Nobody', |
---|
| 95 | required = True, |
---|
| 96 | ) |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | class IWAeUPExporter(Interface): |
---|
| 100 | """An exporter for objects. |
---|
| 101 | """ |
---|
| 102 | def export(obj, filepath=None): |
---|
| 103 | """Export by pickling. |
---|
| 104 | |
---|
| 105 | Returns a file-like object containing a representation of `obj`. |
---|
| 106 | |
---|
| 107 | This is done using `pickle`. If `filepath` is ``None``, a |
---|
| 108 | `cStringIO` object is returned, that contains the saved data. |
---|
| 109 | """ |
---|
| 110 | |
---|
| 111 | class IWAeUPXMLExporter(Interface): |
---|
| 112 | """An XML exporter for objects. |
---|
| 113 | """ |
---|
| 114 | def export(obj, filepath=None): |
---|
| 115 | """Export as XML. |
---|
| 116 | |
---|
| 117 | Returns an XML representation of `obj`. |
---|
| 118 | |
---|
| 119 | If `filepath` is ``None``, a StringIO` object is returned, |
---|
| 120 | that contains the transformed data. |
---|
| 121 | """ |
---|
| 122 | |
---|
| 123 | class IWAeUPXMLImporter(Interface): |
---|
| 124 | """An XML import for objects. |
---|
| 125 | """ |
---|
| 126 | def doImport(filepath): |
---|
| 127 | """Create Python object from XML. |
---|
| 128 | |
---|
| 129 | Returns a Python object. |
---|
| 130 | """ |
---|
| 131 | |
---|
[4858] | 132 | class IBatchProcessor(Interface): |
---|
| 133 | """A batch processor that handles mass-operations. |
---|
| 134 | """ |
---|
| 135 | name = schema.TextLine( |
---|
| 136 | title = u'Importer name' |
---|
| 137 | ) |
---|
| 138 | |
---|
| 139 | mode = schema.Choice( |
---|
| 140 | title = u'Import mode', |
---|
| 141 | values = ['create', 'update', 'remove'] |
---|
| 142 | ) |
---|
| 143 | |
---|
[5476] | 144 | def doImport(path, headerfields, mode='create', user='Unknown', |
---|
| 145 | logger=None): |
---|
[4858] | 146 | """Read data from ``path`` and update connected object. |
---|
[5476] | 147 | |
---|
| 148 | `headerfields` is a list of headerfields as read from the file |
---|
| 149 | to import. |
---|
| 150 | |
---|
| 151 | `mode` gives the import mode to use (``'create'``, |
---|
| 152 | ``'update'``, or ``'remove'``. |
---|
| 153 | |
---|
| 154 | `user` is a string describing the user performing the |
---|
| 155 | import. Normally fetched from current principal. |
---|
| 156 | |
---|
| 157 | `logger` is the logger to use during import. |
---|
[4858] | 158 | """ |
---|
| 159 | |
---|
| 160 | class ISchemaTypeConverter(Interface): |
---|
| 161 | """A converter for zope.schema.types. |
---|
| 162 | """ |
---|
| 163 | def convert(string): |
---|
| 164 | """Convert string to certain schema type. |
---|
| 165 | """ |
---|
| 166 | |
---|
| 167 | |
---|
[4789] | 168 | class IUserAccount(IWAeUPObject): |
---|
| 169 | """A user account. |
---|
| 170 | """ |
---|
| 171 | name = schema.TextLine( |
---|
| 172 | title = u'User ID', |
---|
| 173 | description = u'Loginname', |
---|
| 174 | required = True,) |
---|
| 175 | title = schema.TextLine( |
---|
| 176 | title = u'Username', |
---|
| 177 | description = u'Real name', |
---|
| 178 | required = False,) |
---|
| 179 | description = schema.TextLine( |
---|
| 180 | title = u'User description', |
---|
| 181 | required = False,) |
---|
| 182 | password = schema.Password( |
---|
| 183 | title = u'Password', |
---|
| 184 | required = True,) |
---|
| 185 | roles = schema.List( |
---|
| 186 | title = u'Roles', |
---|
| 187 | value_type = schema.Choice(source=RoleSource())) |
---|
| 188 | |
---|
| 189 | |
---|
| 190 | class IUserContainer(IWAeUPObject): |
---|
| 191 | """A container for users (principals). |
---|
| 192 | |
---|
| 193 | These users are used for authentication purposes. |
---|
| 194 | """ |
---|
| 195 | |
---|
| 196 | def addUser(name, password, title=None, description=None): |
---|
| 197 | """Add a user. |
---|
| 198 | """ |
---|
| 199 | |
---|
| 200 | def delUser(name): |
---|
| 201 | """Delete a user if it exists. |
---|
| 202 | """ |
---|
| 203 | |
---|
| 204 | class IDataCenter(IWAeUPObject): |
---|
| 205 | """A data center. |
---|
| 206 | |
---|
| 207 | TODO : declare methods, at least those needed by pages. |
---|
| 208 | """ |
---|
| 209 | pass |
---|
| 210 | |
---|
| 211 | class IDataCenterFile(Interface): |
---|
| 212 | """A data center file. |
---|
| 213 | """ |
---|
[4858] | 214 | |
---|
| 215 | name = schema.TextLine( |
---|
| 216 | title = u'Filename') |
---|
| 217 | |
---|
| 218 | size = schema.TextLine( |
---|
| 219 | title = u'Human readable file size') |
---|
| 220 | |
---|
| 221 | uploaddate = schema.TextLine( |
---|
| 222 | title = u'Human readable upload datetime') |
---|
| 223 | |
---|
| 224 | lines = schema.Int( |
---|
| 225 | title = u'Number of lines in file') |
---|
| 226 | |
---|
[4789] | 227 | def getDate(): |
---|
| 228 | """Get creation timestamp from file in human readable form. |
---|
| 229 | """ |
---|
| 230 | |
---|
| 231 | def getSize(): |
---|
| 232 | """Get human readable size of file. |
---|
| 233 | """ |
---|
[4858] | 234 | |
---|
| 235 | def getLinesNumber(): |
---|
| 236 | """Get number of lines of file. |
---|
| 237 | """ |
---|
[4882] | 238 | |
---|
| 239 | class IDataCenterStorageMovedEvent(IObjectEvent): |
---|
| 240 | """Emitted, when the storage of a datacenter changes. |
---|
| 241 | """ |
---|
[5007] | 242 | |
---|
| 243 | class IQueryResultItem(Interface): |
---|
| 244 | """An item in a search result. |
---|
| 245 | """ |
---|
| 246 | url = schema.TextLine( |
---|
| 247 | title = u'URL that links to the found item') |
---|
| 248 | title = schema.TextLine( |
---|
| 249 | title = u'Title displayed in search results.') |
---|
| 250 | description = schema.Text( |
---|
| 251 | title = u'Longer description of the item found.') |
---|
| 252 | |
---|
[5013] | 253 | class IWAeUPSIRPPluggable(Interface): |
---|
| 254 | """A component that might be plugged into a WAeUP SIRP app. |
---|
[5658] | 255 | |
---|
| 256 | Components implementing this interface are referred to as |
---|
| 257 | 'plugins'. They are normally called when a new |
---|
| 258 | :class:`waeup.sirp.app.University` instance is created. |
---|
| 259 | |
---|
| 260 | Plugins can setup and update parts of the central site without the |
---|
| 261 | site object (normally a :class:`waeup.sirp.app.University` object) |
---|
| 262 | needing to know about that parts. The site simply collects all |
---|
| 263 | available plugins, calls them and the plugins care for their |
---|
[5676] | 264 | respective subarea like the applicants area or the datacenter |
---|
[5658] | 265 | area. |
---|
| 266 | |
---|
| 267 | Currently we have no mechanism to define an order of plugins. A |
---|
| 268 | plugin should therefore make no assumptions about the state of the |
---|
| 269 | site or other plugins being run before and instead do appropriate |
---|
| 270 | checks if necessary. |
---|
| 271 | |
---|
| 272 | Updates can be triggered for instance by the respective form in |
---|
| 273 | the site configuration. You normally do updates when the |
---|
| 274 | underlying software changed. |
---|
[5013] | 275 | """ |
---|
[5069] | 276 | def setup(site, name, logger): |
---|
| 277 | """Create an instance of the plugin. |
---|
[5013] | 278 | |
---|
[5658] | 279 | The method is meant to be called by the central app (site) |
---|
| 280 | when it is created. |
---|
| 281 | |
---|
| 282 | `site`: |
---|
| 283 | The site that requests a setup. |
---|
| 284 | |
---|
| 285 | `name`: |
---|
| 286 | The name under which the plugin was registered (utility name). |
---|
| 287 | |
---|
| 288 | `logger`: |
---|
| 289 | A standard Python logger for the plugins use. |
---|
[5069] | 290 | """ |
---|
| 291 | |
---|
| 292 | def update(site, name, logger): |
---|
| 293 | """Method to update an already existing plugin. |
---|
| 294 | |
---|
| 295 | This might be called by a site when something serious |
---|
[5658] | 296 | changes. It is a poor-man replacement for Zope generations |
---|
| 297 | (but probably more comprehensive and better understandable). |
---|
| 298 | |
---|
| 299 | `site`: |
---|
| 300 | The site that requests an update. |
---|
| 301 | |
---|
| 302 | `name`: |
---|
| 303 | The name under which the plugin was registered (utility name). |
---|
| 304 | |
---|
| 305 | `logger`: |
---|
| 306 | A standard Python logger for the plugins use. |
---|
[5069] | 307 | """ |
---|
[5898] | 308 | |
---|
[5899] | 309 | class IAuthPluginUtility(Interface): |
---|
[5898] | 310 | """A component that cares for authentication setup at site creation. |
---|
| 311 | |
---|
| 312 | Utilities providing this interface are looked up when a Pluggable |
---|
| 313 | Authentication Utility (PAU) for any |
---|
| 314 | :class:`waeup.sirp.app.University` instance is created and put |
---|
| 315 | into ZODB. |
---|
| 316 | |
---|
| 317 | The setup-code then calls the `register` method of the utility and |
---|
| 318 | expects a modified (or unmodified) version of the PAU back. |
---|
| 319 | |
---|
| 320 | This allows to define any authentication setup modifications by |
---|
| 321 | submodules or third-party modules/packages. |
---|
| 322 | """ |
---|
| 323 | |
---|
| 324 | def register(pau): |
---|
| 325 | """Register any plugins wanted to be in the PAU. |
---|
| 326 | """ |
---|
| 327 | |
---|
| 328 | def unregister(pau): |
---|
| 329 | """Unregister any plugins not wanted to be in the PAU. |
---|
| 330 | """ |
---|