def select_proposal(self, selected_proposal): beamline_name = self.lims_hwobj.beamline_name proposal = selected_proposal['Proposal'] #person = selected_proposal['Person'] #laboratory = selected_proposal['Laboratory'] sessions = selected_proposal['Session'] # Check if there are sessions in the proposal todays_session = None if sessions is None or len(sessions) == 0: pass else: # Check for today's session for session in sessions: beamline = session['beamlineName'] start_date = "%s 00:00:00" % session['startDate'].split()[0] end_date = "%s 23:59:59" % session['endDate'].split()[0] try: start_struct = time.strptime(start_date, "%Y-%m-%d %H:%M:%S") except ValueError: pass else: try: end_struct = time.strptime(end_date, "%Y-%m-%d %H:%M:%S") except ValueError: pass else: start_time = time.mktime(start_struct) end_time = time.mktime(end_struct) current_time = time.time() # Check beamline name if beamline == beamline_name: # Check date if current_time >= start_time and current_time <= end_time: todays_session = session break if todays_session is None: is_inhouse = self.session_hwobj.is_inhouse(proposal["code"], proposal["number"]) if not is_inhouse: if BlissWidget.isInstanceRoleClient(): self.refuseLogin(None, "You don't have a session scheduled for today!") return #if not self.askForNewSession(): # self.refuseLogin(None, None) # return current_time = time.localtime() start_time = time.strftime("%Y-%m-%d 00:00:00", current_time) end_time = time.mktime(current_time) + 60 * 60 *24 tomorrow = time.localtime(end_time) end_time = time.strftime("%Y-%m-%d 07:59:59", tomorrow) # Create a session new_session_dict = {} new_session_dict['proposalId'] = selected_proposal['Proposal']['proposalId'] new_session_dict['startDate'] = start_time new_session_dict['endDate'] = end_time new_session_dict['beamlineName'] = beamline_name new_session_dict['scheduled'] = 0 new_session_dict['nbShifts'] = 3 new_session_dict['comments'] = "Session created by MXCuBE" session_id = self.lims_hwobj.create_session(new_session_dict) new_session_dict['sessionId'] = session_id todays_session = new_session_dict localcontact = None else: session_id = todays_session['sessionId'] logging.getLogger().debug('ProposalBrick: getting local contact for %s' % session_id) localcontact = self.lims_hwobj.get_session_local_contact(session_id) #self.acceptLogin(selected_proposal['Proposal'], # selected_proposal['Person'], # selected_proposal['Laboratory'], # todays_session, # localcontact) self.acceptLogin(selected_proposal['Proposal'], todays_session)
def _do_login(self, proposal_code, proposal_number, proposal_password, beamline_name, impersonate=False): """ Descript. : """ if not impersonate: login_name = self.lims_hwobj.translate(proposal_code, 'ldap') + \ str(proposal_number) logging.getLogger().debug('ProposalBrick: querying LDAP...') ok, msg = self.ldap_connection_hwobj.login(login_name, proposal_password) if not ok: msg = "%s." % msg.capitalize() self.refuseLogin(None, msg) return logging.getLogger().debug("ProposalBrick: password for %s-%s validated" % \ (proposal_code,proposal_number)) # Get proposal and sessions logging.getLogger().debug('ProposalBrick: querying ISPyB database...') prop = self.lims_hwobj.getProposal(proposal_code, proposal_number) # Check if everything went ok prop_ok = True try: prop_ok = (prop['status']['code'] == 'ok') except KeyError: prop_ok = False if not prop_ok: self.ispybDown() return logging.getLogger().debug('ProposalBrick: got sessions from ISPyB...') proposal = prop['Proposal'] person = prop['Person'] laboratory = prop['Laboratory'] try: sessions = prop['Session'] except KeyError: sessions = None # Check if there are sessions in the proposal todays_session = None if sessions is None or len(sessions) == 0: pass else: # Check for today's session for session in sessions: beamline = session['beamlineName'] start_date = "%s 00:00:00" % session['startDate'].split()[0] end_date = "%s 23:59:59" % session['endDate'].split()[0] try: start_struct = time.strptime(start_date, "%Y-%m-%d %H:%M:%S") except ValueError: pass else: try: end_struct = time.strptime(end_date, "%Y-%m-%d %H:%M:%S") except ValueError: pass else: start_time = time.mktime(start_struct) end_time = time.mktime(end_struct) current_time = time.time() # Check beamline name if beamline == beamline_name: # Check date if current_time >= start_time and current_time <= end_time: todays_session = session break if todays_session is None: is_inhouse = self.session_hwobj.is_inhouse(proposal["code"], proposal["number"]) if not is_inhouse: if BlissWidget.isInstanceRoleClient(): self.refuseLogin(None, "You don't have a session scheduled for today!") return if not self.askForNewSession(): self.refuseLogin(None, None) return current_time = time.localtime() start_time = time.strftime("%Y-%m-%d 00:00:00", current_time) end_time = time.mktime(current_time) + 60 * 60 *24 tomorrow = time.localtime(end_time) end_time = time.strftime("%Y-%m-%d 07:59:59", tomorrow) # Create a session new_session_dict = {} new_session_dict['proposalId'] = prop['Proposal']['proposalId'] new_session_dict['startDate'] = start_time new_session_dict['endDate'] = end_time new_session_dict['beamlineName'] = beamline_name new_session_dict['scheduled'] = 0 new_session_dict['nbShifts'] = 3 new_session_dict['comments'] = "Session created by the BCM" session_id = self.lims_hwobj.createSession(new_session_dict) new_session_dict['sessionId'] = session_id todays_session = new_session_dict localcontact = None else: session_id = todays_session['sessionId'] logging.getLogger().debug('ProposalBrick: getting local contact for %s' % session_id) localcontact = self.lims_hwobj.getSessionLocalContact(session_id) self.acceptLogin(prop['Proposal'], prop['Person'], prop['Laboratory'], todays_session, localcontact)
def select_proposal(self, selected_proposal): beamline_name = self.lims_hwobj.beamline_name proposal = selected_proposal['Proposal'] #person = selected_proposal['Person'] #laboratory = selected_proposal['Laboratory'] sessions = selected_proposal['Session'] # Check if there are sessions in the proposal todays_session = None if sessions is None or len(sessions) == 0: pass else: # Check for today's session for session in sessions: beamline = session['beamlineName'] start_date = "%s 00:00:00" % session['startDate'].split()[0] end_date = "%s 23:59:59" % session['endDate'].split()[0] try: start_struct = time.strptime(start_date, "%Y-%m-%d %H:%M:%S") except ValueError: pass else: try: end_struct = time.strptime(end_date, "%Y-%m-%d %H:%M:%S") except ValueError: pass else: start_time = time.mktime(start_struct) end_time = time.mktime(end_struct) current_time = time.time() # Check beamline name if beamline == beamline_name: # Check date if current_time >= start_time and current_time <= end_time: todays_session = session break if todays_session is None: is_inhouse = self.session_hwobj.is_inhouse(proposal["code"], proposal["number"]) if not is_inhouse: if BlissWidget.isInstanceRoleClient(): self.refuseLogin( None, "You don't have a session scheduled for today!") return #if not self.askForNewSession(): # self.refuseLogin(None, None) # return current_time = time.localtime() start_time = time.strftime("%Y-%m-%d 00:00:00", current_time) end_time = time.mktime(current_time) + 60 * 60 * 24 tomorrow = time.localtime(end_time) end_time = time.strftime("%Y-%m-%d 07:59:59", tomorrow) # Create a session new_session_dict = {} new_session_dict['proposalId'] = selected_proposal['Proposal'][ 'proposalId'] new_session_dict['startDate'] = start_time new_session_dict['endDate'] = end_time new_session_dict['beamlineName'] = beamline_name new_session_dict['scheduled'] = 0 new_session_dict['nbShifts'] = 3 new_session_dict['comments'] = "Session created by the BCM" session_id = self.lims_hwobj.create_session(new_session_dict) new_session_dict['sessionId'] = session_id todays_session = new_session_dict localcontact = None else: session_id = todays_session['sessionId'] logging.getLogger().debug( 'ProposalBrick: getting local contact for %s' % session_id) localcontact = self.lims_hwobj.get_session_local_contact( session_id) #self.acceptLogin(selected_proposal['Proposal'], # selected_proposal['Person'], # selected_proposal['Laboratory'], # todays_session, # localcontact) self.acceptLogin(selected_proposal['Proposal'], todays_session)
def _do_login(self, proposal_code, proposal_number, proposal_password, beamline_name, impersonate=False): """ Descript. : """ if not impersonate: login_name = self.lims_hwobj.translate(proposal_code, 'ldap') + \ str(proposal_number) logging.getLogger().debug('ProposalBrick: querying LDAP...') ok, msg = self.ldap_connection_hwobj.login(login_name, proposal_password) if not ok: msg = "%s." % msg.capitalize() self.refuseLogin(None, msg) return logging.getLogger().debug("ProposalBrick: password for %s-%s validated" % \ (proposal_code,proposal_number)) # Get proposal and sessions logging.getLogger().debug('ProposalBrick: querying ISPyB database...') prop = self.lims_hwobj.getProposal(proposal_code, proposal_number) # Check if everything went ok prop_ok = True try: prop_ok = (prop['status']['code'] == 'ok') except KeyError: prop_ok = False if not prop_ok: self.ispybDown() return logging.getLogger().debug('ProposalBrick: got sessions from ISPyB...') proposal = prop['Proposal'] person = prop['Person'] laboratory = prop['Laboratory'] try: sessions = prop['Session'] except KeyError: sessions = None # Check if there are sessions in the proposal todays_session = None if sessions is None or len(sessions) == 0: pass else: # Check for today's session for session in sessions: beamline = session['beamlineName'] start_date = "%s 00:00:00" % session['startDate'].split()[0] end_date = "%s 23:59:59" % session['endDate'].split()[0] try: start_struct = time.strptime(start_date, "%Y-%m-%d %H:%M:%S") except ValueError: pass else: try: end_struct = time.strptime(end_date, "%Y-%m-%d %H:%M:%S") except ValueError: pass else: start_time = time.mktime(start_struct) end_time = time.mktime(end_struct) current_time = time.time() # Check beamline name if beamline == beamline_name: # Check date if current_time >= start_time and current_time <= end_time: todays_session = session break if todays_session is None: is_inhouse = self.session_hwobj.is_inhouse(proposal["code"], proposal["number"]) if not is_inhouse: if BlissWidget.isInstanceRoleClient(): self.refuseLogin( None, "You don't have a session scheduled for today!") return if not self.askForNewSession(): self.refuseLogin(None, None) return current_time = time.localtime() start_time = time.strftime("%Y-%m-%d 00:00:00", current_time) end_time = time.mktime(current_time) + 60 * 60 * 24 tomorrow = time.localtime(end_time) end_time = time.strftime("%Y-%m-%d 07:59:59", tomorrow) # Create a session new_session_dict = {} new_session_dict['proposalId'] = prop['Proposal']['proposalId'] new_session_dict['startDate'] = start_time new_session_dict['endDate'] = end_time new_session_dict['beamlineName'] = beamline_name new_session_dict['scheduled'] = 0 new_session_dict['nbShifts'] = 3 new_session_dict['comments'] = "Session created by the BCM" session_id = self.lims_hwobj.createSession(new_session_dict) new_session_dict['sessionId'] = session_id todays_session = new_session_dict localcontact = None else: session_id = todays_session['sessionId'] logging.getLogger().debug( 'ProposalBrick: getting local contact for %s' % session_id) localcontact = self.lims_hwobj.getSessionLocalContact(session_id) self.acceptLogin(prop['Proposal'], prop['Person'], prop['Laboratory'], todays_session, localcontact)