[7195] | 1 | ## $Id: interfaces.py 9246 2012-09-27 14:46:58Z 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 |
---|
[7819] | 23 | from waeup.kofa.interfaces import (IKofaObject, IKofaContainer) |
---|
[7811] | 24 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
| 25 | from waeup.kofa.university.vocabularies import ( |
---|
[5995] | 26 | course_levels, |
---|
| 27 | CourseSource, |
---|
[7681] | 28 | StudyModeSource, |
---|
| 29 | AppCatSource, |
---|
| 30 | InstTypeSource, |
---|
| 31 | SemesterSource, |
---|
[5995] | 32 | ) |
---|
[5004] | 33 | |
---|
[7819] | 34 | class IFaculty(IKofaContainer): |
---|
[5004] | 35 | """Representation of a university faculty. |
---|
| 36 | """ |
---|
[5948] | 37 | code = schema.TextLine( |
---|
[7707] | 38 | title = _(u'Code'), |
---|
[5948] | 39 | default = u'NA', |
---|
| 40 | required = True, |
---|
| 41 | readonly = True, |
---|
| 42 | ) |
---|
| 43 | |
---|
[5004] | 44 | title = schema.TextLine( |
---|
[7707] | 45 | title = _(u'Name of faculty'), |
---|
| 46 | default = _(u'Unnamed'), |
---|
[5004] | 47 | required = True, |
---|
| 48 | ) |
---|
| 49 | |
---|
[5988] | 50 | title_prefix = schema.Choice( |
---|
[7707] | 51 | title = _(u'Name prefix'), |
---|
[5004] | 52 | default = u'faculty', |
---|
[7681] | 53 | source = InstTypeSource(), |
---|
[5004] | 54 | required = True, |
---|
| 55 | ) |
---|
[6561] | 56 | |
---|
[5988] | 57 | def longtitle(): |
---|
| 58 | """ |
---|
| 59 | Returns the long title of a faculty. |
---|
[6561] | 60 | """ |
---|
| 61 | |
---|
[5951] | 62 | class IFacultyAdd(IFaculty): |
---|
| 63 | """Representation of a university faculty. |
---|
| 64 | """ |
---|
| 65 | code = schema.TextLine( |
---|
[7707] | 66 | title = _(u'Code'), |
---|
| 67 | description = _(u'This code will become part of the URL.'), |
---|
[5951] | 68 | default = u'NA', |
---|
| 69 | required = True, |
---|
| 70 | readonly = False, |
---|
| 71 | ) |
---|
[6561] | 72 | |
---|
| 73 | IFacultyAdd['code'].order = IFaculty['code'].order |
---|
| 74 | |
---|
[7819] | 75 | class IFacultiesContainer(IKofaContainer): |
---|
[5004] | 76 | """A container for faculties. |
---|
| 77 | """ |
---|
| 78 | def addFaculty(faculty): |
---|
| 79 | """Add an IFactulty object. |
---|
| 80 | |
---|
| 81 | """ |
---|
[7819] | 82 | class IDepartment(IKofaObject): |
---|
[5004] | 83 | """Representation of a department. |
---|
| 84 | """ |
---|
[5948] | 85 | code = schema.TextLine( |
---|
[7707] | 86 | title = _(u'Code'), |
---|
[5948] | 87 | default = u'NA', |
---|
| 88 | required = True, |
---|
| 89 | readonly = True, |
---|
| 90 | ) |
---|
| 91 | |
---|
[5004] | 92 | title = schema.TextLine( |
---|
[7707] | 93 | title = _(u'Name of department'), |
---|
| 94 | default = _(u'Unnamed'), |
---|
[5004] | 95 | required = True, |
---|
| 96 | ) |
---|
| 97 | |
---|
[5988] | 98 | title_prefix = schema.Choice( |
---|
[7707] | 99 | title = _(u'Name prefix'), |
---|
[7681] | 100 | source = InstTypeSource(), |
---|
[5004] | 101 | default = u'department', |
---|
| 102 | required = True, |
---|
| 103 | ) |
---|
| 104 | |
---|
| 105 | courses = Attribute("A container for courses.") |
---|
| 106 | certificates = Attribute("A container for certificates.") |
---|
[6561] | 107 | |
---|
[5988] | 108 | def longtitle(): |
---|
| 109 | """ |
---|
| 110 | Returns the long title of a department. |
---|
| 111 | """ |
---|
[6561] | 112 | |
---|
[5951] | 113 | class IDepartmentAdd(IDepartment): |
---|
| 114 | """Representation of a university department. |
---|
| 115 | """ |
---|
| 116 | code = schema.TextLine( |
---|
[7707] | 117 | title = _(u'Code'), |
---|
| 118 | description = _(u'This code will become part of the URL.'), |
---|
[5951] | 119 | default = u'NA', |
---|
| 120 | required = True, |
---|
| 121 | readonly = False, |
---|
| 122 | ) |
---|
[5004] | 123 | |
---|
[6561] | 124 | IDepartmentAdd['code'].order = IDepartment['code'].order |
---|
| 125 | |
---|
[7819] | 126 | class ICoursesContainer(IKofaContainer): |
---|
[5004] | 127 | """A container for faculties. |
---|
| 128 | """ |
---|
[6640] | 129 | def addCourse(course): |
---|
[5004] | 130 | """Add an ICourse object. |
---|
| 131 | |
---|
| 132 | Returns the key, under which the object was stored. |
---|
| 133 | """ |
---|
| 134 | |
---|
[7819] | 135 | class ICourse(IKofaObject): |
---|
[5004] | 136 | """Representation of a course. |
---|
| 137 | """ |
---|
| 138 | code = schema.TextLine( |
---|
[7707] | 139 | title = _(u'Code'), |
---|
[5004] | 140 | default = u'NA', |
---|
| 141 | required = True, |
---|
| 142 | readonly = True, |
---|
| 143 | ) |
---|
| 144 | |
---|
| 145 | title = schema.TextLine( |
---|
[7707] | 146 | title = _(u'Title of course'), |
---|
| 147 | default = _(u'Unnamed'), |
---|
[5004] | 148 | required = True, |
---|
| 149 | ) |
---|
| 150 | |
---|
| 151 | credits = schema.Int( |
---|
[7707] | 152 | title = _(u'Credits'), |
---|
[5004] | 153 | default = 0, |
---|
| 154 | required = False, |
---|
| 155 | ) |
---|
[6561] | 156 | |
---|
[5004] | 157 | passmark = schema.Int( |
---|
[7707] | 158 | title = _(u'Passmark'), |
---|
[5004] | 159 | default = 40, |
---|
| 160 | required = False, |
---|
| 161 | ) |
---|
| 162 | |
---|
| 163 | semester = schema.Choice( |
---|
[7707] | 164 | title = _(u'Semester/Term'), |
---|
[7601] | 165 | default = 9, |
---|
[7681] | 166 | source = SemesterSource(), |
---|
[5004] | 167 | required = True, |
---|
| 168 | ) |
---|
[6561] | 169 | |
---|
[9220] | 170 | former_course = schema.Bool( |
---|
| 171 | title = _(u'Former Course'), |
---|
| 172 | description = _( |
---|
| 173 | u'If this attribute is being set all certificate courses ' |
---|
| 174 | 'referring to this course will be automatically deleted.'), |
---|
| 175 | required = False, |
---|
| 176 | default = False, |
---|
| 177 | ) |
---|
| 178 | |
---|
[6008] | 179 | def longtitle(): |
---|
| 180 | """ |
---|
| 181 | Returns the long title of a course. |
---|
[6561] | 182 | """ |
---|
[5004] | 183 | |
---|
[5951] | 184 | class ICourseAdd(ICourse): |
---|
| 185 | """Representation of a course. |
---|
| 186 | """ |
---|
| 187 | code = schema.TextLine( |
---|
[7707] | 188 | title = _(u'Code'), |
---|
| 189 | description = _(u'Enter unique course code which will become part of the URL.'), |
---|
[5951] | 190 | default = u'NA', |
---|
| 191 | required = True, |
---|
| 192 | readonly = False, |
---|
| 193 | ) |
---|
[5004] | 194 | |
---|
[6561] | 195 | ICourseAdd['code'].order = ICourse['code'].order |
---|
| 196 | |
---|
[7819] | 197 | class ICertificate(IKofaObject): |
---|
[5004] | 198 | """Representation of a certificate. |
---|
| 199 | """ |
---|
| 200 | code = schema.TextLine( |
---|
[7707] | 201 | title = _(u'Code'), |
---|
[5004] | 202 | default = u'NA', |
---|
| 203 | required = True, |
---|
[5948] | 204 | readonly = True, |
---|
[5004] | 205 | ) |
---|
| 206 | |
---|
| 207 | title = schema.TextLine( |
---|
[7707] | 208 | title = _(u'Title'), |
---|
[8299] | 209 | default = _(u'Unnamed Certificate'), |
---|
[5004] | 210 | required = True, |
---|
| 211 | ) |
---|
| 212 | |
---|
[5986] | 213 | study_mode = schema.Choice( |
---|
[7707] | 214 | title = _(u'Study Mode'), |
---|
[7681] | 215 | source = StudyModeSource(), |
---|
[5951] | 216 | default = u'ug_ft', |
---|
[5004] | 217 | required = True, |
---|
| 218 | ) |
---|
| 219 | |
---|
[5977] | 220 | start_level = schema.Choice( |
---|
[7707] | 221 | title = _(u'Start Level'), |
---|
[5977] | 222 | vocabulary = course_levels, |
---|
| 223 | default = 100, |
---|
[5004] | 224 | required = True, |
---|
| 225 | ) |
---|
[6561] | 226 | |
---|
[5977] | 227 | end_level = schema.Choice( |
---|
[7707] | 228 | title = _(u'End Level'), |
---|
[5977] | 229 | vocabulary = course_levels, |
---|
| 230 | default = 500, |
---|
[5004] | 231 | required = True, |
---|
| 232 | ) |
---|
[6561] | 233 | |
---|
[5986] | 234 | application_category = schema.Choice( |
---|
[7707] | 235 | title = _(u'Application Category'), |
---|
[7681] | 236 | source = AppCatSource(), |
---|
[5951] | 237 | default = u'basic', |
---|
[5986] | 238 | required = True, |
---|
[6561] | 239 | ) |
---|
[5004] | 240 | |
---|
[8299] | 241 | school_fee_1 = schema.Float( |
---|
| 242 | title = _(u'Initial School Fee'), |
---|
| 243 | required = False, |
---|
| 244 | ) |
---|
| 245 | |
---|
| 246 | school_fee_2 = schema.Float( |
---|
| 247 | title = _(u'Returning School Fee'), |
---|
| 248 | required = False, |
---|
| 249 | ) |
---|
| 250 | |
---|
[8967] | 251 | school_fee_3 = schema.Float( |
---|
[8970] | 252 | title = _(u'Foreigner Initial School Fee'), |
---|
[8967] | 253 | required = False, |
---|
| 254 | ) |
---|
| 255 | |
---|
| 256 | school_fee_4 = schema.Float( |
---|
[8970] | 257 | title = _(u'Foreigner Returning School Fee'), |
---|
[8967] | 258 | required = False, |
---|
| 259 | ) |
---|
| 260 | |
---|
[6008] | 261 | def longtitle(): |
---|
| 262 | """ |
---|
| 263 | Returns the long title of a certificate. |
---|
[6561] | 264 | """ |
---|
[6008] | 265 | |
---|
[8472] | 266 | @invariant |
---|
| 267 | def check_pg_conditions(cert): |
---|
| 268 | if cert.start_level == 999 and not cert.end_level == 999: |
---|
| 269 | raise Invalid(_("Start level and end level must correspond.")) |
---|
| 270 | if cert.end_level == 999 and not cert.start_level == 999: |
---|
| 271 | raise Invalid(_("Start level and end level must correspond.")) |
---|
| 272 | if cert.study_mode.startswith('pg') and not cert.start_level == 999: |
---|
| 273 | raise Invalid(_( |
---|
| 274 | "Study mode, start level and end level must correspond.")) |
---|
| 275 | if cert.start_level == 999 and not cert.study_mode.startswith('pg'): |
---|
| 276 | raise Invalid(_( |
---|
| 277 | "Study mode, start level and end level must correspond.")) |
---|
| 278 | |
---|
| 279 | |
---|
[5951] | 280 | class ICertificateAdd(ICertificate): |
---|
| 281 | """Representation of a certificate. |
---|
| 282 | """ |
---|
| 283 | code = schema.TextLine( |
---|
[7707] | 284 | title = _(u'Code'), |
---|
[5951] | 285 | default = u'NA', |
---|
[7707] | 286 | description = _(u'Enter unique certificate code which will become part of the URL.'), |
---|
[5951] | 287 | required = True, |
---|
| 288 | readonly = False, |
---|
| 289 | ) |
---|
[6561] | 290 | |
---|
| 291 | ICertificateAdd['code'].order = ICertificate['code'].order |
---|
| 292 | |
---|
[7819] | 293 | class ICertificatesContainer(IKofaContainer): |
---|
[5004] | 294 | """A container for certificates. |
---|
| 295 | """ |
---|
[6640] | 296 | def addCertificate(certificate): |
---|
[5004] | 297 | """Add an ICertificate object. |
---|
| 298 | |
---|
| 299 | Returns the key, under which the object was stored. |
---|
| 300 | """ |
---|
| 301 | |
---|
[7819] | 302 | class ICertificateCourse(IKofaObject): |
---|
[6561] | 303 | """A certificatecourse is referring a course and provides some own |
---|
| 304 | attributes. |
---|
[5004] | 305 | """ |
---|
| 306 | course = schema.Choice( |
---|
[8920] | 307 | title = _(u'Course'), |
---|
[5004] | 308 | source = CourseSource(), |
---|
[5950] | 309 | readonly = True, |
---|
[5004] | 310 | ) |
---|
[6561] | 311 | |
---|
[5977] | 312 | level = schema.Choice( |
---|
[7707] | 313 | title = _(u'Level'), |
---|
[5004] | 314 | required = True, |
---|
[5977] | 315 | vocabulary = course_levels, |
---|
[5950] | 316 | readonly = False, |
---|
[5004] | 317 | ) |
---|
| 318 | |
---|
[7665] | 319 | mandatory = schema.Bool( |
---|
[9246] | 320 | title = _(u'Registration required'), |
---|
[9035] | 321 | required = False, |
---|
[5950] | 322 | default = True, |
---|
[5004] | 323 | ) |
---|
| 324 | |
---|
| 325 | def getCourseCode(): |
---|
[5977] | 326 | """Return the code of the course referred to. |
---|
[5004] | 327 | |
---|
| 328 | This is needed for cataloging. |
---|
| 329 | """ |
---|
[6561] | 330 | |
---|
[6008] | 331 | def longtitle(): |
---|
| 332 | """ |
---|
| 333 | Returns the long title of a certificatecourse. |
---|
[6561] | 334 | """ |
---|
| 335 | |
---|
| 336 | |
---|
[5951] | 337 | class ICertificateCourseAdd(ICertificateCourse): |
---|
[6561] | 338 | """A certificatecourse is referring a course and |
---|
[5951] | 339 | provides some own attributes. |
---|
| 340 | """ |
---|
| 341 | course = schema.Choice( |
---|
[7707] | 342 | title = _(u'Course'), |
---|
[5951] | 343 | source = CourseSource(), |
---|
| 344 | readonly = False, |
---|
| 345 | ) |
---|
[6561] | 346 | |
---|
| 347 | ICertificateCourseAdd['course'].order = ICertificateCourse['course'].order |
---|