[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 |
---|
[4789] | 11 | from zope.interface import Interface, Attribute |
---|
[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 | |
---|
[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 | |
---|
| 28 | class IWAeUPObject(Interface): |
---|
| 29 | """A WAeUP object. |
---|
| 30 | """ |
---|
| 31 | |
---|
| 32 | class IUniversity(IWAeUPObject): |
---|
[3521] | 33 | """Representation of a university. |
---|
| 34 | """ |
---|
| 35 | name = schema.TextLine( |
---|
| 36 | title = u'Name of University', |
---|
| 37 | default = u'Unnamed', |
---|
| 38 | required = True, |
---|
| 39 | ) |
---|
[4789] | 40 | |
---|
| 41 | faculties = Attribute("A container for faculties.") |
---|
| 42 | students = Attribute("A container for students.") |
---|
| 43 | hostels = Attribute("A container for hostels.") |
---|
| 44 | |
---|
| 45 | class IWAeUPContainer(IWAeUPObject): |
---|
| 46 | """A container for WAeUP objects. |
---|
| 47 | """ |
---|
| 48 | |
---|
| 49 | class IWAeUPContained(IWAeUPObject): |
---|
| 50 | """An item contained in an IWAeUPContainer. |
---|
| 51 | """ |
---|
| 52 | |
---|
| 53 | class IStudentContainer(IWAeUPContainer): |
---|
| 54 | """A container for StudentObjects. |
---|
| 55 | """ |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | class IHostelContainer(IWAeUPContainer): |
---|
| 59 | """A container for hostels. |
---|
| 60 | """ |
---|
| 61 | def addHostel(hostel): |
---|
| 62 | """Add an IHostel object. |
---|
| 63 | |
---|
| 64 | Returns the key, under which the object was stored. |
---|
| 65 | """ |
---|
| 66 | |
---|
| 67 | class IHostel(IWAeUPObject): |
---|
| 68 | """Representation of a hostel. |
---|
| 69 | """ |
---|
| 70 | name = schema.TextLine( |
---|
| 71 | title = u'Name of Hostel', |
---|
| 72 | default = u'Nobody', |
---|
| 73 | required = True, |
---|
| 74 | ) |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | class IWAeUPExporter(Interface): |
---|
| 78 | """An exporter for objects. |
---|
| 79 | """ |
---|
| 80 | def export(obj, filepath=None): |
---|
| 81 | """Export by pickling. |
---|
| 82 | |
---|
| 83 | Returns a file-like object containing a representation of `obj`. |
---|
| 84 | |
---|
| 85 | This is done using `pickle`. If `filepath` is ``None``, a |
---|
| 86 | `cStringIO` object is returned, that contains the saved data. |
---|
| 87 | """ |
---|
| 88 | |
---|
| 89 | class IWAeUPXMLExporter(Interface): |
---|
| 90 | """An XML exporter for objects. |
---|
| 91 | """ |
---|
| 92 | def export(obj, filepath=None): |
---|
| 93 | """Export as XML. |
---|
| 94 | |
---|
| 95 | Returns an XML representation of `obj`. |
---|
| 96 | |
---|
| 97 | If `filepath` is ``None``, a StringIO` object is returned, |
---|
| 98 | that contains the transformed data. |
---|
| 99 | """ |
---|
| 100 | |
---|
| 101 | class IWAeUPXMLImporter(Interface): |
---|
| 102 | """An XML import for objects. |
---|
| 103 | """ |
---|
| 104 | def doImport(filepath): |
---|
| 105 | """Create Python object from XML. |
---|
| 106 | |
---|
| 107 | Returns a Python object. |
---|
| 108 | """ |
---|
| 109 | |
---|
[4858] | 110 | class IBatchProcessor(Interface): |
---|
| 111 | """A batch processor that handles mass-operations. |
---|
| 112 | """ |
---|
| 113 | name = schema.TextLine( |
---|
| 114 | title = u'Importer name' |
---|
| 115 | ) |
---|
| 116 | |
---|
| 117 | mode = schema.Choice( |
---|
| 118 | title = u'Import mode', |
---|
| 119 | values = ['create', 'update', 'remove'] |
---|
| 120 | ) |
---|
| 121 | |
---|
| 122 | def doImport(path): |
---|
| 123 | """Read data from ``path`` and update connected object. |
---|
| 124 | """ |
---|
| 125 | |
---|
| 126 | class ISchemaTypeConverter(Interface): |
---|
| 127 | """A converter for zope.schema.types. |
---|
| 128 | """ |
---|
| 129 | def convert(string): |
---|
| 130 | """Convert string to certain schema type. |
---|
| 131 | """ |
---|
| 132 | |
---|
| 133 | |
---|
[4789] | 134 | class IUserAccount(IWAeUPObject): |
---|
| 135 | """A user account. |
---|
| 136 | """ |
---|
| 137 | name = schema.TextLine( |
---|
| 138 | title = u'User ID', |
---|
| 139 | description = u'Loginname', |
---|
| 140 | required = True,) |
---|
| 141 | title = schema.TextLine( |
---|
| 142 | title = u'Username', |
---|
| 143 | description = u'Real name', |
---|
| 144 | required = False,) |
---|
| 145 | description = schema.TextLine( |
---|
| 146 | title = u'User description', |
---|
| 147 | required = False,) |
---|
| 148 | password = schema.Password( |
---|
| 149 | title = u'Password', |
---|
| 150 | required = True,) |
---|
| 151 | roles = schema.List( |
---|
| 152 | title = u'Roles', |
---|
| 153 | value_type = schema.Choice(source=RoleSource())) |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | class IUserContainer(IWAeUPObject): |
---|
| 157 | """A container for users (principals). |
---|
| 158 | |
---|
| 159 | These users are used for authentication purposes. |
---|
| 160 | """ |
---|
| 161 | |
---|
| 162 | def addUser(name, password, title=None, description=None): |
---|
| 163 | """Add a user. |
---|
| 164 | """ |
---|
| 165 | |
---|
| 166 | def delUser(name): |
---|
| 167 | """Delete a user if it exists. |
---|
| 168 | """ |
---|
| 169 | |
---|
| 170 | class IDataCenter(IWAeUPObject): |
---|
| 171 | """A data center. |
---|
| 172 | |
---|
| 173 | TODO : declare methods, at least those needed by pages. |
---|
| 174 | """ |
---|
| 175 | pass |
---|
| 176 | |
---|
| 177 | class IDataCenterFile(Interface): |
---|
| 178 | """A data center file. |
---|
| 179 | """ |
---|
[4858] | 180 | |
---|
| 181 | name = schema.TextLine( |
---|
| 182 | title = u'Filename') |
---|
| 183 | |
---|
| 184 | size = schema.TextLine( |
---|
| 185 | title = u'Human readable file size') |
---|
| 186 | |
---|
| 187 | uploaddate = schema.TextLine( |
---|
| 188 | title = u'Human readable upload datetime') |
---|
| 189 | |
---|
| 190 | lines = schema.Int( |
---|
| 191 | title = u'Number of lines in file') |
---|
| 192 | |
---|
[4789] | 193 | def getDate(): |
---|
| 194 | """Get creation timestamp from file in human readable form. |
---|
| 195 | """ |
---|
| 196 | |
---|
| 197 | def getSize(): |
---|
| 198 | """Get human readable size of file. |
---|
| 199 | """ |
---|
[4858] | 200 | |
---|
| 201 | def getLinesNumber(): |
---|
| 202 | """Get number of lines of file. |
---|
| 203 | """ |
---|
[4882] | 204 | |
---|
| 205 | class IDataCenterStorageMovedEvent(IObjectEvent): |
---|
| 206 | """Emitted, when the storage of a datacenter changes. |
---|
| 207 | """ |
---|
[5007] | 208 | |
---|
| 209 | class IQueryResultItem(Interface): |
---|
| 210 | """An item in a search result. |
---|
| 211 | """ |
---|
| 212 | url = schema.TextLine( |
---|
| 213 | title = u'URL that links to the found item') |
---|
| 214 | title = schema.TextLine( |
---|
| 215 | title = u'Title displayed in search results.') |
---|
| 216 | description = schema.Text( |
---|
| 217 | title = u'Longer description of the item found.') |
---|
| 218 | |
---|
[5013] | 219 | class IWAeUPSIRPPluggable(Interface): |
---|
| 220 | """A component that might be plugged into a WAeUP SIRP app. |
---|
| 221 | """ |
---|
[5069] | 222 | def setup(site, name, logger): |
---|
| 223 | """Create an instance of the plugin. |
---|
[5013] | 224 | |
---|
[5069] | 225 | The method is meant to be called by the central app on startup. |
---|
| 226 | """ |
---|
| 227 | |
---|
| 228 | def update(site, name, logger): |
---|
| 229 | """Method to update an already existing plugin. |
---|
| 230 | |
---|
| 231 | This might be called by a site when something serious |
---|
| 232 | changes. It is a poor-man replacement for Zope generations. |
---|
| 233 | """ |
---|