Beispiel #1
0
    def clean_data(data):

        places = clean_place(data['executionPlace'])
        prepared_data = {'base_id': data['id'],
                         'procedure_type': data['contractingProcedureType'],
                         'contract_type': data[u'contractTypes'],
                         'contract_description': data['objectBriefDescription'],
                         'description': data['description'],
                         'signing_date': data['signingDate'],
                         'added_date': data['publicationDate'],
                         'cpvs': data['cpvs'],
                         'category': data['cpvs'],
                         'price': data['initialContractualPrice'],
                         'country': places[0],
                         'district': places[1],
                         'council': {'district': places[1], 'council': places[2]},
                         'contractors': data['contracting'],
                         'contracted': data['contracted']
                         }

        form = ContractForm(prepared_data)

        if not form.is_valid():
            logging.error('Validation of contract "%d" failed' %
                          data['id'])
            raise ValidationError(form.errors)

        return form.cleaned_data
    def clean_data(data):

        places = clean_place(data["executionPlace"])
        prepared_data = {
            "base_id": data["id"],
            "procedure_type": data["contractingProcedureType"],
            "contract_type": data[u"contractTypes"],
            "contract_description": data["objectBriefDescription"],
            "description": data["description"],
            "signing_date": data["signingDate"],
            "added_date": data["publicationDate"],
            "cpvs": data["cpvs"],
            "category": data["cpvs"],
            "price": data["initialContractualPrice"],
            "country": places[0],
            "district": places[1],
            "council": {"district": places[1], "council": places[2]},
            "contractors": data["contracting"],
            "contracted": data["contracted"],
        }

        form = ContractForm(prepared_data)

        if not form.is_valid():
            logger.error('Validation of contract "%d" failed' % data["id"])
            raise ValidationError(form.errors)

        return form.cleaned_data
Beispiel #3
0
    def clean_data(data):

        def fix_exceptions(prepared_data):
            # this is confirmed from the official contract in PDF
            if prepared_data['base_id'] in (1892486, 1892453, 1892392):
                prepared_data['contractors'] = [{'id': 8468}]
            elif prepared_data['base_id'] in (2377732, 2377789, 2377777):
                prepared_data['contractors'] = [{'id': 2154}]
            return prepared_data

        places = clean_place(data['executionPlace'])
        prepared_data = {'base_id': data['id'],
                         'procedure_type': data['contractingProcedureType'],
                         'contract_type': data[u'contractTypes'],
                         'contract_description': data['objectBriefDescription'],
                         'description': data['description'],
                         'signing_date': data['signingDate'],
                         'added_date': data['publicationDate'],
                         'cpvs': data['cpvs'],
                         'category': data['cpvs'],
                         'price': data['initialContractualPrice'],
                         'country': places[0],
                         'district': places[1],
                         'council': {'district': places[1], 'council': places[2]},
                         'contractors': data['contracting'],
                         'contracted': data['contracted']
                         }

        prepared_data = fix_exceptions(prepared_data)

        form = ContractForm(prepared_data)

        if not form.is_valid():
            logger.error('Validation of contract "%d" failed' %
                         data['id'])
            raise ValidationError(form.errors)

        return form.cleaned_data
 def test_incomplete_more(self):
     value = clean_place('Portugal, Porto<BR/>Portugal')
     self.assertEqual(value, ('Portugal', 'Porto', None))
 def test_more_than_one(self):
     value = clean_place('Portugal, Porto, Maia<BR/>'
                         'Portugal<BR/>Portugal, Distrito não determinado, '
                         'Concelho não determinado<BR/>'
                         'Portugal, Vila Real, Vila Real')
     self.assertEqual(value, ('Portugal', 'Porto', 'Maia'))
 def test_incomplete_more(self):
     value = clean_place('Portugal, Porto<BR/>Portugal')
     self.assertEqual(value, ('Portugal', 'Porto', None))
 def test_more_than_one(self):
     value = clean_place('Portugal, Porto, Maia<BR/>'
                         'Portugal<BR/>Portugal, Distrito não determinado, '
                         'Concelho não determinado<BR/>'
                         'Portugal, Vila Real, Vila Real')
     self.assertEqual(value, ('Portugal', 'Porto', 'Maia'))