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