def post(self):
    logging.debug('XLSFileUpload.post')

    xls_upload_form = XLSFileUploadForm()

    if xls_upload_form.validate(self.request.form, self.request.files):
      logging.debug('process data here')

      in_data = [ ]

      for i in self.request.files:
        self.request.files[i].stream.seek(0)
        in_file = self.request.files[i].stream.getvalue()

        in_xls = open_workbook(file_contents=in_file)

##        base_sheet = in_xls.sheet_by_index(0)
##        tenrows = [ base_sheet.row_values(i) for i in range(10) ]
        request.session['in_xls'] = in_xls

      logging.debug('data processed')
      return redirect('/client/title_list_grid')

##      return render_to_response('client/one_message.html', { 'message': "/thanks/" })
##      return redirect('client/process_spreadsheet.html', { 'message': 'I care', 'sheet': in_xls})
    else:
      logging.debug('form did not validate')
      return render_to_response('client/one_message.html', { 'message': "oopsie!" })
Пример #2
0
    def __init__(self, directory, year, month, province):
        fname = os.path.join(directory, 'xls', str(year), str(month), '%s.xls' % province)

        if not os.path.exists(fname):
            raise Exception("File %s does not exist" % fname)

        # print fname

        workbook = xlrd1.open_workbook(fname)
        if 'PARO' in workbook.sheet_names():
            sheet_name = 'PARO'
        else:
            potential_sheet_names = [ sheet_name for sheet_name in workbook.sheet_names() if sheet_name.startswith('PARO') ]
            assert len(potential_sheet_names) == 1
            sheet_name = potential_sheet_names[0]

        self.worksheet = workbook.sheet_by_name(sheet_name)
        self.towns     = {}
        self.total     = None

        self.retrieve_data()