Beispiel #1
0
def notification_rev_ph1(context, event):
    """
    To:     ReviewerPhase1
    When:   Your question was sent to MS
    """
    _temp = PageTemplateFile('question_to_ms_rev_msg.pt')

    if event.action in ['phase1-approve-question']:
        observation = aq_parent(context)
        subject = u'Your observation was sent to MS'
        notify(observation,
               _temp,
               subject,
               role='ReviewerPhase1',
               notification_name='question_to_ms')
Beispiel #2
0
def notification_lr(context, event):
    """
    To:     LeadReviewer
    When:   New draft question to comment on
    """
    _temp = PageTemplateFile('question_to_counterpart.pt')

    if event.action in ['phase2-request-for-counterpart-comments']:
        observation = aq_parent(context)
        subject = u'New draft question to comment'
        notify(observation,
               _temp,
               subject,
               role='LeadReviewer',
               notification_name='question_to_counterpart')
Beispiel #3
0
def notification_qe(context, event):
    """
    To:     QualityExpert
    When:   New draft question to comment on
    """
    _temp = PageTemplateFile('question_to_counterpart.pt')

    if event.action in ['phase1-request-for-counterpart-comments']:
        observation = aq_parent(context)
        subject = u'New draft question to comment'
        notify(observation,
               _temp,
               subject,
               role='QualityExpert',
               notification_name='question_to_counterpart')
Beispiel #4
0
def notification_cp(context, event):
    """
    To:     CounterParts
    When:   New draft conclusion to comment on
    """
    _temp = PageTemplateFile('conclusion_to_comment.pt')

    if event.action in ['request-comments']:
        observation = context
        subject = u'New draft conclusion to comment on'
        notify(
            observation,
            _temp,
            subject,
            ROLE_CP,
            'conclusion_to_comment'
        )
def notification_rev_ph2(context, event):
    """
    To:     ReviewerPhase2
    When:   New answer from country
    """
    _temp = PageTemplateFile('question_answered_rev_msg.pt')

    if event.action in ['phase2-answer-to-lr']:
        observation = aq_parent(context)
        subject = u'New answer from country'
        notify(
            observation,
            _temp,
            subject,
            'ReviewerPhase2',
            'question_answered'
        )
def notification_rev_msexperts(context, event):
    """
    To:     MSExperts
    When:   New answer from country
    """
    _temp = PageTemplateFile('question_answered_msexperts_msg.pt')

    if event.action in ['phase1-answer-to-lr', 'phase2-answer-to-lr']:
        observation = aq_parent(context)
        subject = u'New answer from country'
        notify(
            observation,
            _temp,
            subject,
            'MSExpert',
            'question_answered'
        )
def notification_lr(context, event):
    """
    To:     LeadReviewer
    When:   Observation handed over to phase 2
    """
    _temp = PageTemplateFile('observation_to_phase2.pt')

    if event.action in ['phase1-send-to-team-2']:
        observation = context
        subject = u'Observation handed over to phase 2'
        notify(
            observation,
            _temp,
            subject,
            'LeadReviewer',
            'observation_to_phase2'
        )
def notification_qe(context, event):
    """
    To:     QualityExpert
    When:   New answer from country
    """
    _temp = PageTemplateFile('question_answered_lr_msg.pt')

    if event.action in ['phase1-answer-to-lr']:
        observation = aq_parent(context)
        subject = u'New answer from country'
        notify(
            observation,
            _temp,
            subject,
            'QualityExpert',
            'question_answered'
        )
Beispiel #9
0
def notification_lr(context, event):
    """
    To:     LeadReviewer
    When:   Observation finalisation request
    """
    _temp = PageTemplateFile('observation_finalisation_request.pt')

    if event.action in ['finish-observation']:
        observation = context
        subject = u'Observation finalisation request'
        notify(
            observation,
            _temp,
            subject,
            ROLE_LR,
            'observation_finalisation_request'
        )
Beispiel #10
0
def notification_lr(context, event):
    """
    To:     LeadReviewer
    When:   New draft question to comment on
    """
    _temp = PageTemplateFile('conclusion_to_comment.pt')

    if event.action in ['request-comments']:
        observation = context
        subject = u'New draft conclusion to comment on'
        notify(
            observation,
            _temp,
            subject,
            ROLE_LR,
            'conclusion_to_comment'
        )
def notification_ms(context, event):
    """
    To:     MSAuthority
    When:   Answer Acknowledged
    """
    _temp = PageTemplateFile('answer_acknowledged.pt')

    if event.action in ['phase1-validate-answer-msa', 'phase2-validate-answer-msa']:
        observation = aq_parent(context)
        subject = u'Your answer was acknowledged'
        notify(
            observation,
            _temp,
            subject,
            'MSAuthority',
            'answer_acknowledged'
        )
Beispiel #12
0
def notification_cp(context, event=None, reassign=False):
    """
    To:     CounterParts
    When:   New draft question to comment on
    """
    _temp = PageTemplateFile('question_to_counterpart.pt')

    should_run = (event
                  and event.action in ['request-for-counterpart-comments']
                  or reassign)

    if should_run:
        observation = aq_parent(context)
        subject = u'New draft question to comment'
        notify(observation,
               _temp,
               subject,
               role=ROLE_CP,
               notification_name='question_to_counterpart')
Beispiel #13
0
    def handler(observation, event):
        if event.action != SKIP_UNLESS_ACTION:
            return

        # get previous state
        _wf_state = observation.workflow_history.get(
            'esd-review-workflow')[-2]['review_state']
        _obs_state = OBS_STATES[_wf_state]

        # only handle specific states
        if _obs_state not in for_states:
            return

        _mail_subject = MAIL_SUBJECT.format(state=_obs_state)
        _mail_template = PageTemplateFile(
            MAIL_TEMPLATE.format(state=_obs_state, suffix=suffix))

        notify(observation, _mail_template, _mail_subject, role,
               NOTIFICATION_NAME)
Beispiel #14
0
class ItemList(TemplateMixin):
    """ Render a python list of ItemLabels as an HTML list
    """

    template = PageTemplateFile('pt/list.pt')

    def __init__(self, rows, sort=True):
        rows = list(rows)

        # the rows may be ItemLabel instances

        if sort and rows and (not isinstance(rows[0], basestring)):
            self.rows = sorted(rows,
                               key=lambda r: (r is not None) and r.title or '')
        elif sort:
            self.rows = sorted(rows)
        else:
            self.rows = rows

    def __repr__(self):
        v = ', '.join(map(unicode, self.rows))

        return v
        # return "<ItemList of %s children>" % len(self.rows)

    def __cmp__(self, other):

        if len(self.rows) != len(other.rows):
            return -1

        for v1, v2 in zip(self.rows, other.rows):
            if v1 != v2:
                return -1

        return 0

    def __hash__(self):
        # this is needed to be able to set a list of marineunitids as group
        # for Art9 2018

        return id(self)     # wonky but should work
Beispiel #15
0
class EventListingView(BaseEventListingView):

    eventlist = PageTemplateFile('app_cal_events.pt')

    def getTags(self):
        from p4a.calendar import interfaces
        from ubify.cyninv2theme import getTagsAndTagsCount
        tags = []
        provider = interfaces.IEventProvider(self.context)
        now = datetime.datetime.now()
        events = []
        if self.context.REQUEST.URL.endswith('upcomingEvents'):
            events = list(
                provider.gather_events(start=now,
                                       stop=None,
                                       **self.request.form))
        else:
            events = list(
                provider.gather_events(start=None,
                                       stop=now,
                                       **self.request.form))
        tags = getTagsAndTagsCount(events)
        return tags
def notification_mse(context, event=None, reassign=False):
    """
    To:     MSExperts
    When:   New question for your country
    """
    _temp = PageTemplateFile('answer_to_msexperts.pt')

    should_run = (
        event
        and event.action in ['assign-answerer']
        or reassign
    )

    if should_run:
        observation = aq_parent(context)
        subject = u'New question for your country'
        notify(
            observation,
            _temp,
            subject,
            ROLE_MSE,
            'answer_to_msexperts'
        )
Beispiel #17
0
    def __call__(self):
        """Perform the update and redirect if necessary, or render the page
        """
        target = self.assignation_target()
        if self.request.form.get('send', None):
            counterparts = self.request.get('counterparts', None)
            if counterparts is None:
                status = IStatusMessage(self.request)
                msg = _(u'You need to select at least one counterpart')
                status.addStatusMessage(msg, "error")
                return self.index()

            self.revoke_all_roles()

            for username in counterparts:
                api.user.grant_roles(username=username,
                                     roles=['CounterPart'],
                                     obj=target)

            status = IStatusMessage(self.request)
            msg = _(u'CounterParts reassigned correctly')
            status.addStatusMessage(msg, "info")
            url = self.context.absolute_url()

            subject = u'New draft question to comment'
            _temp = PageTemplateFile(
                '../notifications/question_to_counterpart.pt')
            notify(target,
                   _temp,
                   subject,
                   role='CounterPart',
                   notification_name='question_to_counterpart')

            return self.request.response.redirect(url)

        else:
            return self.index()
Beispiel #18
0
class ItemListGroup(LabeledItemList):
    template = PageTemplateFile('pt/grouped-list.pt')
Beispiel #19
0
class BaseLandingPageRow(BaseComplianceView, AssessmentDataMixin,
                         LandingpageDataMixin):
    """ Base class with all the needed base methods to build the landing page
        structure
    """

    template = PageTemplateFile('pt/landingpage-row.pt')

    @property
    def _nr_of_countries(self):
        cnt = 0

        for region_folder in self._reg_desc_region_folders:
            available_countries = region_folder._countries_for_region

            cnt += len(available_countries)

        return cnt

    @property
    def regions_and_countries(self):
        res = []

        for region_folder in self._reg_desc_region_folders:
            region_id = region_folder.id.upper()
            available_countries = region_folder._countries_for_region

            res.append(
                (region_id, sorted(available_countries, key=lambda i: i[1])))

        return res

    def _make_subrow_row(self,
                         text,
                         data,
                         color_class,
                         extra_css_class,
                         rowspan=1):
        res = []
        _text = text
        color_suffix = COLOR_SUFFIX.get(color_class, "")
        css_class = extra_css_class + " {}{}"

        res.append(
            SubrowItem(self._nr_of_countries, _text, data.get('ROW', ''),
                       css_class.format('ROW', color_suffix), rowspan))

        return res

    def _make_subrow_region(self,
                            text,
                            data,
                            color_class,
                            extra_css_class,
                            rowspan=1):
        res = []
        color_suffix = COLOR_SUFFIX.get(color_class, "")
        css_class = extra_css_class + " {}{}"

        for region_id, available_countries in self.regions_and_countries:
            _text = text.format(region_id)

            if text == '_region':
                _text = [
                    r.title for r in REGIONAL_DESCRIPTORS_REGIONS
                    if r.code == region_id
                ][0]

            res.append(
                SubrowItem(len(available_countries), _text,
                           data.get(region_id, ''),
                           css_class.format(region_id, color_suffix), rowspan))

        return res

    def _make_subrow_country(self,
                             text,
                             data,
                             color_class,
                             extra_css_class,
                             rowspan=1):
        res = []
        color_suffix = COLOR_SUFFIX.get(color_class, "")
        css_class = extra_css_class + " {}{}"

        for region_id, available_countries in self.regions_and_countries:
            for country in available_countries:
                country_id = country[0]
                country_name = country[1]

                _text = text.format(country_id)

                if text == '_country':
                    _text = country_name

                res.append(
                    SubrowItem(1, _text, data.get(country_id, ""),
                               css_class.format(region_id, color_suffix),
                               rowspan))

        return res

    def make_subrow(self, colspan_type, rowspan, text, color_class, css_extra,
                    data):
        make_method = getattr(self, "_make_subrow_" + colspan_type)
        subrow_final = make_method(text, data, color_class, css_extra, rowspan)

        return subrow_final

    def __init__(self, context, request, year_def):
        super(BaseLandingPageRow, self).__init__(context, request)

        data = []

        for row in year_def.rows:
            date = row.date
            who = row.who
            art = row.article
            task = row.task
            css_extra = row.css_extra
            subrows = row.subrows
            _subrows = []

            for subrow_def in subrows:
                colspan_type = subrow_def.colspan_type
                text = subrow_def.text
                color_class = subrow_def.color_class
                get_data_method = subrow_def.get_method
                rowspan = subrow_def.rowspan
                permission = subrow_def.permission
                msfd_article = subrow_def.msfd_article
                report_type = subrow_def.report_type
                # task_product = subrow_def.task_product

                if permission and not (self.check_permission(permission)):
                    continue

                _get_method = getattr(self, get_data_method, self._default)
                subrow_data = _get_method(colspan_type, msfd_article,
                                          report_type, task, who)

                _subrows.append(
                    self.make_subrow(colspan_type, rowspan, text, color_class,
                                     css_extra, subrow_data))

            data.append(YearRow(date, who, art, task, css_extra, _subrows))

        self.data = data

    def __call__(self):
        return self.template(data=self.data)
Beispiel #20
0
class CyninFeedView(BaseFeedView):

    basepath = os.path.join(os.path.dirname(cyninv2theme.__file__), 'browser')
    atom = PageTemplateFile(os.path.join(basepath, 'atom.xml.pt'))
    rss = PageTemplateFile(os.path.join(basepath, 'rss.xml.pt'))
    itunes = PageTemplateFile(os.path.join(basepath, 'itunes.xml.pt'))
Beispiel #21
0
class EventListingView(object):
    """View that lists events.
    """

    eventlist = PageTemplateFile('events.pt')

    def _getEventList(self, start=None, stop=None, reverse=False):
        provider = interfaces.IEventProvider(self.context)
        now = datetime.datetime.now()
        events = list(
            provider.gather_events(start=start, stop=stop,
                                   **self.request.form))
        events.sort()
        # If this is an archive, revert the event list.
        if reverse:
            events.reverse()
        months = []
        month_info = []
        old_month_year = None
        for event in events:
            start = event.start
            month = str(start.month)
            year = str(start.year)
            month_year = year + month
            if month_year != old_month_year:
                old_month_year = month_year
                if month_info:
                    months.append(month_info)
                month_info = {
                    'month': start.month,
                    'year': start.year,
                    'month_name': start.strftime("%B"),
                    'events': []
                }
            event_dict = {
                'event': event,
                'day': start.day,
                'start': start,
                'end': event.end,
                'location': event.location,
                'title': event.title,
                'description': event.description,
                'url': event.local_url,
            }
            month_info['events'].append(event_dict)

        if month_info:
            months.append(month_info)

        return months

    def upcomingEvents(self):
        now = datetime.datetime.now()
        months = self._getEventList(start=now)
        return self.eventlist(months=months, show_past=False)

    def pastEvents(self):
        now = datetime.datetime.now()
        months = self._getEventList(stop=now, reverse=True)
        return self.eventlist(months=months, show_past=True)

    def event_creation_link(self, start=None, stop=None):
        provider = interfaces.IEventProvider(self.context)
        return provider.event_creation_link(start, stop)

    def render_filter(self):
        provider = queryMultiAdapter((self.context, self.request, self),
                                     IContentProvider, 'eventfilter')
        if provider is None:
            return ''
        provider.update()
        return provider.render()
Beispiel #22
0
def notify_role(rolename, tpl_name, notification_name, subject, context):
    template = PageTemplateFile(tpl_name)
    utils.notify(context, template, subject, rolename, notification_name)
Beispiel #23
0
class TableHeader(TemplateMixin):
    template = PageTemplateFile('pt/table-header.pt')

    def __init__(self, title, values):
        self.title = title
        self.cells = values
 def pt_getContext(self, args=(), options={}, **kw):
     rval = PageTemplateFile.pt_getContext(self, args=args)
     options.update(rval)
     return options
Beispiel #25
0
class ItemListOverview(ItemList):
    template = PageTemplateFile('pt/list.pt')
Beispiel #26
0
    @property  # TODO: memoize
    def descriptor_obj(self):
        return get_descriptor(self.descriptor)

    # TODO: use memoize
    @property
    def questions(self):
        qs = self._questions[self.article]

        return qs


Cell = namedtuple('Cell', ['text', 'rowspan'])

help_template = PageTemplateFile('pt/assessment-question-help.pt')


def render_assessment_help(criterias, descriptor):
    elements = []
    methods = []

    for c in criterias:
        elements.extend([e.id for e in c.elements])
        methods.append(c.methodological_standard.id)

    element_count = {}

    for k in elements:
        element_count[k] = elements.count(k)
Beispiel #27
0
class BaseLandingPageRow(BaseComplianceView, AssessmentDataMixin):
    """ Base class with all the needed base methods to build the landing page
        structure
    """

    template = PageTemplateFile('pt/landingpage-row.pt')

    @property
    def _nr_of_countries(self):
        cnt = 0

        for region_folder in self._reg_desc_region_folders:
            available_countries = region_folder._countries_for_region

            cnt += len(available_countries)

        return cnt

    @property
    def regions_and_countries(self):
        res = []

        for region_folder in self._reg_desc_region_folders:
            region_id = region_folder.id.upper()
            available_countries = region_folder._countries_for_region

            res.append((region_id, available_countries))

        return res

    def _default(self):
        return {}

    def get_2018_countries_assess(self):
        return self.get_2018_countries(extra_path='assessments')

    def get_2018_countries_reports(self):
        return self.get_2018_countries(extra_path='reports')

    def get_2018_countries(self, extra_path=''):
        data = {}

        for folder in self._nat_desc_country_folders:
            url = "{}/{}".format(folder.absolute_url(), extra_path)
            reg_id = folder.id.upper()
            data[reg_id] = url

        return data

    def get_2018_regions_assess(self):
        return self.get_2018_regions(extra_path='assessments')

    def get_2018_regions_reports(self):
        return self.get_2018_regions(extra_path='reports')

    def get_2018_regions(self, extra_path=''):
        data = {}

        for folder in self._reg_desc_region_folders:
            url = "{}/{}".format(folder.absolute_url(), extra_path)
            reg_id = folder.id.upper()
            data[reg_id] = url

        return data

    def _make_subrow_row(self, text, data, color_class, extra_css_class):
        res = []
        _text = text
        color_suffix = COLOR_SUFFIX.get(color_class, "")
        css_class = extra_css_class + " {}{}"

        res.append((self._nr_of_countries, _text, data.get('ROW', ''),
                    css_class.format('ROW', color_suffix)))

        return res

    def _make_subrow_region(self, text, data, color_class, extra_css_class):
        res = []
        _text = text
        color_suffix = COLOR_SUFFIX.get(color_class, "")
        css_class = extra_css_class + " {}{}"

        for region_id, available_countries in self.regions_and_countries:
            if text == '_region':
                _text = region_id

            res.append(
                (len(available_countries), _text, data.get(region_id, ''),
                 css_class.format(region_id, color_suffix)))

        return res

    def _make_subrow_country(self, text, data, color_class, extra_css_class):
        res = []
        _text = text
        color_suffix = COLOR_SUFFIX.get(color_class, "")
        css_class = extra_css_class + " {}{}"

        for region_id, available_countries in self.regions_and_countries:
            for country in available_countries:
                country_id = country[0]
                country_name = country[1]

                if text == '_country':
                    _text = country_id

                res.append((1, _text, data.get(country_id, ""),
                            css_class.format(region_id, color_suffix)))

        return res

    def make_subrow(self, colspan_type, text, color_class, css_extra, data):
        make_method = getattr(self, "_make_subrow_" + colspan_type)
        subrow_final = make_method(text, data, color_class, css_extra)

        return subrow_final

    def __init__(self, context, request, year_def):
        super(BaseLandingPageRow, self).__init__(context, request)

        data = []

        for row in year_def.rows:
            date = row[0]
            who = row[1]
            art = row[2]
            task = row[3]
            css_extra = row[4]
            subrows = row[5]
            _subrows = []

            for subrow in subrows:
                colspan_type = subrow[0]
                text = subrow[1]
                color_class = subrow[2]
                get_data_method = subrow[3]

                subrow_data = getattr(self, get_data_method, self._default)()

                _subrows.append(
                    self.make_subrow(colspan_type, text, color_class,
                                     css_extra, subrow_data))

            data.append((date, who, art, task, css_extra, _subrows))

        self.data = data

    def __call__(self):
        return self.template(data=self.data)