예제 #1
0
    def process(self):
        """
        Collects responses to the signal `process_csv_upload`. Raises an
        exception if multiple results were found, and re-raises received Exceptions.

        Returns a list of one or more RealTransaction objects if no Exception
        was raised.
        """
        self.state = SourceState.PROCESSING
        self.save()
        from byro.bookkeeping.signals import process_csv_upload
        responses = process_csv_upload.send_robust(sender=self)
        if len(responses) > 1:
            self.state = SourceState.FAILED
            self.save()
            raise Exception(
                'More than one plugin tried to process the CSV upload: {}'.
                format([
                    r[0].__module__ + '.' + r[0].__name__ for r in responses
                ]))
        if len(responses) < 1:
            self.state = SourceState.FAILED
            self.save()
            raise Exception('No plugin tried to process the CSV upload.')
        receiver, response = responses[0]

        if isinstance(response, Exception):
            self.state = SourceState.FAILED
            self.save()
            raise response
        self.state = SourceState.PROCESSED
        self.save()
        return response
예제 #2
0
    def process(self):
        """
        Collects responses to the signal `process_csv_upload`. Raises an
        exception if multiple results were found, and re-raises received Exceptions.

        Returns a list of one or more Transaction objects if no Exception
        was raised.
        """
        self.state = SourceState.PROCESSING
        self.save()
        from byro.bookkeeping.signals import process_csv_upload

        responses = process_csv_upload.send_robust(sender=self)
        if len(responses) > 1:
            self.state = SourceState.FAILED
            self.save()
            raise Exception(
                "More than one plugin tried to process the CSV upload: {}".format(
                    [r[0].__module__ + "." + r[0].__name__ for r in responses]
                )
            )
        if len(responses) < 1:
            self.state = SourceState.FAILED
            self.save()
            raise Exception("No plugin tried to process the CSV upload.")
        receiver, response = responses[0]

        if isinstance(response, Exception):
            self.state = SourceState.FAILED
            self.save()
            raise response

        for t in Transaction.objects.filter(bookings__source=self):
            try:
                t.process_transaction()
            except Exception as e:
                print(e)  # FIXME

        self.state = SourceState.PROCESSED
        self.save()
        return response