[7195] | 1 | ## $Id: interfaces.py 15422 2019-05-24 09:11:40Z henrik $ |
---|
| 2 | ## |
---|
| 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
| 4 | ## This program is free software; you can redistribute it and/or modify |
---|
| 5 | ## it under the terms of the GNU General Public License as published by |
---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | ## (at your option) any later version. |
---|
| 8 | ## |
---|
| 9 | ## This program is distributed in the hope that it will be useful, |
---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | ## GNU General Public License for more details. |
---|
| 13 | ## |
---|
| 14 | ## You should have received a copy of the GNU General Public License |
---|
| 15 | ## along with this program; if not, write to the Free Software |
---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | ## |
---|
[5004] | 18 | """Interfaces of academics specific objects. |
---|
| 19 | """ |
---|
[7670] | 20 | |
---|
[5004] | 21 | from zope import schema |
---|
[8472] | 22 | from zope.interface import Attribute, invariant, Invalid |
---|
[15422] | 23 | from waeup.kofa.interfaces import ( |
---|
| 24 | IKofaObject, IKofaContainer, validate_id, academic_sessions_vocab) |
---|
[7811] | 25 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
| 26 | from waeup.kofa.university.vocabularies import ( |
---|
[5995] | 27 | course_levels, |
---|
| 28 | CourseSource, |
---|
[7681] | 29 | StudyModeSource, |
---|
| 30 | AppCatSource, |
---|
| 31 | InstTypeSource, |
---|
| 32 | SemesterSource, |
---|
[13617] | 33 | DegreeSource, |
---|
[14638] | 34 | CourseCategorySource |
---|
[5995] | 35 | ) |
---|
[5004] | 36 | |
---|
[7819] | 37 | class IFaculty(IKofaContainer): |
---|
[5004] | 38 | """Representation of a university faculty. |
---|
| 39 | """ |
---|
[5948] | 40 | code = schema.TextLine( |
---|
[7707] | 41 | title = _(u'Code'), |
---|
[5948] | 42 | default = u'NA', |
---|
| 43 | required = True, |
---|
[12414] | 44 | constraint=validate_id, |
---|
[5948] | 45 | ) |
---|
| 46 | |
---|
[5004] | 47 | title = schema.TextLine( |
---|
[7707] | 48 | title = _(u'Name of faculty'), |
---|
[10787] | 49 | default = u'Unnamed', |
---|
[5004] | 50 | required = True, |
---|
| 51 | ) |
---|
| 52 | |
---|
[5988] | 53 | title_prefix = schema.Choice( |
---|
[7707] | 54 | title = _(u'Name prefix'), |
---|
[5004] | 55 | default = u'faculty', |
---|
[7681] | 56 | source = InstTypeSource(), |
---|
[5004] | 57 | required = True, |
---|
| 58 | ) |
---|
[6561] | 59 | |
---|
[14511] | 60 | officer_1 = schema.TextLine( |
---|
| 61 | title = _(u'Faculty Officer 1'), |
---|
| 62 | default = u'', |
---|
| 63 | required = False, |
---|
| 64 | ) |
---|
[6561] | 65 | |
---|
[14511] | 66 | officer_2 = schema.TextLine( |
---|
| 67 | title = _(u'Faculty Officer 2'), |
---|
| 68 | default = u'', |
---|
| 69 | required = False, |
---|
| 70 | ) |
---|
| 71 | |
---|
| 72 | |
---|
[7819] | 73 | class IFacultiesContainer(IKofaContainer): |
---|
[5004] | 74 | """A container for faculties. |
---|
| 75 | """ |
---|
| 76 | def addFaculty(faculty): |
---|
| 77 | """Add an IFactulty object. |
---|
| 78 | |
---|
| 79 | """ |
---|
[7819] | 80 | class IDepartment(IKofaObject): |
---|
[5004] | 81 | """Representation of a department. |
---|
| 82 | """ |
---|
[5948] | 83 | code = schema.TextLine( |
---|
[7707] | 84 | title = _(u'Code'), |
---|
[5948] | 85 | default = u'NA', |
---|
| 86 | required = True, |
---|
[12414] | 87 | constraint=validate_id, |
---|
[5948] | 88 | ) |
---|
| 89 | |
---|
[5004] | 90 | title = schema.TextLine( |
---|
[7707] | 91 | title = _(u'Name of department'), |
---|
[10787] | 92 | default = u'Unnamed', |
---|
[5004] | 93 | required = True, |
---|
| 94 | ) |
---|
| 95 | |
---|
[5988] | 96 | title_prefix = schema.Choice( |
---|
[7707] | 97 | title = _(u'Name prefix'), |
---|
[7681] | 98 | source = InstTypeSource(), |
---|
[5004] | 99 | default = u'department', |
---|
| 100 | required = True, |
---|
| 101 | ) |
---|
| 102 | |
---|
[10634] | 103 | score_editing_disabled = schema.Bool( |
---|
| 104 | title = _(u'Score editing disabled'), |
---|
| 105 | description = _( |
---|
[10642] | 106 | u'Lectures can not edit scores if ticked.'), |
---|
[10634] | 107 | required = False, |
---|
| 108 | default = False, |
---|
| 109 | ) |
---|
| 110 | |
---|
[14511] | 111 | officer_1 = schema.TextLine( |
---|
| 112 | title = _(u'Department Officer 1'), |
---|
| 113 | default = u'', |
---|
| 114 | required = False, |
---|
| 115 | ) |
---|
| 116 | |
---|
| 117 | officer_2 = schema.TextLine( |
---|
| 118 | title = _(u'Department Officer 2'), |
---|
| 119 | default = u'', |
---|
| 120 | required = False, |
---|
| 121 | ) |
---|
| 122 | |
---|
| 123 | officer_3 = schema.TextLine( |
---|
| 124 | title = _(u'Department Officer 3'), |
---|
| 125 | default = u'', |
---|
| 126 | required = False, |
---|
| 127 | ) |
---|
| 128 | |
---|
| 129 | officer_4 = schema.TextLine( |
---|
| 130 | title = _(u'Department Officer 4'), |
---|
| 131 | default = u'', |
---|
| 132 | required = False, |
---|
| 133 | ) |
---|
| 134 | |
---|
[5004] | 135 | courses = Attribute("A container for courses.") |
---|
| 136 | certificates = Attribute("A container for certificates.") |
---|
[6561] | 137 | |
---|
| 138 | |
---|
[7819] | 139 | class ICoursesContainer(IKofaContainer): |
---|
[5004] | 140 | """A container for faculties. |
---|
| 141 | """ |
---|
[6640] | 142 | def addCourse(course): |
---|
[5004] | 143 | """Add an ICourse object. |
---|
| 144 | |
---|
| 145 | Returns the key, under which the object was stored. |
---|
| 146 | """ |
---|
| 147 | |
---|
[7819] | 148 | class ICourse(IKofaObject): |
---|
[5004] | 149 | """Representation of a course. |
---|
| 150 | """ |
---|
| 151 | code = schema.TextLine( |
---|
[7707] | 152 | title = _(u'Code'), |
---|
[5004] | 153 | default = u'NA', |
---|
| 154 | required = True, |
---|
[12414] | 155 | constraint=validate_id, |
---|
[5004] | 156 | ) |
---|
| 157 | |
---|
| 158 | title = schema.TextLine( |
---|
[7707] | 159 | title = _(u'Title of course'), |
---|
[10787] | 160 | default = u'Unnamed', |
---|
[5004] | 161 | required = True, |
---|
| 162 | ) |
---|
| 163 | |
---|
| 164 | credits = schema.Int( |
---|
[7707] | 165 | title = _(u'Credits'), |
---|
[5004] | 166 | default = 0, |
---|
[9315] | 167 | required = True, |
---|
[5004] | 168 | ) |
---|
[6561] | 169 | |
---|
[5004] | 170 | passmark = schema.Int( |
---|
[7707] | 171 | title = _(u'Passmark'), |
---|
[5004] | 172 | default = 40, |
---|
[9315] | 173 | required = True, |
---|
[5004] | 174 | ) |
---|
| 175 | |
---|
| 176 | semester = schema.Choice( |
---|
[7707] | 177 | title = _(u'Semester/Term'), |
---|
[7601] | 178 | default = 9, |
---|
[7681] | 179 | source = SemesterSource(), |
---|
[5004] | 180 | required = True, |
---|
| 181 | ) |
---|
[6561] | 182 | |
---|
[9220] | 183 | former_course = schema.Bool( |
---|
[10830] | 184 | title = _(u'Former course'), |
---|
[9220] | 185 | description = _( |
---|
| 186 | u'If this attribute is being set all certificate courses ' |
---|
| 187 | 'referring to this course will be automatically deleted.'), |
---|
| 188 | required = False, |
---|
| 189 | default = False, |
---|
| 190 | ) |
---|
| 191 | |
---|
[15422] | 192 | results_validated_by = schema.TextLine( |
---|
| 193 | title = _(u'Results validated by'), |
---|
| 194 | default = None, |
---|
| 195 | required = False, |
---|
| 196 | ) |
---|
[5004] | 197 | |
---|
[15422] | 198 | results_validation_date = schema.Datetime( |
---|
| 199 | title = _(u'Results validation date'), |
---|
| 200 | required = False, |
---|
| 201 | readonly = False, |
---|
| 202 | ) |
---|
| 203 | |
---|
| 204 | results_validation_session = schema.Choice( |
---|
| 205 | title = _(u'Results validation session'), |
---|
| 206 | source = academic_sessions_vocab, |
---|
| 207 | required = False, |
---|
| 208 | readonly = False, |
---|
| 209 | ) |
---|
| 210 | |
---|
[7819] | 211 | class ICertificate(IKofaObject): |
---|
[5004] | 212 | """Representation of a certificate. |
---|
| 213 | """ |
---|
| 214 | code = schema.TextLine( |
---|
[7707] | 215 | title = _(u'Code'), |
---|
[5004] | 216 | default = u'NA', |
---|
| 217 | required = True, |
---|
[12414] | 218 | constraint=validate_id, |
---|
[5004] | 219 | ) |
---|
| 220 | |
---|
| 221 | title = schema.TextLine( |
---|
[7707] | 222 | title = _(u'Title'), |
---|
[11838] | 223 | default = u'Unnamed', |
---|
[5004] | 224 | required = True, |
---|
| 225 | ) |
---|
| 226 | |
---|
[5986] | 227 | study_mode = schema.Choice( |
---|
[7707] | 228 | title = _(u'Study Mode'), |
---|
[7681] | 229 | source = StudyModeSource(), |
---|
[5951] | 230 | default = u'ug_ft', |
---|
[5004] | 231 | required = True, |
---|
| 232 | ) |
---|
| 233 | |
---|
[13617] | 234 | degree = schema.Choice( |
---|
| 235 | title = _(u'Degree'), |
---|
| 236 | source = DegreeSource(), |
---|
| 237 | required = False, |
---|
| 238 | ) |
---|
| 239 | |
---|
[5977] | 240 | start_level = schema.Choice( |
---|
[7707] | 241 | title = _(u'Start Level'), |
---|
[5977] | 242 | vocabulary = course_levels, |
---|
| 243 | default = 100, |
---|
[5004] | 244 | required = True, |
---|
| 245 | ) |
---|
[6561] | 246 | |
---|
[5977] | 247 | end_level = schema.Choice( |
---|
[7707] | 248 | title = _(u'End Level'), |
---|
[5977] | 249 | vocabulary = course_levels, |
---|
| 250 | default = 500, |
---|
[5004] | 251 | required = True, |
---|
| 252 | ) |
---|
[6561] | 253 | |
---|
[5986] | 254 | application_category = schema.Choice( |
---|
[7707] | 255 | title = _(u'Application Category'), |
---|
[7681] | 256 | source = AppCatSource(), |
---|
[5951] | 257 | default = u'basic', |
---|
[5986] | 258 | required = True, |
---|
[6561] | 259 | ) |
---|
[5004] | 260 | |
---|
[8299] | 261 | school_fee_1 = schema.Float( |
---|
| 262 | title = _(u'Initial School Fee'), |
---|
| 263 | required = False, |
---|
[13399] | 264 | default = 0.0, |
---|
[8299] | 265 | ) |
---|
| 266 | |
---|
| 267 | school_fee_2 = schema.Float( |
---|
| 268 | title = _(u'Returning School Fee'), |
---|
| 269 | required = False, |
---|
[13399] | 270 | default = 0.0, |
---|
[8299] | 271 | ) |
---|
| 272 | |
---|
[8967] | 273 | school_fee_3 = schema.Float( |
---|
[8970] | 274 | title = _(u'Foreigner Initial School Fee'), |
---|
[8967] | 275 | required = False, |
---|
[13399] | 276 | default = 0.0, |
---|
[8967] | 277 | ) |
---|
| 278 | |
---|
| 279 | school_fee_4 = schema.Float( |
---|
[8970] | 280 | title = _(u'Foreigner Returning School Fee'), |
---|
[8967] | 281 | required = False, |
---|
[13399] | 282 | default = 0.0, |
---|
[8967] | 283 | ) |
---|
| 284 | |
---|
[10166] | 285 | ratio = schema.Float( |
---|
| 286 | title = _(u'Installment Ratio'), |
---|
| 287 | required = False, |
---|
| 288 | min = 0.0, |
---|
| 289 | max = 1.0, |
---|
| 290 | ) |
---|
| 291 | |
---|
[10185] | 292 | custom_textline_1 = schema.TextLine( |
---|
| 293 | title = _(u'Custom Textline 1 (not used)'), |
---|
| 294 | required = False, |
---|
| 295 | ) |
---|
| 296 | |
---|
| 297 | custom_textline_2 = schema.TextLine( |
---|
| 298 | title = _(u'Custom Textline 2 (not used)'), |
---|
| 299 | required = False, |
---|
| 300 | ) |
---|
| 301 | |
---|
| 302 | custom_float_1 = schema.Float( |
---|
| 303 | title = _(u'Custom Float 1 (not used)'), |
---|
| 304 | required = False, |
---|
| 305 | ) |
---|
| 306 | |
---|
| 307 | custom_float_2 = schema.Float( |
---|
| 308 | title = _(u'Custom Float 2 (not used)'), |
---|
| 309 | required = False, |
---|
| 310 | ) |
---|
| 311 | |
---|
[8472] | 312 | @invariant |
---|
| 313 | def check_pg_conditions(cert): |
---|
| 314 | if cert.start_level == 999 and not cert.end_level == 999: |
---|
| 315 | raise Invalid(_("Start level and end level must correspond.")) |
---|
| 316 | if cert.end_level == 999 and not cert.start_level == 999: |
---|
| 317 | raise Invalid(_("Start level and end level must correspond.")) |
---|
| 318 | if cert.study_mode.startswith('pg') and not cert.start_level == 999: |
---|
| 319 | raise Invalid(_( |
---|
| 320 | "Study mode, start level and end level must correspond.")) |
---|
| 321 | if cert.start_level == 999 and not cert.study_mode.startswith('pg'): |
---|
| 322 | raise Invalid(_( |
---|
| 323 | "Study mode, start level and end level must correspond.")) |
---|
| 324 | |
---|
| 325 | |
---|
[7819] | 326 | class ICertificatesContainer(IKofaContainer): |
---|
[5004] | 327 | """A container for certificates. |
---|
| 328 | """ |
---|
[6640] | 329 | def addCertificate(certificate): |
---|
[5004] | 330 | """Add an ICertificate object. |
---|
| 331 | |
---|
| 332 | Returns the key, under which the object was stored. |
---|
| 333 | """ |
---|
| 334 | |
---|
[7819] | 335 | class ICertificateCourse(IKofaObject): |
---|
[6561] | 336 | """A certificatecourse is referring a course and provides some own |
---|
| 337 | attributes. |
---|
[5004] | 338 | """ |
---|
| 339 | course = schema.Choice( |
---|
[8920] | 340 | title = _(u'Course'), |
---|
[5004] | 341 | source = CourseSource(), |
---|
| 342 | ) |
---|
[6561] | 343 | |
---|
[5977] | 344 | level = schema.Choice( |
---|
[7707] | 345 | title = _(u'Level'), |
---|
[5004] | 346 | required = True, |
---|
[5977] | 347 | vocabulary = course_levels, |
---|
[5950] | 348 | readonly = False, |
---|
[5004] | 349 | ) |
---|
| 350 | |
---|
[14638] | 351 | course_category = schema.Choice( |
---|
| 352 | title = _(u'Course Category'), |
---|
| 353 | source = CourseCategorySource(), |
---|
| 354 | required = False, |
---|
| 355 | ) |
---|
| 356 | |
---|
[7665] | 357 | mandatory = schema.Bool( |
---|
[9246] | 358 | title = _(u'Registration required'), |
---|
[9035] | 359 | required = False, |
---|
[5950] | 360 | default = True, |
---|
[5004] | 361 | ) |
---|
| 362 | |
---|
| 363 | def getCourseCode(): |
---|
[5977] | 364 | """Return the code of the course referred to. |
---|
[5004] | 365 | |
---|
| 366 | This is needed for cataloging. |
---|
[10685] | 367 | """ |
---|