def exportDocHeaderForUpdate(cls, isEnd=True): export_line = '' export_line += 'command,doc_id,user_id,line_id,store_id' if isEnd: export_line += '\r\n' export_line = sateraito_func.washShiftJISErrorChar(export_line) return export_line
def exportStoreDataRowForUpdate(cls, row_doc, timezone=sateraito_inc.DEFAULT_TIMEZONE): export_line = '' # command export_line += 'IU' # store_id export_line += ',' + sateraito_func.escapeForCsv(row_doc['store_id']) # store_name export_line += ',' + sateraito_func.escapeForCsv( row_doc['store_name'] if row_doc.has_key('store_name') else '') #user_id export_line += ',' + sateraito_func.escapeForCsv(row_doc['user_id']) # last_name export_line += ',' + sateraito_func.escapeForCsv(row_doc['last_name']) # first_name export_line += ',' + sateraito_func.escapeForCsv(row_doc['first_name']) # mail_address export_line += ',' + sateraito_func.escapeForCsv( row_doc['mail_address']) # created_date export_line += ',' + sateraito_func.escapeForCsv( row_doc['created_date']) export_line += '\r\n' export_line = sateraito_func.washShiftJISErrorChar(export_line) return export_line
def exportStoreRowForUpdate(cls, row_doc, template_name='', timezone=sateraito_inc.DEFAULT_TIMEZONE): export_line = '' # command export_line += 'IU' # store_id disp export_line += ',' + sateraito_func.escapeForCsv(row_doc.store_id_disp) # store_id (scan id) export_line += ',' + sateraito_func.escapeForCsv(row_doc.store_id) #name export_line += ',' + sateraito_func.escapeForCsv(row_doc.name) # reply_message export_line += ',' + sateraito_func.escapeForCsv(row_doc.reply_message) # qrcode_id export_line += ',' + sateraito_func.escapeForCsv(row_doc.qrcode_id) # qrcode_url export_line += ',' + sateraito_func.escapeForCsv(row_doc.qrcode_url) # reply_user # reply_user = row_doc.reply_user if row_doc.reply_user else [] # export_line += ',' + sateraito_func.escapeForCsv(''.join(reply_user)) # form_template export_line += ',' + sateraito_func.escapeForCsv(template_name) # memo export_line += ',' + sateraito_func.escapeForCsv(row_doc.memo) export_line += '\r\n' export_line = sateraito_func.washShiftJISErrorChar(export_line) return export_line
def saveCsvStoreData(cls, tenant, tq_entry, csv_download_id, csv_filename, csv_string, is_api=False, is_success=True, have_more_rows=False): # ## save csv data to datastore # csv_string = str(csv_string) csv_string = sateraito_func.washShiftJISErrorChar(csv_string) csv_string = csv_string.encode('cp932') #Shift_JIS変換 # devide csv data # CAUTION: Datastore entity can have only 1MB data per entity # so you have to devide data if it is over 1MB csv_data_length = len(csv_string) csv_datas = [] NUM_STRING_PER_ENTITY = 1000 * 900 # 900 KB number_of_entity = (csv_data_length // NUM_STRING_PER_ENTITY) + 1 for i in range(0, number_of_entity): start_index = i * NUM_STRING_PER_ENTITY end_index = start_index + NUM_STRING_PER_ENTITY csv_datas.append(csv_string[start_index:end_index]) # store data to datastore expire_date = datetime.datetime.now() + datetime.timedelta( days=1) # csv download expires in 24 hours for i in range(0, number_of_entity): new_data = sateraito_db.CsvDownloadData() new_data.csv_data = csv_datas[i] new_data.data_order = i new_data.csv_download_id = csv_download_id new_data.expire_date = expire_date new_data.csv_filename = csv_filename new_data.put() # ダウンロードURL if is_api: download_url = sateraito_inc.my_site_url + '/a/' + tenant + '/storedata/exportcsvfile?id=' + csv_download_id else: download_url = sateraito_inc.my_site_url + '/a/' + tenant + '/storedata/exportcsvfile?id=' + csv_download_id if is_success: tq_entry.status = 'SUCCESS' tq_entry.deal_status = 'FIN' else: tq_entry.status = '' tq_entry.deal_status = 'PROCESSING' tq_entry.have_more_rows = have_more_rows tq_entry.download_url = download_url tq_entry.expire_date = expire_date tq_entry.csv_download_id = csv_download_id tq_entry.put() return download_url
def exportDocRowForUpdateQA(cls, row_doc, timezone=sateraito_inc.DEFAULT_TIMEZONE): line_id = '' user_info = sateraito_db.User.getUserInfo(row_doc.author_user_id) #logging.info(user_info) if user_info: line_id = user_info['line_id'] #============================== #Parse Question & Answer if row_doc.contentQA is None: return '' content_values = json.JSONDecoder().decode( sateraito_func.noneToZeroStr(row_doc.contentQA)) #logging.info(content_values) #sort list content_values_new = sorted(content_values, cmp=ExportCsv.compareValue) export_line = '' for item in content_values_new: logging.info(item) export_line_item = '' # command # export_line_item += 'IU' # user_id export_line_item += sateraito_func.escapeForCsv( row_doc.author_user_id) # line_id export_line_item += ',' + sateraito_func.escapeForCsv(line_id) #store_id export_line_item += ',' + sateraito_func.escapeForCsv( row_doc.store_id) # template_name export_line_item += ',' + sateraito_func.escapeForCsv( row_doc.template_name) #questtion number export_line_item += ',' + sateraito_func.escapeForCsv( str(item['number'])) #questtion string export_line_item += ',' + sateraito_func.escapeForCsv( item['question']) #answer string: export_line_item += ',' + sateraito_func.escapeForCsv( item['answer']) # submit_date export_line_item += ',' + sateraito_func.toShortLocalTime( row_doc.submit_date, timezone=timezone) export_line_item += '\r\n' export_line_item = sateraito_func.washShiftJISErrorChar( export_line_item) export_line += export_line_item return export_line
def appendColumnListToHeader(cls, columns): export_line = '' logging.info(columns) for col in columns: if col != '' and col not in sateraito_inc.FORM_DATA_TEMPLATE_FIELD_NAME_SKIP: export_line += ',' + col export_line += '\r\n' export_line = sateraito_func.washShiftJISErrorChar(export_line) return export_line
def exportDocRowForUpdate(cls, row_doc, timezone=sateraito_inc.DEFAULT_TIMEZONE, columns=[]): author_name = '' author_email = '' line_id = '' user_info = sateraito_db.User.getUserInfo(row_doc.author_user_id) #logging.info(user_info) if user_info: author_name = '{0} {1}'.format(user_info['last_name'], user_info['first_name']) author_email = user_info['mail_address'] line_id = user_info['line_id'] export_line = '' # command export_line += 'IU' # doc_id export_line += ',' + sateraito_func.escapeForCsv(row_doc.doc_id) # user_id export_line += ',' + sateraito_func.escapeForCsv( row_doc.author_user_id) # line_id export_line += ',' + sateraito_func.escapeForCsv(line_id) # store_id export_line += ',' + sateraito_func.escapeForCsv(row_doc.store_id) # #author_name # export_line += ',' + sateraito_func.escapeForCsv(author_name) # # author_email # export_line += ',' + sateraito_func.escapeForCsv(author_email) #export doc value doc_values = json.JSONDecoder().decode( sateraito_func.noneToZeroStr(row_doc.doc_values)) keys = doc_values.keys() if (len(columns) > 0): for column in columns: if column in keys: export_line += ',' + sateraito_func.escapeForCsv( doc_values[column]) else: export_line += ',' else: for column in keys: if column != '': export_line += ',' + sateraito_func.escapeForCsv( doc_values[column]) export_line += '\r\n' export_line = sateraito_func.washShiftJISErrorChar(export_line) return export_line
def appendDocValueToHeader(cls, row): export_line = '' doc_values = json.JSONDecoder().decode( sateraito_func.noneToZeroStr(row.doc_values)) logging.info(doc_values) for col in doc_values.keys(): if col != '' and col not in sateraito_inc.FORM_DATA_TEMPLATE_FIELD_NAME_SKIP: export_line += ',' + col export_line += '\r\n' export_line = sateraito_func.washShiftJISErrorChar(export_line) return export_line
def appendFieldExportToHeader(cls, fieldsExport): export_line = '' columns = [] for row in fieldsExport: col = row['field'] if col != '' and col not in sateraito_inc.FORM_DATA_TEMPLATE_FIELD_NAME_SKIP: export_line += ',' + col columns.append(col) export_line += '\r\n' export_line = sateraito_func.washShiftJISErrorChar(export_line) return export_line, columns
def exportStoreHeaderForUpdate(cls): export_line = '' export_line += 'command,store_id,scan_id,name,reply_message,qrcode_id,qrcode_url,form_template,memo' export_line += '\r\n' export_line = sateraito_func.washShiftJISErrorChar(export_line) return export_line
def exportDocRowForUpdateQA2(cls, row_doc, timezone=sateraito_inc.DEFAULT_TIMEZONE): line_id = '' user_info = sateraito_db.User.getUserInfo(row_doc.author_user_id) #logging.info(user_info) if user_info: line_id = user_info['line_id'] #============================== #Parse Question & Answer QA_list = [] num_list = [] #export doc value doc_values = json.JSONDecoder().decode( sateraito_func.noneToZeroStr(row_doc.doc_values)) logging.info(doc_values) for column in doc_values.keys(): if ExportCsv.checkColQA(column): num = int(column[1:]) if not num in num_list: num_list.append(num) question_field = sateraito_inc.QA_QUESTION_FORMAT.format( num) answer_field = sateraito_inc.QA_ANSWER_FORMAT.format(num) if doc_values.has_key( question_field) and doc_values.has_key( answer_field): QA_list.append({ 'num_index': num, 'question': question_field, 'answer': answer_field }) if len(QA_list) > 0: QA_list_new = sorted(QA_list, key=lambda objeto: objeto['num_index']) QA_list = QA_list_new #logging.info('==========QA_new_list==============') #logging.info(QA_list_new) export_line = '' for item in QA_list: export_line_item = '' # command # export_line_item += 'IU' # line_id export_line_item += sateraito_func.escapeForCsv(line_id) #store_id export_line_item += ',' + sateraito_func.escapeForCsv( row_doc.store_id) # template_name export_line_item += ',' + sateraito_func.escapeForCsv( row_doc.template_name) #questtion number export_line_item += ',' + sateraito_func.escapeForCsv( str(item['num_index'])) #questtion string export_line_item += ',' + sateraito_func.escapeForCsv( doc_values[item['question']]) #answer string: export_line_item += ',' + sateraito_func.escapeForCsv( doc_values[item['answer']]) # submit_date export_line_item += ',' + sateraito_func.toShortLocalTime( row_doc.submit_date, timezone=timezone) export_line_item += '\r\n' export_line_item = sateraito_func.washShiftJISErrorChar( export_line_item) export_line += export_line_item return export_line
def exportStoreDataHeaderForUpdate(cls): export_line = '' export_line += 'command,store_id,store_name,user_id,last_name,first_name,mail_address,created_date' export_line += '\r\n' export_line = sateraito_func.washShiftJISErrorChar(export_line) return export_line
def appendDocValueToHeaderQA(cls): export_line = u'ユーザーID,LINEID,ブースID,文書ひな形名,設問番号,設問文字列,回答文字列,回答日時' export_line += '\r\n' export_line = sateraito_func.washShiftJISErrorChar(export_line) return export_line