[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 |
---|
[4789] | 6 | from zope.app.catalog.interfaces import ICatalog |
---|
| 7 | from zope.interface import Interface, Attribute |
---|
[3521] | 8 | from zope import schema |
---|
[4789] | 9 | from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
---|
[4920] | 10 | from waeup.sirp.permissions import RoleSource |
---|
[3521] | 11 | |
---|
[4858] | 12 | class FatalCSVError(Exception): |
---|
| 13 | """Some row could not be processed. |
---|
| 14 | """ |
---|
| 15 | pass |
---|
| 16 | |
---|
[4789] | 17 | def SimpleWAeUPVocabulary(*terms): |
---|
| 18 | """A well-buildt vocabulary provides terms with a value, token and |
---|
| 19 | title for each term |
---|
| 20 | """ |
---|
| 21 | return SimpleVocabulary([ |
---|
| 22 | SimpleTerm(value, value, title) for title, value in terms]) |
---|
| 23 | |
---|
| 24 | class IWAeUPObject(Interface): |
---|
| 25 | """A WAeUP object. |
---|
| 26 | """ |
---|
| 27 | |
---|
| 28 | class IUniversity(IWAeUPObject): |
---|
[3521] | 29 | """Representation of a university. |
---|
| 30 | """ |
---|
| 31 | name = schema.TextLine( |
---|
| 32 | title = u'Name of University', |
---|
| 33 | default = u'Unnamed', |
---|
| 34 | required = True, |
---|
| 35 | ) |
---|
[4789] | 36 | |
---|
| 37 | faculties = Attribute("A container for faculties.") |
---|
| 38 | students = Attribute("A container for students.") |
---|
| 39 | hostels = Attribute("A container for hostels.") |
---|
| 40 | |
---|
| 41 | class IWAeUPContainer(IWAeUPObject): |
---|
| 42 | """A container for WAeUP objects. |
---|
| 43 | """ |
---|
| 44 | |
---|
| 45 | class IWAeUPContained(IWAeUPObject): |
---|
| 46 | """An item contained in an IWAeUPContainer. |
---|
| 47 | """ |
---|
| 48 | |
---|
| 49 | class IStudentContainer(IWAeUPContainer): |
---|
| 50 | """A container for StudentObjects. |
---|
| 51 | """ |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | class IHostelContainer(IWAeUPContainer): |
---|
| 55 | """A container for hostels. |
---|
| 56 | """ |
---|
| 57 | def addHostel(hostel): |
---|
| 58 | """Add an IHostel object. |
---|
| 59 | |
---|
| 60 | Returns the key, under which the object was stored. |
---|
| 61 | """ |
---|
| 62 | |
---|
| 63 | class IHostel(IWAeUPObject): |
---|
| 64 | """Representation of a hostel. |
---|
| 65 | """ |
---|
| 66 | name = schema.TextLine( |
---|
| 67 | title = u'Name of Hostel', |
---|
| 68 | default = u'Nobody', |
---|
| 69 | required = True, |
---|
| 70 | ) |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | class IWAeUPExporter(Interface): |
---|
| 74 | """An exporter for objects. |
---|
| 75 | """ |
---|
| 76 | def export(obj, filepath=None): |
---|
| 77 | """Export by pickling. |
---|
| 78 | |
---|
| 79 | Returns a file-like object containing a representation of `obj`. |
---|
| 80 | |
---|
| 81 | This is done using `pickle`. If `filepath` is ``None``, a |
---|
| 82 | `cStringIO` object is returned, that contains the saved data. |
---|
| 83 | """ |
---|
| 84 | |
---|
| 85 | class IWAeUPXMLExporter(Interface): |
---|
| 86 | """An XML exporter for objects. |
---|
| 87 | """ |
---|
| 88 | def export(obj, filepath=None): |
---|
| 89 | """Export as XML. |
---|
| 90 | |
---|
| 91 | Returns an XML representation of `obj`. |
---|
| 92 | |
---|
| 93 | If `filepath` is ``None``, a StringIO` object is returned, |
---|
| 94 | that contains the transformed data. |
---|
| 95 | """ |
---|
| 96 | |
---|
| 97 | class IWAeUPXMLImporter(Interface): |
---|
| 98 | """An XML import for objects. |
---|
| 99 | """ |
---|
| 100 | def doImport(filepath): |
---|
| 101 | """Create Python object from XML. |
---|
| 102 | |
---|
| 103 | Returns a Python object. |
---|
| 104 | """ |
---|
| 105 | |
---|
[4858] | 106 | class IBatchProcessor(Interface): |
---|
| 107 | """A batch processor that handles mass-operations. |
---|
| 108 | """ |
---|
| 109 | name = schema.TextLine( |
---|
| 110 | title = u'Importer name' |
---|
| 111 | ) |
---|
| 112 | |
---|
| 113 | mode = schema.Choice( |
---|
| 114 | title = u'Import mode', |
---|
| 115 | values = ['create', 'update', 'remove'] |
---|
| 116 | ) |
---|
| 117 | |
---|
| 118 | def doImport(path): |
---|
| 119 | """Read data from ``path`` and update connected object. |
---|
| 120 | """ |
---|
| 121 | |
---|
| 122 | class ISchemaTypeConverter(Interface): |
---|
| 123 | """A converter for zope.schema.types. |
---|
| 124 | """ |
---|
| 125 | def convert(string): |
---|
| 126 | """Convert string to certain schema type. |
---|
| 127 | """ |
---|
| 128 | |
---|
| 129 | |
---|
[4789] | 130 | class IUserAccount(IWAeUPObject): |
---|
| 131 | """A user account. |
---|
| 132 | """ |
---|
| 133 | name = schema.TextLine( |
---|
| 134 | title = u'User ID', |
---|
| 135 | description = u'Loginname', |
---|
| 136 | required = True,) |
---|
| 137 | title = schema.TextLine( |
---|
| 138 | title = u'Username', |
---|
| 139 | description = u'Real name', |
---|
| 140 | required = False,) |
---|
| 141 | description = schema.TextLine( |
---|
| 142 | title = u'User description', |
---|
| 143 | required = False,) |
---|
| 144 | password = schema.Password( |
---|
| 145 | title = u'Password', |
---|
| 146 | required = True,) |
---|
| 147 | roles = schema.List( |
---|
| 148 | title = u'Roles', |
---|
| 149 | value_type = schema.Choice(source=RoleSource())) |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | class IUserContainer(IWAeUPObject): |
---|
| 153 | """A container for users (principals). |
---|
| 154 | |
---|
| 155 | These users are used for authentication purposes. |
---|
| 156 | """ |
---|
| 157 | |
---|
| 158 | def addUser(name, password, title=None, description=None): |
---|
| 159 | """Add a user. |
---|
| 160 | """ |
---|
| 161 | |
---|
| 162 | def delUser(name): |
---|
| 163 | """Delete a user if it exists. |
---|
| 164 | """ |
---|
| 165 | |
---|
| 166 | class IDataCenter(IWAeUPObject): |
---|
| 167 | """A data center. |
---|
| 168 | |
---|
| 169 | TODO : declare methods, at least those needed by pages. |
---|
| 170 | """ |
---|
| 171 | pass |
---|
| 172 | |
---|
| 173 | class IDataCenterFile(Interface): |
---|
| 174 | """A data center file. |
---|
| 175 | """ |
---|
[4858] | 176 | |
---|
| 177 | name = schema.TextLine( |
---|
| 178 | title = u'Filename') |
---|
| 179 | |
---|
| 180 | size = schema.TextLine( |
---|
| 181 | title = u'Human readable file size') |
---|
| 182 | |
---|
| 183 | uploaddate = schema.TextLine( |
---|
| 184 | title = u'Human readable upload datetime') |
---|
| 185 | |
---|
| 186 | lines = schema.Int( |
---|
| 187 | title = u'Number of lines in file') |
---|
| 188 | |
---|
[4789] | 189 | def getDate(): |
---|
| 190 | """Get creation timestamp from file in human readable form. |
---|
| 191 | """ |
---|
| 192 | |
---|
| 193 | def getSize(): |
---|
| 194 | """Get human readable size of file. |
---|
| 195 | """ |
---|
[4858] | 196 | |
---|
| 197 | def getLinesNumber(): |
---|
| 198 | """Get number of lines of file. |
---|
| 199 | """ |
---|
[4882] | 200 | |
---|
| 201 | class IDataCenterStorageMovedEvent(IObjectEvent): |
---|
| 202 | """Emitted, when the storage of a datacenter changes. |
---|
| 203 | """ |
---|