4815
4808
fields = z3c.form.field.Fields(ITimestamp)
4816
4809
ignoreContext = True
4812
class AttendanceOptionsAbsoluteURLAdapter(object):
4814
adapts(IAttendanceOptions, IBrowserRequest)
4815
implements(IAbsoluteURL)
4818
app = ISchoolToolApplication(None)
4819
url = absoluteURL(app, self.request)
4820
return url + '/attendance_options'
4825
class FieldsetForm(object):
4827
fieldset_groups = {}
4831
self.buildFieldsetGroups()
4833
def makeRows(self, fields, cols=1):
4836
rows.append(fields[:cols])
4837
fields = fields[cols:]
4840
def makeFieldSet(self, fieldset_id, legend, fields, cols=1):
4845
result['rows'] = self.makeRows(fields, cols)
4848
def fieldsets(self):
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)))
4856
def buildFieldsetGroups(self):
4857
raise NotImplementedError('Do in subclass')
4860
class AttendanceOptionsEditView(
4863
z3c.form.form.EditForm,
4866
template = flourish.templates.Inherit(flourish.page.Page.template)
4868
legend = _('Attendance Options Information')
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
4880
super(AttendanceOptionsEditView, self).update()
4881
z3c.form.form.EditForm.update(self)
4883
def updateActions(self):
4884
super(AttendanceOptionsEditView, self).updateActions()
4885
self.actions['apply'].addClass('button-ok')
4886
self.actions['cancel'].addClass('button-cancel')
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())
4896
@z3c.form.button.buttonAndHandler(s_('Cancel'))
4897
def handle_cancel_action(self, action):
4898
self.request.response.redirect(self.nextURL())
4901
app = ISchoolToolApplication(None)
4902
url = '%s/manage' % absoluteURL(app, self.request)
4903
return self.request.get('camefrom', url)
4905
def buildFieldsetGroups(self):
4906
self.fieldset_groups = {
4912
'students_options': (
4913
_('Students Options'),
4915
'students_am_enabled',
4916
'students_am_start',
4918
'students_pm_enabled',
4919
'students_pm_start',
4922
'teachers_options': (
4923
_('Teachers Options'),
4925
'teachers_am_enabled',
4926
'teachers_am_start',
4928
'teachers_pm_enabled',
4929
'teachers_pm_start',
4933
_('Report Options'),
4936
'students_timestamp_codes',
4938
'teachers_timestamp_codes',
4941
self.fieldset_order = (
4949
class AttendanceOptionsScriptViewlet(flourish.viewlet.Viewlet):
4951
template = flourish.templates.File('templates/attendance_options_script.pt')
4954
def time_enabled_rows(self):
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]
4965
class StudentsAttendanceCodesVocabulary(SimpleVocabulary):
4967
implements(IContextSourceBinder)
4969
def __init__(self, context):
4970
self.context = context
4971
terms = self.createTerms()
4972
SimpleVocabulary.__init__(self, terms)
4974
def createTerms(self):
4976
prefs = IJournalScoreSystemPreferences(ISchoolToolApplication(None))
4977
ss = prefs.student_scoresystem
4979
for code, score_title in ss.scores:
4980
title = '%s (%s)' % (score_title, code)
4981
result.append(self.createTerm(code, code, title))
4985
def StudentsAttendanceCodesVocabularyFactory():
4986
return StudentsAttendanceCodesVocabulary
4989
class TeachersAttendanceCodesVocabulary(SimpleVocabulary):
4991
implements(IContextSourceBinder)
4993
def __init__(self, context):
4994
self.context = context
4995
terms = self.createTerms()
4996
SimpleVocabulary.__init__(self, terms)
4998
def createTerms(self):
5000
prefs = IJournalScoreSystemPreferences(ISchoolToolApplication(None))
5001
ss = prefs.teacher_scoresystem
5003
for code, score_title in ss.scores:
5004
title = '%s (%s)' % (score_title, code)
5005
result.append(self.createTerm(code, code, title))
5009
def TeachersAttendanceCodesVocabularyFactory():
5010
return TeachersAttendanceCodesVocabulary