def contact_details(): if request.method == 'POST': security_form = {'Clearance required': request.form.get('security-clearance-required')} if request.form.get('nationality-restrictions') == 'yes': security_form['Permitted nationalities'] = request.form.get('nationality-detail') else: security_form['Permitted nationalities'] = 'Any' redis_store.hmset('security', security_form) question = { 'am_email': { 'for': 'activity-manager-email', 'label': 'Please give the activity manager\'s email address', 'hint': "We'll email a copy of this completed form to that address" }, 'location': { 'for': 'activity-manager-location', 'label': 'Please give your address', 'hint': 'Please include a postcode. We generally find that Activity Managers who are local ' 'to their Fast Streamer get greater benefit. ' }, 'grade': { 'for': 'activity-manager-grade', 'label': 'What grade will the Fast Streamer\'s Activity Manager hold?', 'hint': 'In general we expect this to be a Grade 7 or equivalent for trainees with less than two years ' 'experience, and a Grade 6 or equivalent for those with more.' }, 'grade_manager': { 'for': 'grade-manager-email', 'label': 'Please give the grade manager\'s email address', 'hint': "Your grade manager is the person in your department responsible for coordinating Fast Streamers. " "We'll send them a copy of this completed form." } } return render_template('submit/contact-details.html', question=question)
def confirm_role_details(): redis_store.set('roles_seen', 0) if request.method == 'POST': redis_store.hmset('contact', request.form.to_dict()) data = { 'role': { 'caption': 'Role details', 'row_data': redis_store.hgetall('role') }, 'logistics': { 'caption': 'Logistical details', 'row_data': redis_store.hgetall('logistics') }, 'security': { 'caption': 'Security details', 'row_data': redis_store.hgetall('security') } } skills = redis_store.lrange('skills', 0, -1) for s in skills: skill_data = { 'row_data': json.loads(redis_store.get(s)), 'caption': s } data[s] = skill_data return render_template('submit/confirm-role-details.html', data=data)
def security(): if request.method == 'POST': redis_store.hmset('logistics', request.form.to_dict()) question = { 'clearance': { 'heading': 'What level of security clearance is required?', 'name': 'security-clearance-required', 'values': { 'Baseline Personnel Security Standard': 'BPSS', 'Security Check': 'SC', 'Counter-Terrorism Check': 'CTC', 'Developed Vetting': 'DV', 'Not applicable': 'NA' }, 'for': 'clearance' }, 'nationality': { 'for': 'nationality-restriction', 'label': 'Are there any restrictions on the nationality of the Fast Streamer?', 'hint': "For preference, this should be one of the 37 " "<a href='https://www.gov.uk/government/collections/digital-data-and-technology-profession-capability-framework'> " "DDaT roles" }, } return render_template('submit/security.html', question=question)
def setEventData(eventName, entity): entityID = getIncEntityID(eventName) entity['id'] = entityID oldConnections = getEventConnections(eventName) # app.logger.debug(oldConnections) oldConnections['Funding'] = ([] if 'Funding' not in oldConnections else oldConnections['Funding']) oldConnections['Data'] = ([] if 'Data' not in oldConnections else oldConnections['Data']) oldConnections['Collaboration'] = ([] if 'Collaboration' not in oldConnections else oldConnections['Collaboration']) oldConnections['Employment'] = ([] if 'Employment' not in oldConnections else oldConnections['Employment']) connections = { "Funding": json.dumps(fundingConversion(entity) + oldConnections['Funding']), "Data": json.dumps(dataConversion(entity) + oldConnections['Data']), "Collaboration": json.dumps( collaborationConversion(entity) + oldConnections['Collaboration']), "Employment": json.dumps( employmentConversion(entity) + oldConnections['Employment']) } app.logger.debug(connections) entity['timestamp'] = datetime.now().strftime('%Y-%m-%dT%H:%M:%S') redis_store.hmset(eventName + '.connection', connections) redis_store.sadd(eventName + '.entity', json.dumps(entity)) return getEventEntities(eventName)
def role_details(): if request.method == 'POST': details = request.form.to_dict() redis_store.hmset('role', details) return redirect(url_for('submit.role_family')) question = { 'textarea': { 'label': 'Role description', 'hint': "Please give a description of the role and some context. For example, what " "are the team's priorities?", 'for': 'Description' }, 'role_title': { 'for': 'Title', 'label': 'Role title', 'hint': "For preference, this should be one of the 37 " "<a href='https://www.gov.uk/government/collections/digital-data-and-technology-profession-capability-framework'> " "DDaT roles" }, 'responsibilities': { 'for': 'Key responsibilities', 'label': 'Main responsibilities and deliverables of post', 'hint': "We'll use this to decide if the role has sufficient stretch" } } return render_template('submit/role-details.html', title='Role details', question=question)
def remove_base(data): # удаление базы из посчитанных redis_store.hmset(data['BASE'], { 'check_time': '', 'PNN': '', 'status': '0' }) emit('server_response', { 'info': 'bandge', 'data': data['BASE'] }, broadcast=True)
def start_counting(data): # запуск расчета баз PNN = 'ПНН' if data['CHECKED'] == True else 'без ПНН' connect_bases = [] for base in data['BASES']: host = redis_store.hmget(base[:3], ['host'])[0] try: if platform == 'linux': call(["ping", "-c", "1", host], timeout=0.25, stdout=DEVNULL) else: call(["ping", "-n", "1", host], timeout=0.25, stdout=DEVNULL) except TimeoutExpired: basename = redis_store.hmget(base[:3], ['name'])[0] emit('server_response', { 'info': 'button', 'procedure': 'error', 'data': basename }) continue connect_bases.append(base) conn = get_connection(base) cursor = conn.cursor() if PNN == 'ПНН': cursor.execute( querySQL.sql_update3, (1, 1, 'Запуск обработок: 2. Выполнить расчет с ПНН')) else: cursor.execute( querySQL.sql_update3, (1, 1, 'Запуск обработок: 1. Выполнить расчет без ПНН')) conn.commit() conn.close() # minutes = redis_store.hmget(base, ['interval'])[0] # check_time = (datetime.now()+timedelta(minutes=int(minutes))).strftime('%d.%m.%Y %H:%M:%S') check_time = (datetime.now()).strftime( '%d.%m.%Y %H:%M:%S') # DELETE THIS ROW redis_store.hmset(base, { 'check_time': check_time, 'PNN': PNN, 'status': '1' }) # need to check if len(connect_bases) > 0: emit('server_response', { 'info': 'button', 'procedure': 'start_counting', 'data': connect_bases }, broadcast=True)
def register(): username = request.form.get("username") uuid = request.form.get("uuid") push_key = request.form.get("push_key") one_time_code = request.form.get("one_time_code") print("{} {} {} {}".format(username, uuid, push_key, one_time_code)) if not (username and uuid and push_key and one_time_code): return "ERROR - INVALID INFO" key = redis_store.get(one_time_code) if not one_time_code: return "INCORRECT ONE TIME CODE" redis_store.hmset(username, {"uuid": uuid, "push_key": push_key}) redis_store.setex(one_time_code, username, 60) return "Great success!"
def change_period(data): # изменение даты запрета редактирования time = datetime.strptime('01.' + data['TIME'].replace('.2', '.4'), '%d.%m.%Y') if data['CHECKED'] == True: checked = 1 PO = '(v)' else: checked = 0 PO = '( )' connect_bases = [] for base in data['BASES']: host = redis_store.hmget(base[:3], ['host'])[0] try: if platform == 'linux': call(["ping", "-c", "1", host], timeout=0.25, stdout=DEVNULL) else: call(["ping", "-n", "1", host], timeout=0.25, stdout=DEVNULL) except TimeoutExpired: basename = redis_store.hmget(base[:3], ['name'])[0] emit('server_response', { 'info': 'button', 'procedure': 'error', 'data': basename }) continue connect_bases.append(base) conn = get_connection(base) cursor = conn.cursor() cursor.execute(querySQL.sql_update2, (time, checked)) conn.commit() conn.close() redis_store.hmset(base, {'period': data['TIME'], 'PO': PO}) if len(connect_bases) > 0: emit('server_response', { 'info': 'button', 'procedure': 'change_period', 'data': connect_bases }, broadcast=True)
def setEventData(eventName, entity): entityID = getIncEntityID(eventName) entity['id'] = entityID oldConnections = getEventConnections(eventName) # app.logger.debug(oldConnections) oldConnections['Funding'] = ([] if 'Funding' not in oldConnections else oldConnections['Funding']) oldConnections['Data'] = ([] if 'Data' not in oldConnections else oldConnections['Data']) oldConnections['Collaboration'] = ([] if 'Collaboration' not in oldConnections else oldConnections['Collaboration']) oldConnections['Employment'] = ([] if 'Employment' not in oldConnections else oldConnections['Employment']) connections = { "Funding": json.dumps(fundingConversion(entity) + oldConnections['Funding']), "Data": json.dumps(dataConversion(entity) + oldConnections['Data']), "Collaboration": json.dumps(collaborationConversion(entity) + oldConnections['Collaboration']), "Employment": json.dumps(employmentConversion(entity) + oldConnections['Employment']) } app.logger.debug(connections) entity['timestamp'] = datetime.now().strftime('%Y-%m-%dT%H:%M:%S') redis_store.hmset(eventName + '.connection', connections) redis_store.sadd(eventName + '.entity', json.dumps(entity)) return getEventEntities(eventName)
def clean_cache(data): for key in redis_store.hkeys('users'): if key[-8:] == data['BASE']: redis_store.hdel('users', key) # удаляет данные из таблицы users redis_store.delete( key ) # удаляет подробную информацию о настройках пользователе в базе 1С redis_store.hmset( data['BASE'], { 'period': '', 'PO': '', 'check_time': '', 'PNN': '', 'status': '0', 'cache': '' }) emit('server_response', { 'info': 'cache', 'data': data['BASE'] }, broadcast=True)
def server_response(): # проверка баз на окончание расчета current_bases = redis_store.smembers('current_bases') complite_bases = [] grz = redis_store.hmget('grz', ['name', 'host', 'interval']) dbk = redis_store.hmget('dbk', ['name', 'host', 'interval']) lvt = redis_store.hmget('lvt', ['name', 'host', 'interval']) usm = redis_store.hmget('usm', ['name', 'host', 'interval']) grz_work = redis_store.hmget( 'grz_work', ['period', 'PO', 'check_time', 'PNN', 'status', 'cache']) grz_test = redis_store.hmget( 'grz_test', ['period', 'PO', 'check_time', 'PNN', 'status', 'cache']) dbk_work = redis_store.hmget( 'dbk_work', ['period', 'PO', 'check_time', 'PNN', 'status', 'cache']) dbk_test = redis_store.hmget( 'dbk_test', ['period', 'PO', 'check_time', 'PNN', 'status', 'cache']) lvt_work = redis_store.hmget( 'lvt_work', ['period', 'PO', 'check_time', 'PNN', 'status', 'cache']) lvt_test = redis_store.hmget( 'lvt_test', ['period', 'PO', 'check_time', 'PNN', 'status', 'cache']) usm_work = redis_store.hmget( 'usm_work', ['period', 'PO', 'check_time', 'PNN', 'status', 'cache']) usm_test = redis_store.hmget( 'usm_test', ['period', 'PO', 'check_time', 'PNN', 'status', 'cache']) for base in redis_store.smembers('current_bases'): for operating_mode in ['work', 'test']: if redis_store.hmget( base + '_' + operating_mode, 'status' )[0] == '1': # если у базы статус "идет расчет", то проверяем по документам начисления и льгот str_date = redis_store.hmget(base + '_' + operating_mode, ['check_time'])[0] check_time = datetime.strptime(str_date, '%d.%m.%Y %H:%M:%S') if check_time < datetime.now(): str_date = redis_store.hmget(base + '_' + operating_mode, ['period'])[0] date = datetime.strptime( '01.' + str_date.replace('.2', '.4'), '%d.%m.%Y') PNN = redis_store.hmget(base + '_' + operating_mode, ['PNN'])[0] host = redis_store.hmget(base, ['host'])[0] try: if platform == 'linux': call(["ping", "-c", "1", host], timeout=0.25, stdout=DEVNULL) else: call(["ping", "-n", "1", host], timeout=0.25, stdout=DEVNULL) except TimeoutExpired: continue conn = get_connection(base + '_' + operating_mode) cursor = conn.cursor() cursor.execute(querySQL.sql_select10, ( date, 'Абоненты с групповым измерительным оборудованием (создано обработкой)', 'Абоненты без групповых счетчиков (создано обработкой)' )) result = cursor.fetchone() if result[ 'STATUS'] == 1: # если количество проведенных документов начислений равно общему количеству документов за установленный учетный месяц if PNN == 'ПНН': cursor.execute(querySQL.sql_update3, ( 0, 1, 'Запуск обработок: 2. Выполнить расчет с ПНН')) else: cursor.execute(querySQL.sql_update3, ( 0, 1, 'Запуск обработок: 1. Выполнить расчет без ПНН' )) conn.commit() redis_store.hmset(base + '_' + operating_mode, { 'check_time': '', 'status': '2' }) # меняем статус базы на "расчет завершен" conn.close() elif redis_store.hmget( base + '_' + operating_mode, 'status')[0] == '2': # если у базы "расчет завершен" complite_bases.append(base + '_' + operating_mode) emit('server_response', { 'info': 'server', 'data': complite_bases }, broadcast=True) # if __name__ == '__main__': # socketio.run(app)