Example #1
0
class FlourishGroupEditView(flourish.form.Form, form.EditForm):

    template = InheritTemplate(flourish.page.Page.template)
    label = None
    legend = _('Group Information')
    fields = field.Fields(IGroup)
    fields = fields.select('title', 'description')

    @property
    def title(self):
        return self.context.title

    def update(self):
        return form.EditForm.update(self)

    @button.buttonAndHandler(_('Submit'), name='apply')
    def handleApply(self, action):
        super(FlourishGroupEditView, self).handleApply.func(self, action)
        # XXX: hacky sucessful submit check
        if (self.status == self.successMessage
                or self.status == self.noChangesMessage):
            url = absoluteURL(self.context, self.request)
            self.request.response.redirect(url)

    @button.buttonAndHandler(_("Cancel"))
    def handle_cancel_action(self, action):
        url = absoluteURL(self.context, self.request)
        self.request.response.redirect(url)

    def updateActions(self):
        super(FlourishGroupEditView, self).updateActions()
        self.actions['apply'].addClass('button-ok')
        self.actions['cancel'].addClass('button-cancel')
Example #2
0
class FlourishFieldDescriptionAddView(flourish.form.AddForm,
                                      FieldDescriptionAddView):

    template = InheritTemplate(flourish.page.Page.template)
    label = None
    legend = _('Field Details')
    formErrorsMessage = _('Please correct the marked fields below.')

    @property
    def title(self):
        return getAdapter(self.context, IAddEditViewTitle)

    @button.buttonAndHandler(_('Submit'), name='add')
    def handleAdd(self, action):
        super(FlourishFieldDescriptionAddView,
              self).handleAdd.func(self, action)

    @button.buttonAndHandler(_("Cancel"))
    def handle_cancel_action(self, action):
        self.request.response.redirect(self.nextURL())

    def updateWidgets(self):
        super(FlourishFieldDescriptionAddView, self).updateWidgets()
        self.widgets['limit_keys'].label = getAdapter(self.context,
                                                      ILimitKeysLabel)
        self.widgets['limit_keys'].field.description = getAdapter(
            self.context, ILimitKeysHint)

    def nextURL(self):
        return absoluteURL(self.context, self.request)
Example #3
0
class FlourishTermEditView(flourish.form.Form, TermEditForm):

    template = InheritTemplate(flourish.page.Page.template)
    label = None

    @property
    def title(self):
        return self.context.title

    @property
    def legend(self):
        return _(u'Change information for ${term_title}',
                 mapping={'term_title': self.context.title})

    @button.buttonAndHandler(_('Refresh'), name='refresh',
                             condition=lambda form: form.showRefresh)
    def handleRefresh(self, action):
        super(FlourishTermEditView, self).handleRefresh.func(self, action)

    @button.buttonAndHandler(_('Submit'), name='apply')
    def handleApply(self, action):
        super(FlourishTermEditView, self).handleApply.func(self, action)
        if self.status != self.formErrorsMessage:
            url = absoluteURL(self.context, self.request)
            self.request.response.redirect(url)

    @button.buttonAndHandler(_("Cancel"))
    def handle_cancel_action(self, action):
        super(FlourishTermEditView, self).handle_cancel_action.func(self,
            action)
Example #4
0
class FlourishEmailSettingsEditView(Form, form.EditForm):

    template = InheritTemplate(flourish.page.Page.template)
    label = None
    legend = _('Settings')
    fields = field.Fields(IEmailSettingsEditForm)
    fields = fields.omit('server_status', 'dummy_password')

    def update(self):
        form.EditForm.update(self)

    @button.buttonAndHandler(_('Apply'))
    def handle_apply_action(self, action):
        super(FlourishEmailSettingsEditView,
              self).handleApply.func(self, action)
        # XXX: hacky sucessful submit check
        if (self.status == self.successMessage
                or self.status == self.noChangesMessage):
            self.request.response.redirect(self.nextURL())

    @button.buttonAndHandler(_('Cancel'))
    def handle_cancel_action(self, action):
        self.request.response.redirect(self.nextURL())

    def updateActions(self):
        super(FlourishEmailSettingsEditView, self).updateActions()
        self.actions['apply'].addClass('button-ok')
        self.actions['cancel'].addClass('button-cancel')

    def nextURL(self):
        return absoluteURL(self.context, self.request)
Example #5
0
class FlourishSendEmailView(Form, SendEmailView):

    template = InheritTemplate(flourish.page.Page.template)
    label = None
    legend = _('Email')
    fields = field.Fields(ISendEmailForm).omit('server_status')

    def update(self):
        form.Form.update(self)

    @button.buttonAndHandler(_('Send'))
    def handle_send_action(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return
        from_address = data['from_address']
        to_addresses = [
            address.strip() for address in data['to_addresses'].split(',')
        ]
        body = data['body']
        subject = data['subject']
        email = Email(from_address, to_addresses, body, subject)
        utility = getUtility(IEmailUtility)
        success = utility.send(email)
        if success:
            url = absoluteURL(self.context, self.request)
        else:
            url = '%s/queue.html' % absoluteURL(self.context, self.request)
        self.request.response.redirect(url)

    @button.buttonAndHandler(_('Cancel'))
    def handle_cancel_action(self, action):
        url = absoluteURL(self.context, self.request)
        self.request.response.redirect(url)
Example #6
0
class FlourishContactManagementView(EditContactRelationships):

    page_template = InheritTemplate(Page.page_template)

    current_title = _('Current contacts')
    available_title = _('Available contacts')

    def getCollection(self):
        return IContactable(removeSecurityProxy(self.context)).contacts

    def getSelectedItemIds(self):
        collection = self.getCollection()
        return list(collection.all().int_ids)

    def getAvailableItemsContainer(self):
        return IContactContainer(ISchoolToolApplication(None))

    def getCatalog(self):
        return ICatalog(self.getAvailableItemsContainer())

    def getAvailableItemIds(self):
        selected = self.getSelectedItemIds()
        catalog = self.getCatalog()
        return [intid for intid in catalog.extent if intid not in selected]

    def getOmmitedItemIds(self):
        int_ids = getUtility(IIntIds)
        self_contact = IContact(self.context)
        return self.getSelectedItemIds() + [int_ids.getId(self_contact)]

    def getKey(self, item):
        return IUniqueFormKey(item)
Example #7
0
class FlourishSchoolYearEditView(flourish.form.Form, SchoolYearEditView):
    """flourish Edit form for schoolyear."""

    template = InheritTemplate(flourish.page.Page.template)
    label = None

    def update(self):
        SchoolYearEditView.update(self)

    @button.buttonAndHandler(_('Submit'), name='apply')
    def handleApply(self, action):
        super(FlourishSchoolYearEditView, self).handleApply.func(self, action)
        if self.status == self.successMessage:
            url = absoluteURL(self.context, self.request)
            self.request.response.redirect(url)

    @button.buttonAndHandler(_("Cancel"))
    def handle_cancel_action(self, action):
        url = absoluteURL(self.context, self.request)
        self.request.response.redirect(url)

    def updateWidgets(self):
        super(FlourishSchoolYearEditView, self).updateWidgets()
        self.widgets['title'].maxlength = 12
        title_description = _('Limited to 12 characters or less')
        self.widgets['title'].field.description = title_description

    @property
    def legend(self):
        return _(u'Change information for ${schoolyear_title}',
                 mapping={'schoolyear_title': self.context.title})
Example #8
0
class FlourishCourseAddView(AddForm, ActiveSchoolYearContentMixin):

    template = InheritTemplate(Page.template)
    label = None
    legend = _('Course Information')

    @property
    def fields(self):
        fields = field.Fields(ICourse)
        fields += field.Fields(ICourseLevel)
        fields = fields.select('title', 'description', 'course_id', 'government_id', 'credits', 'level')
        return fields

    def updateActions(self):
        super(FlourishCourseAddView, self).updateActions()
        self.actions['add'].addClass('button-ok')
        self.actions['cancel'].addClass('button-cancel')

    @button.buttonAndHandler(_('Submit'), name='add')
    def handleAdd(self, action):
        super(FlourishCourseAddView, self).handleAdd.func(self, action)

    @button.buttonAndHandler(_('Cancel'))
    def handle_cancel_action(self, action):
        if 'camefrom' in self.request:
            url = self.request['camefrom']
            self.request.response.redirect(url)
            return
        app = ISchoolToolApplication(None)
        url = self.url_with_schoolyear_id(app, view_name='courses')
        self.request.response.redirect(url)

    def create(self, data):
        course = Course(data['title'], data.get('description'))
        self._level = removeSecurityProxy(data.pop('level'))
        form.applyChanges(self, course, data)
        return course

    def add(self, course):
        chooser = INameChooser(self.context)
        name = chooser.chooseName(u'', course)
        self.context[name] = course
        self._course = course
        if self._level is not None:
            self._level.courses.add(course)
        return course

    def nextURL(self):
        return absoluteURL(self._course, self.request)

    @property
    def schoolyear(self):
        return ISchoolYear(self.context)

    @property
    def title(self):
        return _('Courses for ${schoolyear}',
                 mapping={'schoolyear': self.schoolyear.title})
Example #9
0
class FlourishTermAddView(flourish.form.AddForm, TermAddForm, ActiveSchoolYearContentMixin):

    template = InheritTemplate(flourish.page.Page.template)
    label = None
    legend = _('Term Details')

    @property
    def title(self):
        return self.context.title

    @button.buttonAndHandler(_('Refresh'), name='refresh',
                             condition=lambda form: form.showRefresh)
    def handleRefresh(self, action):
        super(FlourishTermAddView, self).handleRefresh.func(self, action)

    @button.buttonAndHandler(_('Next'), name='next',
                             condition=lambda form: form.showNext)
    def next(self, action):
        super(FlourishTermAddView, self).next.func(self, action)

    @button.buttonAndHandler(_('Submit'), name='add',
                             condition=lambda form: form.showRefresh)
    def handleAdd(self, action):
        super(FlourishTermAddView, self).handleAdd.func(self, action)

    def create(self, data):
        term = Term(data['title'], data['first'], data['last'])
        form.applyChanges(self, term, data)
        self.setHolidays(term)
        self._term = term
        return term

    def nextURL(self):
        return absoluteURL(self._term, self.request)

    @property
    def schoolyear(self):
        return ISchoolYear(self.context)

    @button.buttonAndHandler(_("Cancel"))
    def handle_cancel_action(self, action):
        app = ISchoolToolApplication(None)
        url = self.url_with_schoolyear_id(app, view_name='terms')
        self.request.response.redirect(url)

    def dateString(self, date):
        return DateFormatterMediumView(date, self.request)()

    def updateWidgets(self):
        super(FlourishTermAddView, self).updateWidgets()
        description = _(u'The year starts ${year_start}',
            mapping={'year_start': self.dateString(self.context.first)})
        self.widgets['first'].field.description = description
        description = _(u'The year ends ${year_end}',
            mapping={'year_end': self.dateString(self.context.last)})
        self.widgets['last'].field.description = description
Example #10
0
class Form(z3c.form.form.Form, page.PageBase):
    __call__ = page.PageBase.__call__
    formErrorsMessage = _('Please correct the marked fields below.')
    template = InheritTemplate(page.PageBase.template)

    def update(self):
        super(Form, self).update()

    def updateActions(self):
        super(Form, self).updateActions()
Example #11
0
class FlourishSpecialDayView(flourish.page.Page, SpecialDayView):
    select_template = ViewPageTemplateFile('templates/f_specialday_select.pt')
    form_template = ViewPageTemplateFile('templates/f_specialday_change.pt')
    flourish_template = InheritTemplate(flourish.page.Page.template)

    field_error_message = _('Please correct the marked fields below.')

    def update(self):
        SpecialDayView.update(self)
        self.content_template = self.template
        self.template = self.flourish_template
Example #12
0
class FlourishGroupAddView(flourish.form.AddForm,
                           ActiveSchoolYearContentMixin):

    template = InheritTemplate(flourish.page.Page.template)
    label = None
    legend = _('Group Information')
    fields = field.Fields(IGroup)
    fields = fields.select('title', 'description')

    def updateActions(self):
        super(FlourishGroupAddView, self).updateActions()
        self.actions['add'].addClass('button-ok')
        self.actions['cancel'].addClass('button-cancel')

    @button.buttonAndHandler(_('Submit'), name='add')
    def handleAdd(self, action):
        super(FlourishGroupAddView, self).handleAdd.func(self, action)

    @button.buttonAndHandler(_('Cancel'))
    def handle_cancel_action(self, action):
        if 'camefrom' in self.request:
            url = self.request['camefrom']
            self.request.response.redirect(url)
            return
        app = ISchoolToolApplication(None)
        url = self.url_with_schoolyear_id(app, view_name='groups')
        self.request.response.redirect(url)

    def create(self, data):
        group = Group(data['title'], data.get('description'))
        form.applyChanges(self, group, data)
        return group

    def add(self, group):
        chooser = INameChooser(self.context)
        name = chooser.chooseName(u'', group)
        self.context[name] = group
        self._group = group
        return group

    def nextURL(self):
        return absoluteURL(self._group, self.request)

    @property
    def schoolyear(self):
        return ISchoolYear(self.context)

    @property
    def title(self):
        return _('Groups for ${schoolyear}',
                 mapping={'schoolyear': self.schoolyear.title})
Example #13
0
class FlourishCourseView(DisplayForm):

    template = InheritTemplate(Page.template)
    content_template = ViewPageTemplateFile('templates/f_course_view.pt')

    @property
    def fields(self):
        fields = field.Fields(ICourse)
        fields += field.Fields(ICourseLevel)
        fields = fields.select('__name__', 'title', 'description', 'course_id', 'government_id', 'credits', 'level')
        return fields

    @property
    def sections(self):
        return list(removeSecurityProxy(self.context).sections)

    @property
    def unproxied_course(self):
        return removeSecurityProxy(self.context)

    @property
    def canModify(self):
        return checkPermission('schooltool.edit', self.context)

    @property
    def title(self):
        schoolyear = ISchoolYear(self.context.__parent__)
        return _('Courses for ${schoolyear}',
                 mapping={'schoolyear': schoolyear.title})

    @property
    def subtitle(self):
        return self.context.title

    def done_link(self):
        schoolyear = ISchoolYear(self.context.__parent__)
        url = '%s/%s?schoolyear_id=%s' % (
            absoluteURL(ISchoolToolApplication(None), self.request),
            'courses',
            schoolyear.__name__)
        return url

    def updateWidgets(self):
        super(FlourishCourseView, self).updateWidgets()
        for widget in self.widgets.values():
            if not widget.value:
                widget.mode = HIDDEN_MODE

    def has_leaders(self):
        return bool(list(self.context.leaders))
Example #14
0
class FlourishCourseWorksheetEditView(flourish.form.Form, form.EditForm):

    template = InheritTemplate(flourish.page.Page.template)
    label = None
    legend = _('Course Worksheet Template Information')
    fields = field.Fields(ICourseWorksheet).select('title')

    @property
    def title(self):
        return self.context.title

    def update(self):
        if 'form-submitted' in self.request:
            for activity in self.context.values():
                name = 'delete.%s' % activity.__name__
                if name in self.request:
                    del self.context[activity.__name__]
                    break
        return form.EditForm.update(self)

    @button.buttonAndHandler(_('Submit'), name='apply')
    def handleApply(self, action):
        super(FlourishCourseWorksheetEditView,
              self).handleApply.func(self, action)
        # XXX: hacky sucessful submit check
        if (self.status == self.successMessage
                or self.status == self.noChangesMessage):
            self.request.response.redirect(self.nextURL())

    @button.buttonAndHandler(_("Cancel"))
    def handle_cancel_action(self, action):
        self.request.response.redirect(self.nextURL())

    def nextURL(self):
        return absoluteURL(self.context.__parent__, self.request)

    def updateActions(self):
        super(FlourishCourseWorksheetEditView, self).updateActions()
        self.actions['apply'].addClass('button-ok')
        self.actions['cancel'].addClass('button-cancel')

    def display_scoresystem(self, activity):
        ss = activity.scoresystem
        if IRangedValuesScoreSystem.providedBy(ss):
            return '%s - %s' % (ss.min, ss.max)
        return ss.title
Example #15
0
class FlourishGroupView(flourish.form.DisplayForm,
                        ActiveSchoolYearContentMixin):

    template = InheritTemplate(flourish.page.Page.template)
    content_template = ViewPageTemplateFile('templates/f_group_view.pt')
    fields = field.Fields(IGroup)
    fields = fields.select('title', 'description')

    @property
    def canModify(self):
        return checkPermission('schooltool.edit', self.context)

    @property
    def schoolyear(self):
        return ISchoolYear(self.context.__parent__)

    @property
    def title(self):
        return _('Groups for ${schoolyear}',
                 mapping={'schoolyear': self.schoolyear.title})

    @property
    def subtitle(self):
        return self.context.title

    def done_link(self):
        url = self.request.get('done_link', None)
        if url is not None:
            return url
        app = ISchoolToolApplication(None)
        return self.url_with_schoolyear_id(app, view_name='groups')

    def updateWidgets(self):
        super(FlourishGroupView, self).updateWidgets()
        for widget in self.widgets.values():
            if not widget.value:
                widget.mode = HIDDEN_MODE

    def has_members(self):
        return bool(self.context.members)

    def has_leaders(self):
        return bool(self.context.leaders)
Example #16
0
class BaseFlourishResourceAddForm(flourish.form.AddForm):

    template = InheritTemplate(flourish.page.Page.template)
    label = None

    def createAndAdd(self, data):
        resource = self._factory()
        resource.title = data.get('title')
        chooser = INameChooser(self.context)
        resource.__name__ = chooser.chooseName('', resource)
        form.applyChanges(self, resource, data)
        notify(ObjectCreatedEvent(resource))
        self.context[resource.__name__] = resource
        self._resource = resource
        return resource

    def nextURL(self):
        return absoluteURL(
            getattr(self, '_resource', None) or self.context, self.request)
Example #17
0
class FlourishWorksheetAddView(flourish.form.AddForm):
    """flourish view for adding a worksheet."""

    fields = field.Fields(interfaces.IActivityWorksheet).select('title')
    template = InheritTemplate(flourish.page.Page.template)
    label = None
    legend = _('Worksheet Details')

    @button.buttonAndHandler(_('Submit'), name='add')
    def handleAdd(self, action):
        super(FlourishWorksheetAddView, self).handleAdd.func(self, action)

    @button.buttonAndHandler(_("Cancel"))
    def handle_cancel_action(self, action):
        person = IPerson(self.request.principal, None)
        if person is None:
            worksheet = self.context._getDefaultWorksheet()
        else:
            worksheet = self.context.getCurrentWorksheet(person)
        if worksheet is None:
            url = absoluteURL(self.context.__parent__, self.request)
        else:
            url = absoluteURL(worksheet, self.request) + '/gradebook'
        self.request.response.redirect(url)

    def create(self, data):
        self.worksheet = Worksheet(data['title'])
        return self.worksheet

    def add(self, worksheet):
        chooser = INameChooser(self.context)
        name = chooser.chooseName(worksheet.title, worksheet)
        self.context[name] = worksheet
        return worksheet

    def nextURL(self):
        return absoluteURL(self.worksheet, self.request)

    def updateActions(self):
        super(FlourishWorksheetAddView, self).updateActions()
        self.actions['add'].addClass('button-ok')
        self.actions['cancel'].addClass('button-cancel')
Example #18
0
class FlourishSchoolYearAddView(flourish.form.AddForm, SchoolYearAddView):

    template = InheritTemplate(flourish.page.Page.template)
    label = None
    legend = _('School Year Details')

    @button.buttonAndHandler(_('Submit'), name='add')
    def handleAdd(self, action):
        super(FlourishSchoolYearAddView, self).handleAdd.func(self, action)

    @button.buttonAndHandler(_("Cancel"))
    def handle_cancel_action(self, action):
        super(FlourishSchoolYearAddView,
              self).handle_cancel_action.func(self, action)

    def updateWidgets(self):
        super(FlourishSchoolYearAddView, self).updateWidgets()
        self.widgets['title'].maxlength = 12
        title_description = _('Limited to 12 characters or less')
        self.widgets['title'].field.description = title_description
Example #19
0
class FlourishCourseWorksheetAddView(flourish.form.AddForm):
    """flourish view for adding a course worksheet."""

    fields = field.Fields(ICourseWorksheet).select('title')
    template = InheritTemplate(flourish.page.Page.template)
    label = None
    legend = _('Course Worksheet Details')

    @property
    def title(self):
        return self.context.__parent__.title

    @button.buttonAndHandler(_('Submit'), name='add')
    def handleAdd(self, action):
        super(FlourishCourseWorksheetAddView,
              self).handleAdd.func(self, action)

    @button.buttonAndHandler(_("Cancel"))
    def handle_cancel_action(self, action):
        url = absoluteURL(self.context, self.request)
        self.request.response.redirect(url)

    def create(self, data):
        worksheet = CourseWorksheet(data['title'])
        return worksheet

    def add(self, worksheet):
        chooser = INameChooser(self.context)
        name = chooser.chooseName(worksheet.title, worksheet)
        self.context[name] = worksheet
        self._worksheet = worksheet
        return worksheet

    def nextURL(self):
        return absoluteURL(self._worksheet, self.request)

    def updateActions(self):
        super(FlourishCourseWorksheetAddView, self).updateActions()
        self.actions['add'].addClass('button-ok')
        self.actions['cancel'].addClass('button-cancel')
Example #20
0
class FlourishFieldDescriptionEditView(flourish.form.Form,
                                       FieldDescriptionEditView):

    template = InheritTemplate(flourish.page.Page.template)
    label = None
    legend = _('Field Details')

    @property
    def title(self):
        return getAdapter(self.context.__parent__, IAddEditViewTitle)

    @property
    def subtitle(self):
        return _(u'Change information for ${field_title}',
                 mapping={'field_title': self.context.title})

    @button.buttonAndHandler(_('Submit'), name='apply')
    def handleApply(self, action):
        super(FlourishFieldDescriptionEditView,
              self).handleApply.func(self, action)
        # XXX: hacky sucessful submit check
        if (self.status == self.successMessage
                or self.status == self.noChangesMessage):
            self.request.response.redirect(self.nextURL())

    @button.buttonAndHandler(_("Cancel"))
    def handle_cancel_action(self, action):
        self.request.response.redirect(self.nextURL())

    def updateWidgets(self):
        super(FlourishFieldDescriptionEditView, self).updateWidgets()
        self.widgets['limit_keys'].label = getAdapter(self.context.__parent__,
                                                      ILimitKeysLabel)
        self.widgets['limit_keys'].field.description = getAdapter(
            self.context.__parent__, ILimitKeysHint)

    def nextURL(self):
        return absoluteURL(self.context.__parent__, self.request)
Example #21
0
class DisplayForm(z3c.form.form.DisplayForm, page.PageBase):
    template = InheritTemplate(page.PageBase.template)
    __call__ = page.PageBase.__call__

    def update(self):
        super(DisplayForm, self).update()
Example #22
0
class FlourishLevelEditView(flourish.form.Form, LevelEditView):
    template = InheritTemplate(flourish.page.Page.template)
    label = None
    legend = _('Level information')