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