示例#1
0
	def getApprovalApplyVoListByUser(cls, helper, operator_unique_id):
		apply_vos = []
		q = UCFMDLAccessApply.all()
		q.filter('operator_unique_id =', operator_unique_id)
		q.filter('approval_status IN', ['APPROVAL', 'DENY'])			# 申請済みはカウントしないべきなので修正 2016.11.24
		active_apply_count = 0
		for entry in q:
			vo = entry.exchangeVo(helper._timezone)
			AccessApplyUtils.editVoForSelect(helper, vo)
			is_approval = True
			# ステータス.承認済みかどうか
			if is_approval and UcfUtil.getHashStr(vo, 'approval_status') != 'APPROVAL':
				is_approval = False
			# アクセス期限.切れていないかどうか
			if is_approval:
				access_expire = UcfUtil.getHashStr(vo, 'access_expire')
				if access_expire != '' and UcfUtil.getNowLocalTime(helper._timezone) > UcfUtil.getDateTime(access_expire):
					is_approval = False
			if is_approval:
				apply_vos.append(vo)
		return apply_vos
示例#2
0
	def createCsv(cls, helper, login_operator_entry=None, sk_operator_unique_id='', optional_scond=None):

		logging.info('start create csv...')
		with_cursor = True
		csv_records = []
		# タイトル
		titles = AccessApplyUtils.getCsvTitles(helper)
		csv_records.append(UcfUtil.createCsvRecordEx(titles))
		# データ一覧取得
		q = UCFMDLAccessApply.all()
		if sk_operator_unique_id != '':
			q.filter('operator_unique_id =', sk_operator_unique_id)

			## ユーザーごとのレコードは従来通り1000件固定
			#max_export_cnt = 1000		# 最大出力件数

		else:

			sk_search_type = UcfUtil.getHashStr(optional_scond, 'sk_search_type') if optional_scond is not None else ''
			sk_operator_id = UcfUtil.getHashStr(optional_scond, 'sk_operator_id').lower() if optional_scond is not None else ''
			#sk_operator_unique_id = UcfUtil.getHashStr(optional_scond, 'sk_operator_unique_id') if optional_scond is not None else ''
			sk_apply_date_date_from = UcfUtil.getHashStr(optional_scond, 'sk_apply_date_date_from') if optional_scond is not None else ''
			sk_apply_date_time_from = UcfUtil.getHashStr(optional_scond, 'sk_apply_date_time_from') if optional_scond is not None else ''
			sk_apply_date_date_to = UcfUtil.getHashStr(optional_scond, 'sk_apply_date_date_to') if optional_scond is not None else ''
			sk_apply_date_time_to = UcfUtil.getHashStr(optional_scond, 'sk_apply_date_time_to') if optional_scond is not None else ''

			if sk_search_type == '':
				sk_search_type = 'operator_id'


			# 委託管理者なら自分が触れるデータのみ対象
			if ucffunc.isDelegateOperator(login_operator_entry) and login_operator_entry.delegate_management_groups is not None and len(login_operator_entry.delegate_management_groups) > 0:
				q.filter('management_group IN', login_operator_entry.delegate_management_groups)
				# 管理グループが複数ある場合はカーソル使えないので
				if len(login_operator_entry.delegate_management_groups) >= 2:
					with_cursor = False

			# ログインIDで検索
			if sk_search_type == 'operator_id' and sk_operator_id != '':
				q.filter('operator_id_lower >=', sk_operator_id)
				q.filter('operator_id_lower <', sk_operator_id + u'\uFFFD')

			# 申請日時で検索
			elif sk_search_type == 'apply_date' and (sk_apply_date_date_from != '' or sk_apply_date_date_to != ''):
				if sk_apply_date_date_from != '':
					if sk_apply_date_time_from != '':
						time_ary = sk_apply_date_time_from.split(':')
						sk_apply_date_from = sk_apply_date_date_from + ' ' + time_ary[0] + ':' + time_ary[1] + ':00'
						sk_apply_date_from_utc = UcfUtil.getUTCTime(UcfUtil.getDateTime(sk_apply_date_from), helper._timezone)
					else:
						sk_apply_date_from = sk_apply_date_date_from + ' 00:00:00'
						sk_apply_date_from_utc = UcfUtil.getUTCTime(UcfUtil.getDateTime(sk_apply_date_from), helper._timezone)
					#wheres.append("apply_date >= '" + UcfUtil.escapeGql(sk_apply_date_from_utc) + "'")
					q.filter('apply_date >=', sk_apply_date_from_utc)
				if sk_apply_date_date_to != '':
					if sk_apply_date_time_to != '':
						time_ary = sk_apply_date_time_to.split(':')
						sk_apply_date_to = sk_apply_date_date_to + ' ' + time_ary[0] + ':' + time_ary[1] + ':00'
						sk_apply_date_to_utc = UcfUtil.getUTCTime(UcfUtil.getDateTime(sk_apply_date_to), helper._timezone)
					else:
						sk_apply_date_to = sk_apply_date_date_to + ' 00:00:00'
						sk_apply_date_to_utc = UcfUtil.getUTCTime(UcfUtil.add_days(UcfUtil.getDateTime(sk_apply_date_to), 1), helper._timezone)
					#wheres.append("apply_date < '" + UcfUtil.escapeGql(sk_apply_date_to_utc) + "'")
					q.filter('apply_date <', sk_apply_date_to_utc)
				q.order('-apply_date')


		# ユーザーごとも全体も上限を統一 2017.02.14
		# 全件取得の場合は、fetchのメモリ使用量が大きいため、過去何ヶ月分の制約を設けてみる(ログイン履歴の設定を流用)
		login_history_max_export_cnt = helper.getDeptInfo().get('login_history_max_export_cnt')
		max_export_cnt = UcfUtil.toInt(login_history_max_export_cnt)		# 最大出力件数
		if max_export_cnt <= 0:
			max_export_cnt = 1000
		logging.info('max_export_cnt=' + str(max_export_cnt))

		cnt = 0
		limit = 500
		#limit = 1000					# 通常の、max_export_cnt == 1000 のドメインは1発で取れたほうがいいはずなので 1000 とする
		start_cursor = None
		while True:
			if with_cursor and start_cursor is not None:
				fetch_data = q.with_cursor(start_cursor=start_cursor).fetch(limit)
			else:
				fetch_data = q.fetch(limit, cnt)

			each_cnt = 0
			for entry in fetch_data:

				vo = entry.exchangeVo(helper._timezone)
				AccessApplyUtils.editVoForCsv(helper, vo)

				data = []
				data.append('IU')																						# command
				data.append(UcfUtil.getHashStr(vo, 'apply_date'))					# apply_date
				data.append(UcfUtil.getHashStr(vo, 'operator_id'))					# email
				data.append(UcfUtil.getHashStr(vo, 'device_distinguish_id'))					# device_distinguish_id
				data.append(UcfUtil.getHashStr(vo, 'device_mac_address'))					# mac_address
				data.append(UcfUtil.getHashStr(vo, 'identifier_for_vendor'))					# identifier_for_vendor
				data.append(UcfUtil.getHashStr(vo, 'target_career'))					# target_career
				data.append(UcfUtil.getHashStr(vo, 'target_env'))					# target_env
				data.append(UcfUtil.getHashStr(vo, 'use_profile_id'))					# use_profile_id
				data.append(UcfUtil.getHashStr(vo, 'useragent_id'))					# user_agent
				data.append(UcfUtil.getHashStr(vo, 'approval_status'))					# status
				data.append(UcfUtil.getHashStr(vo, 'approval_status_date'))					# status_date
				data.append(UcfUtil.getHashStr(vo, 'access_expire'))					# access_expire
				data.append(UcfUtil.getHashStr(vo, 'last_login_date'))					# last_login_date
				data.append(UcfUtil.getHashStr(vo, 'apply_comment'))					# apply_comment
				data.append(UcfUtil.getHashStr(vo, 'approval_comment'))					# approval_comment

				csv_records.append(UcfUtil.createCsvRecordEx(data))
				each_cnt += 1

				vo = None
				entry = None
				if each_cnt % 100 == 0:
					gc.collect()

			cnt += each_cnt

			if with_cursor:
				start_cursor = q.cursor()
				logging.info(start_cursor)
			logging.info(cnt)

			# 件数上限
			if cnt >= max_export_cnt or each_cnt < limit:
				break

		csv_text = '\r\n'.join(csv_records)
		return csv_text