~replaceafill/schooltool.lyceum.journal/ark_2.10_packaging

« back to all changes in this revision

Viewing changes to src/schooltool/lyceum/journal/browser/journal.py

  • Committer: Douglas Cerna
  • Date: 2015-09-27 06:00:49 UTC
  • mfrom: (1.1.47)
  • Revision ID: douglascerna@yahoo.com-20150927060049-wcrwst3mmfigzd7f
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
from zope.viewlet.viewlet import CSSViewlet
36
36
from zope.exceptions.interfaces import UserError
37
37
from zope.publisher.browser import BrowserView
 
38
from zope.publisher.interfaces.browser import IBrowserRequest
38
39
from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
39
40
from zope.formlib.widget import quoteattr
40
41
from zope.component import queryMultiAdapter
45
46
from zope.interface import Interface
46
47
from zope.intid.interfaces import IIntIds
47
48
from zope.traversing.browser.absoluteurl import absoluteURL
 
49
from zope.traversing.browser.interfaces import IAbsoluteURL
48
50
from zope.cachedescriptors.property import Lazy
49
51
from zope.component import getUtility
50
52
from zope.container.interfaces import INameChooser
51
53
from zope.schema import Date, Choice
52
54
from zope.schema.interfaces import IVocabularyTokenized
 
55
from zope.schema.interfaces import IContextSourceBinder
 
56
from zope.schema.vocabulary import SimpleVocabulary
53
57
 
54
58
import z3c.form.field
55
59
from z3c.form.converter import BaseDataConverter
58
62
import z3c.form.button
59
63
import z3c.form.widget
60
64
from z3c.form.interfaces import IWidget
 
65
from z3c.form.browser.checkbox import CheckBoxFieldWidget
 
66
from z3c.form.browser.checkbox import SingleCheckBoxFieldWidget
61
67
from zc.table.column import GetterColumn
62
68
from zc.table.interfaces import IColumn
63
69
 
132
138
from schooltool.lyceum.journal.interfaces import ITeacherAbsences
133
139
from schooltool.lyceum.journal.interfaces import ITimestamp
134
140
from schooltool.lyceum.journal.interfaces import Time
 
141
from schooltool.lyceum.journal.interfaces import IAttendanceOptions
135
142
from schooltool.lyceum.journal.browser.interfaces import IIndependentColumn
136
143
from schooltool.lyceum.journal.browser.interfaces import ISelectableColumn
137
144
from schooltool.lyceum.journal.browser.table import SelectStudentCellFormatter
3649
3656
 
3650
3657
    @Lazy
3651
3658
    def timestamp_scores(self):
3652
 
        from schooltool.ark.interfaces import IAttendanceOptions
3653
3659
        result = IAttendanceOptions(ISchoolToolApplication(None)).teachers_timestamp_codes or []
3654
3660
        return result
3655
3661
 
3805
3811
 
3806
3812
    @Lazy
3807
3813
    def am_enabled(self):
3808
 
        from schooltool.ark.interfaces import IAttendanceOptions
3809
3814
        return IAttendanceOptions(ISchoolToolApplication(None)).teachers_am_enabled
3810
3815
 
3811
3816
    @Lazy
3812
3817
    def pm_enabled(self):
3813
 
        from schooltool.ark.interfaces import IAttendanceOptions
3814
3818
        return IAttendanceOptions(ISchoolToolApplication(None)).teachers_pm_enabled
3815
3819
 
3816
3820
    def fillPresent(self):
3873
3877
 
3874
3878
    @Lazy
3875
3879
    def am_enabled(self):
3876
 
        from schooltool.ark.interfaces import IAttendanceOptions
3877
3880
        return IAttendanceOptions(ISchoolToolApplication(None)).teachers_am_enabled
3878
3881
 
3879
3882
    @Lazy
3880
3883
    def pm_enabled(self):
3881
 
        from schooltool.ark.interfaces import IAttendanceOptions
3882
3884
        return IAttendanceOptions(ISchoolToolApplication(None)).teachers_pm_enabled
3883
3885
 
3884
3886
    @Lazy
4029
4031
 
4030
4032
    @Lazy
4031
4033
    def am_enabled(self):
4032
 
        from schooltool.ark.interfaces import IAttendanceOptions
4033
4034
        return IAttendanceOptions(ISchoolToolApplication(None)).students_am_enabled
4034
4035
 
4035
4036
    @Lazy
4036
4037
    def pm_enabled(self):
4037
 
        from schooltool.ark.interfaces import IAttendanceOptions
4038
4038
        return IAttendanceOptions(ISchoolToolApplication(None)).students_pm_enabled
4039
4039
 
4040
4040
    def fillPresent(self):
4072
4072
 
4073
4073
    @Lazy
4074
4074
    def am_enabled(self):
4075
 
        from schooltool.ark.interfaces import IAttendanceOptions
4076
4075
        return IAttendanceOptions(ISchoolToolApplication(None)).students_am_enabled
4077
4076
 
4078
4077
    @Lazy
4079
4078
    def pm_enabled(self):
4080
 
        from schooltool.ark.interfaces import IAttendanceOptions
4081
4079
        return IAttendanceOptions(ISchoolToolApplication(None)).students_pm_enabled
4082
4080
 
4083
4081
    @Lazy
4173
4171
 
4174
4172
    @Lazy
4175
4173
    def timestamp_scores(self):
4176
 
        from schooltool.ark.interfaces import IAttendanceOptions
4177
4174
        result = IAttendanceOptions(ISchoolToolApplication(None)).students_timestamp_codes or []
4178
4175
        encoder = flourish.tal.JSONEncoder()
4179
4176
        return encoder.encode(result)
4621
4618
 
4622
4619
    @Lazy
4623
4620
    def am_enabled(self):
4624
 
        from schooltool.ark.interfaces import IAttendanceOptions
4625
4621
        return IAttendanceOptions(ISchoolToolApplication(None)).students_am_enabled
4626
4622
 
4627
4623
    @Lazy
4628
4624
    def pm_enabled(self):
4629
 
        from schooltool.ark.interfaces import IAttendanceOptions
4630
4625
        return IAttendanceOptions(ISchoolToolApplication(None)).students_pm_enabled
4631
4626
 
4632
4627
    @property
4771
4766
 
4772
4767
    @Lazy
4773
4768
    def am_enabled(self):
4774
 
        from schooltool.ark.interfaces import IAttendanceOptions
4775
4769
        return IAttendanceOptions(ISchoolToolApplication(None)).teachers_am_enabled
4776
4770
 
4777
4771
    @Lazy
4778
4772
    def pm_enabled(self):
4779
 
        from schooltool.ark.interfaces import IAttendanceOptions
4780
4773
        return IAttendanceOptions(ISchoolToolApplication(None)).teachers_pm_enabled
4781
4774
 
4782
4775
    @property
4814
4807
 
4815
4808
    fields = z3c.form.field.Fields(ITimestamp)
4816
4809
    ignoreContext = True
 
4810
 
 
4811
 
 
4812
class AttendanceOptionsAbsoluteURLAdapter(object):
 
4813
 
 
4814
    adapts(IAttendanceOptions, IBrowserRequest)
 
4815
    implements(IAbsoluteURL)
 
4816
 
 
4817
    def __str__(self):
 
4818
        app = ISchoolToolApplication(None)
 
4819
        url = absoluteURL(app, self.request)
 
4820
        return url + '/attendance_options'
 
4821
 
 
4822
    __call__ = __str__
 
4823
 
 
4824
 
 
4825
class FieldsetForm(object):
 
4826
 
 
4827
    fieldset_groups = {}
 
4828
    fieldset_order = ()
 
4829
 
 
4830
    def update(self):
 
4831
        self.buildFieldsetGroups()
 
4832
 
 
4833
    def makeRows(self, fields, cols=1):
 
4834
        rows = []
 
4835
        while fields:
 
4836
            rows.append(fields[:cols])
 
4837
            fields = fields[cols:]
 
4838
        return rows
 
4839
 
 
4840
    def makeFieldSet(self, fieldset_id, legend, fields, cols=1):
 
4841
        result = {
 
4842
            'id': fieldset_id,
 
4843
            'legend': legend,
 
4844
            }
 
4845
        result['rows'] = self.makeRows(fields, cols)
 
4846
        return result
 
4847
 
 
4848
    def fieldsets(self):
 
4849
        result = []
 
4850
        for fieldset_id in self.fieldset_order:
 
4851
            legend, fields = self.fieldset_groups[fieldset_id]
 
4852
            result.append(self.makeFieldSet(
 
4853
                    fieldset_id, legend, list(fields)))
 
4854
        return result
 
4855
 
 
4856
    def buildFieldsetGroups(self):
 
4857
        raise NotImplementedError('Do in subclass')
 
4858
 
 
4859
 
 
4860
class AttendanceOptionsEditView(
 
4861
        FieldsetForm,
 
4862
        flourish.form.Form,
 
4863
        z3c.form.form.EditForm,
 
4864
):
 
4865
 
 
4866
    template = flourish.templates.Inherit(flourish.page.Page.template)
 
4867
    label = None
 
4868
    legend = _('Attendance Options Information')
 
4869
 
 
4870
    fields = z3c.form.field.Fields(IAttendanceOptions)
 
4871
    fields['time_enabled'].widgetFactory = SingleCheckBoxFieldWidget
 
4872
    fields['students_am_enabled'].widgetFactory = SingleCheckBoxFieldWidget
 
4873
    fields['students_pm_enabled'].widgetFactory = SingleCheckBoxFieldWidget
 
4874
    fields['teachers_am_enabled'].widgetFactory = SingleCheckBoxFieldWidget
 
4875
    fields['teachers_pm_enabled'].widgetFactory = SingleCheckBoxFieldWidget
 
4876
    fields['students_timestamp_codes'].widgetFactory = CheckBoxFieldWidget
 
4877
    fields['teachers_timestamp_codes'].widgetFactory = CheckBoxFieldWidget
 
4878
 
 
4879
    def update(self):
 
4880
        super(AttendanceOptionsEditView, self).update()
 
4881
        z3c.form.form.EditForm.update(self)
 
4882
 
 
4883
    def updateActions(self):
 
4884
        super(AttendanceOptionsEditView, self).updateActions()
 
4885
        self.actions['apply'].addClass('button-ok')
 
4886
        self.actions['cancel'].addClass('button-cancel')
 
4887
 
 
4888
    @z3c.form.button.buttonAndHandler(s_('Submit'), name='apply')
 
4889
    def handleApply(self, action):
 
4890
        super(AttendanceOptionsEditView, self).handleApply.func(self, action)
 
4891
        # XXX: hacky sucessful submit check
 
4892
        if (self.status == self.successMessage or
 
4893
            self.status == self.noChangesMessage):
 
4894
            self.request.response.redirect(self.nextURL())
 
4895
 
 
4896
    @z3c.form.button.buttonAndHandler(s_('Cancel'))
 
4897
    def handle_cancel_action(self, action):
 
4898
        self.request.response.redirect(self.nextURL())
 
4899
 
 
4900
    def nextURL(self):
 
4901
        app = ISchoolToolApplication(None)
 
4902
        url = '%s/manage' % absoluteURL(app, self.request)
 
4903
        return self.request.get('camefrom', url)
 
4904
 
 
4905
    def buildFieldsetGroups(self):
 
4906
        self.fieldset_groups = {
 
4907
            'time_options': (
 
4908
                _('Time Options'),
 
4909
                [
 
4910
                    'time_enabled',
 
4911
                ]),
 
4912
            'students_options': (
 
4913
                _('Students Options'),
 
4914
                [
 
4915
                    'students_am_enabled',
 
4916
                    'students_am_start',
 
4917
                    'students_am_end',
 
4918
                    'students_pm_enabled',
 
4919
                    'students_pm_start',
 
4920
                    'students_pm_end',
 
4921
                ]),
 
4922
            'teachers_options': (
 
4923
                _('Teachers Options'),
 
4924
                [
 
4925
                    'teachers_am_enabled',
 
4926
                    'teachers_am_start',
 
4927
                    'teachers_am_end',
 
4928
                    'teachers_pm_enabled',
 
4929
                    'teachers_pm_start',
 
4930
                    'teachers_pm_end',
 
4931
                ]),
 
4932
            'report_options': (
 
4933
                _('Report Options'),
 
4934
                [
 
4935
                    'students_hours',
 
4936
                    'students_timestamp_codes',
 
4937
                    'teachers_hours',
 
4938
                    'teachers_timestamp_codes',
 
4939
                ]),
 
4940
        }
 
4941
        self.fieldset_order = (
 
4942
            'time_options',
 
4943
            'students_options',
 
4944
            'teachers_options',
 
4945
            'report_options',
 
4946
        )
 
4947
 
 
4948
 
 
4949
class AttendanceOptionsScriptViewlet(flourish.viewlet.Viewlet):
 
4950
 
 
4951
    template = flourish.templates.File('templates/attendance_options_script.pt')
 
4952
 
 
4953
    @property
 
4954
    def time_enabled_rows(self):
 
4955
        widgets = []
 
4956
        for prefix in ('students', 'teachers'):
 
4957
            widgets.append('%s_am_start' % prefix)
 
4958
            widgets.append('%s_am_end' % prefix)
 
4959
            widgets.append('%s_pm_start' % prefix)
 
4960
            widgets.append('%s_pm_end' % prefix)
 
4961
        return ['%s-row' % self.view.widgets[widget].id
 
4962
                for widget in widgets]
 
4963
 
 
4964
 
 
4965
class StudentsAttendanceCodesVocabulary(SimpleVocabulary):
 
4966
 
 
4967
    implements(IContextSourceBinder)
 
4968
 
 
4969
    def __init__(self, context):
 
4970
        self.context = context
 
4971
        terms = self.createTerms()
 
4972
        SimpleVocabulary.__init__(self, terms)
 
4973
 
 
4974
    def createTerms(self):
 
4975
        result = []
 
4976
        prefs = IJournalScoreSystemPreferences(ISchoolToolApplication(None))
 
4977
        ss = prefs.student_scoresystem
 
4978
        if ss is not None:
 
4979
            for code, score_title in ss.scores:
 
4980
                title = '%s (%s)' % (score_title, code)
 
4981
                result.append(self.createTerm(code, code, title))
 
4982
        return result
 
4983
 
 
4984
 
 
4985
def StudentsAttendanceCodesVocabularyFactory():
 
4986
    return StudentsAttendanceCodesVocabulary
 
4987
 
 
4988
 
 
4989
class TeachersAttendanceCodesVocabulary(SimpleVocabulary):
 
4990
 
 
4991
    implements(IContextSourceBinder)
 
4992
 
 
4993
    def __init__(self, context):
 
4994
        self.context = context
 
4995
        terms = self.createTerms()
 
4996
        SimpleVocabulary.__init__(self, terms)
 
4997
 
 
4998
    def createTerms(self):
 
4999
        result = []
 
5000
        prefs = IJournalScoreSystemPreferences(ISchoolToolApplication(None))
 
5001
        ss = prefs.teacher_scoresystem
 
5002
        if ss is not None:
 
5003
            for code, score_title in ss.scores:
 
5004
                title = '%s (%s)' % (score_title, code)
 
5005
                result.append(self.createTerm(code, code, title))
 
5006
        return result
 
5007
 
 
5008
 
 
5009
def TeachersAttendanceCodesVocabularyFactory():
 
5010
    return TeachersAttendanceCodesVocabulary