Exemple #1
0
    def test_basic_validation_error(self):
        '''Exercise converting BasicValidationError to string'''
        e = BasicValidationError()
        self.assertEqual(six.text_type(e), '')

        e = BasicValidationError('hello world')
        self.assertEqual(six.text_type(e), 'hello world')
Exemple #2
0
def signatures_valid(agreement):
    today = date.today()
    unicef_signing_requirements = [
        agreement.signed_by_unicef_date, agreement.signed_by
    ]
    partner_signing_requirements = [
        agreement.signed_by_partner_date, agreement.partner_manager
    ]
    if agreement.agreement_type == agreement.SSFA:
        if any(unicef_signing_requirements + partner_signing_requirements):
            raise BasicValidationError(
                _('SSFA signatures are captured at the Document (TOR) level, please clear the '
                  'signatures and dates and add them to the TOR'))
    unicef_signing_requirements = [
        agreement.signed_by_unicef_date, agreement.signed_by
    ]
    partner_signing_requirements = [
        agreement.signed_by_partner_date, agreement.partner_manager
    ]
    if (any(unicef_signing_requirements) and not all(unicef_signing_requirements)) or \
            (any(partner_signing_requirements) and not all(partner_signing_requirements)) or \
            (agreement.signed_by_partner_date and agreement.signed_by_partner_date > today) or \
            (agreement.signed_by_unicef_date and agreement.signed_by_unicef_date > today):
        return False
    return True
Exemple #3
0
def cp_structure_valid(i):
    if i.country_programme and i.agreement.agreement_type == i.agreement.PCA \
            and i.country_programme != i.agreement.country_programme:
        raise BasicValidationError(_('The Country Programme selected on this PD is not the same as the '
                                     'Country Programme selected on the Agreement, '
                                     'please select "{}"'.format(i.agreement.country_programme)))
    return True
Exemple #4
0
def ssfa_static(agreement):
    if agreement.agreement_type == agreement.SSFA:
        if agreement.interventions.all().exists():
            # there should be only one.. there is a different validation that ensures this
            intervention = agreement.interventions.all().first()
            if intervention.start != agreement.start or intervention.end != agreement.end:
                raise BasicValidationError(
                    _("Start and end dates don't match the Document's start and end"
                      ))
    return True
Exemple #5
0
def ssfa_agreement_has_no_other_intervention(i):
    '''
    checks if SSFA intervention has an SSFA agreement connected. also checks if it's
    the only intervention for that ssfa agreement
    '''
    if i.document_type == i.SSFA:
        if not(i.agreement.agreement_type == i.agreement.SSFA):
            raise BasicValidationError(_('Agreement selected is not of type SSFA'))
        return i.agreement.interventions.all().count() <= 1
    return True
Exemple #6
0
def locations_valid(i):
    ainds = AppliedIndicator.objects.filter(lower_result__result_link__intervention__pk=i.pk).all()
    ind_locations = set()
    for ind in ainds:
        for l in ind.locations.all():
            ind_locations.add(l)
    intervention_locations = set(i.flat_locations.all())
    if not ind_locations.issubset(intervention_locations):
        raise BasicValidationError(_('The following locations have been selected on '
                                     'the PD/SSFA indicators and cannot be removed'
                                     ' without removing them from the indicators first: ') +
                                   ', '.join([six.text_type(l) for l in ind_locations - intervention_locations]))
    return True
Exemple #7
0
def sections_valid(i):
    ainds = AppliedIndicator.objects.filter(lower_result__result_link__intervention__pk=i.pk).all()
    ind_sections = set()
    for ind in ainds:
        ind_sections.add(ind.section)
    intervention_sections = set(s for s in i.sections.all())
    if not ind_sections.issubset(intervention_sections):
        draft_status_err = ' without deleting the indicators first' if i.status == i.DRAFT else ''
        raise BasicValidationError(_('The following sections have been selected on '
                                     'the PD/SSFA indicators and cannot be removed{}: '.format(draft_status_err)) +
                                   ', '.join([s.name for s in ind_sections - intervention_sections]))
        # return False
    return True