Esempio n. 1
0
    def next(self):
        try:
            self.line_number, self.values = self.shredder.next()
            mpan_core_str = self.get_field(0, "MPAN Core")
            datum = {'mpan_core': utils.parse_mpan_core(mpan_core_str)}
            channel_type_str = self.get_field(1, "Channel Type")
            datum['channel_type'] = utils.parse_channel_type(channel_type_str)

            start_date_str = self.get_field(2, "Start Date")
            datum['start_date'] = utils.validate_hh_start(
                datetime.datetime.strptime(
                    start_date_str, "%Y-%m-%d %H:%M").replace(tzinfo=pytz.utc))

            value_str = self.get_field(3, "Value")
            datum['value'] = decimal.Decimal(value_str)

            status = self.get_field(4, "Status")
            if len(status) != 1:
                raise UserException(
                    "The status character must be one character in length.")
            datum['status'] = status
            return datum
        except UserException, e:
            raise UserException(
                "Problem at line number: " + str(self.line_number) + ": " +
                str(self.values) + ": " + str(e))
Esempio n. 2
0
method = inv.getRequest().getMethod()

if inv.hasParameter('supply_id'):
    supply_id = inv.getLong('supply_id')
else:
    supply_id = None

if inv.hasParameter('mpan_cores'):
    mpan_cores_str = form_str(inv, 'mpan_cores')
    mpan_cores = mpan_cores_str.splitlines()
    if len(mpan_cores) == 0:
        mpan_cores = None
    else:
        for i in range(len(mpan_cores)):
            mpan_cores[i] = utils.parse_mpan_core(mpan_cores[i])
else:
    mpan_cores = None

if finish_date < start_date:
    raise UserException("The finish date can't be before the start date.")

is_zipped = form_bool(inv, 'is_zipped')

if is_zipped:
    mimetype = 'application/zip'
    file_extension = ".zip"
else:
    mimetype = 'text/csv'
    file_extension = ".csv"