~replaceafill/ubuntu/trusty/schooltool/2.8_custom-css

« back to all changes in this revision

Viewing changes to src/schooltool/course/section.py

  • Committer: Gediminas Paulauskas
  • Date: 2014-04-18 16:25:33 UTC
  • mfrom: (1.1.33)
  • Revision ID: menesis@pov.lt-20140418162533-noklnc6b89w2epee
Tags: 1:2.7.0-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
from schooltool.app.security import ConfigurableCrowd
43
43
from schooltool.app.interfaces import ISchoolToolApplication
44
44
from schooltool.app.utils import vocabulary_titled
 
45
from schooltool.app.states import StateStartUpBase
 
46
from schooltool.app.states import RelationshipStates, RelationshipState
45
47
from schooltool.course import interfaces, booking
46
48
from schooltool.group.interfaces import IBaseGroup as IGroup
47
49
from schooltool.person.interfaces import IPerson
 
50
from schooltool.relationship import RelationshipProperty
48
51
from schooltool.relationship.relationship import getRelatedObjects
49
 
from schooltool.relationship import RelationshipProperty
 
52
from schooltool.relationship.temporal import ACTIVE, INACTIVE
 
53
from schooltool.securitypolicy.crowds import Crowd
50
54
from schooltool.schoolyear.subscriber import EventAdapterSubscriber
51
55
from schooltool.schoolyear.subscriber import ObjectEventAdapterSubscriber
52
56
from schooltool.schoolyear.interfaces import ISubscriber
53
57
from schooltool.schoolyear.interfaces import ISchoolYear
54
 
from schooltool.securitypolicy.crowds import Crowd, AggregateCrowd
55
 
from schooltool.securitypolicy.crowds import ClerksCrowd, AdministratorsCrowd
56
58
from schooltool.term.term import getNextTerm
57
59
from schooltool.term.interfaces import ITerm
58
60
 
59
61
from schooltool.common import SchoolToolMessage as _
60
62
 
61
63
 
 
64
SECTION_CONTAINERS_KEY = 'schooltool.course.section'
 
65
COMPLETED = 'c'
 
66
 
 
67
 
62
68
class InvalidSectionLinkException(Exception):
63
69
    pass
64
70
 
206
212
    int_ids = getUtility(IIntIds)
207
213
    term_id = str(int_ids.getId(term))
208
214
    app = ISchoolToolApplication(None)
209
 
    sc = app['schooltool.course.section'].get(term_id, None)
 
215
    sc = app[SECTION_CONTAINERS_KEY].get(term_id, None)
210
216
    if sc is None:
211
 
        sc = app['schooltool.course.section'][term_id] = SectionContainer()
 
217
        sc = app[SECTION_CONTAINERS_KEY][term_id] = SectionContainer()
212
218
    return sc
213
219
 
214
220
 
266
272
class SectionInit(InitBase):
267
273
 
268
274
    def __call__(self):
269
 
        self.app['schooltool.course.section'] = SectionContainerContainer()
 
275
        self.app[SECTION_CONTAINERS_KEY] = SectionContainerContainer()
270
276
 
271
277
 
272
278
class InstructorsCrowd(Crowd):
328
334
                InstructorsCrowd(self.context).contains(principal))
329
335
 
330
336
 
331
 
class SectionCalendarViewers(AggregateCrowd):
332
 
    """Crowd of those who can see the section calendar."""
333
 
    adapts(interfaces.ISection)
334
 
 
335
 
    def crowdFactories(self):
336
 
        return [ClerksCrowd, AdministratorsCrowd,
337
 
                InstructorsCrowd, LearnersCrowd, SectionCalendarSettingCrowd]
338
 
 
339
 
 
340
337
class PersonLearnerAdapter(object):
341
338
    implements(interfaces.ILearner)
342
339
    adapts(IPerson)
373
370
        section_container = interfaces.ISectionContainer(self.object)
374
371
        for section_id in list(section_container.keys()):
375
372
            del section_container[section_id]
 
373
        del section_container.__parent__[section_container.__name__]
376
374
 
377
375
 
378
376
class UnlinkSectionWhenDeleted(ObjectEventAdapterSubscriber):
408
406
                _("Sections must be in consecutive terms"))
409
407
 
410
408
 
411
 
def getSectionRosterEventParticipants(event, rel_type):
412
 
    if rel_type != event.rel_type:
413
 
        return None, None
414
 
    if interfaces.ISection.providedBy(event.participant1):
415
 
        return event.participant1, event.participant2
416
 
    elif interfaces.ISection.providedBy(event.participant2):
417
 
        return event.participant2, event.participant1
418
 
    else:
419
 
        return None, None
420
 
 
421
 
 
422
 
def propagateSectionInstructorAdded(event):
423
 
    section, teacher = getSectionRosterEventParticipants(event,
424
 
        relationships.URIInstruction)
425
 
    if section is None:
426
 
        return
427
 
    if section.next and teacher not in section.next.instructors:
428
 
        section.next.instructors.add(teacher)
429
 
 
430
 
 
431
 
def propagateSectionInstructorRemoved(event):
432
 
    section, teacher = getSectionRosterEventParticipants(event,
433
 
        relationships.URIInstruction)
434
 
    if section is None:
435
 
        return
436
 
    if section.next and teacher in section.next.instructors:
437
 
        section.next.instructors.remove(teacher)
438
 
 
439
 
 
440
 
def propagateSectionStudentAdded(event):
441
 
    section, student = getSectionRosterEventParticipants(event,
442
 
        relationships.URIMembership)
443
 
    if section is None:
444
 
        return
445
 
    if section.next and student not in section.next.members:
446
 
        section.next.members.add(student)
447
 
 
448
 
 
449
 
def propagateSectionStudentRemoved(event):
450
 
    section, student = getSectionRosterEventParticipants(event,
451
 
        relationships.URIMembership)
452
 
    if section is None:
453
 
        return
454
 
    if section.next and student in section.next.members:
455
 
        section.next.members.remove(student)
 
409
def propagateSectionInstructorsChange(event):
 
410
    link = event.link
 
411
    if not (link.rel_type == relationships.URIInstruction and
 
412
            interfaces.ISection.providedBy(event.this)):
 
413
        return
 
414
    section = event.this
 
415
    person = event.other
 
416
    if section.next:
 
417
        collection = section.next.instructors.all()
 
418
        collection.on(event.date).relate(person, event.meaning, event.code)
 
419
 
 
420
 
 
421
def propagateSectionStudentsChange(event):
 
422
    link = event.link
 
423
    if not (link.rel_type == relationships.URIMembership and
 
424
            interfaces.ISection.providedBy(event.this)):
 
425
        return
 
426
    section = event.this
 
427
    person = event.other
 
428
    if section.next:
 
429
        collection = section.next.members.all()
 
430
        collection.on(event.date).relate(person, event.meaning, event.code)
456
431
 
457
432
 
458
433
def copySection(section, target_term):
481
456
 
482
457
def LinkedSectionTermsVocabularyFactory():
483
458
    return linkedSectionTermsVocabulary
 
459
 
 
460
 
 
461
class SectionMemberStatesStartup(StateStartUpBase):
 
462
 
 
463
    states_name = 'section-membership'
 
464
    states_title = _('Section Enrollment')
 
465
 
 
466
    def populate(self, states):
 
467
        states.add(_('Pending'), INACTIVE, 'p')
 
468
        states.add(_('Enrolled'), ACTIVE, 'a')
 
469
        states.add(_('Withdrawn'), INACTIVE, 'i')
 
470
        states.add(_('Completed'), ACTIVE+COMPLETED, 'c')
 
471
        states.describe(ACTIVE, _('Member'))
 
472
        states.describe(ACTIVE+COMPLETED, _('Completed/Active'))
 
473
        states.describe(INACTIVE+COMPLETED, _('Completed/Inactive'))
 
474
        states.describe(INACTIVE, _('Inactive'))
 
475
 
 
476
 
 
477
class SectionInstructorStatesStartup(StateStartUpBase):
 
478
 
 
479
    states_name = 'section-instruction'
 
480
    states_title = _('Section Instruction')
 
481
 
 
482
    def populate(self, states):
 
483
        states.add(_('Instructor'), ACTIVE, 'a')
 
484
        states.add(_('Substitute'), ACTIVE, 's')
 
485
        states.add(_('Withdrawn'), INACTIVE, 'i')
 
486
        states.describe(ACTIVE, _('Instructing'))
 
487
        states.describe(INACTIVE, _('Removed'))