def addRecord(row): staff = Staff(row["name"], row["no"]) phone = Phone(row["ofphone"], row["mobile"], row["mobile2"]) staff.phone = phone session = connectdb() session.add(staff) try: session.commit() except: session.rollback() raise session.close()
def test_parse_and_convert_modified_staff(): original_dict = db.get_all_staff()[0] parsed_object = Staff.parse(original_dict) # Type: Meeting parsed_object.name = "AASNvlaSNv aknsv laksnvlakvn" original_dict["name"] = "AASNvlaSNv aknsv laksnvlakvn" parsed_dict = parsed_object.to_json_dict() assert original_dict == parsed_dict
def insert_client_info(self, client_name, client_id, client_phone, client_address, contact_name, relationship, contact_phone, contact_email): # necessary info complete and valid -> add # you cannot use self.handle_client if len(client_name) > 20 or '"' in client_name or "'" in client_name or client_id[0:2] != 'ID' or len(client_phone) != 11: msg = '用户信息不合法' elif len(contact_phone) != 11 or '@' not in contact_email or '"' in contact_name or "'" in contact_name: msg = '联系人信息不合法' else: try: client_item = BankClient.create(client_name=client_name, client_id_number=client_id, client_contact=client_phone, client_address=client_address, contactor_name=contact_name, contactor_phone=contact_phone, contactor_email=contact_email, relationship=relationship) except Exception as e: msg = repr(e) else: try: query1 = Staff.select().where(Staff.branch_bank_name == self.branch_name) except Exception as e: client_item.delete_instance() msg = 'no staff, empty bank' + repr(e) else: choice_staff = randint(0, query1.count() - 1) charge_item = Charge.create(branchbankname=self.branch_name, client_id_number=client_id, staff_id_number=query1[choice_staff].staff_id_number, loan_or_account=0, cheque_or_saving=0) charge_item.save() msg = 'success' finally: print('insert_client_info: ' + msg) return msg
def test_get_role_none(): meeting = Meeting.parse(db.get_meeting(mid)) all_staff_ids = set([staff["_id"] for staff in db.get_all_staff()]) non_participants = all_staff_ids.difference(set(meeting.staff)) staff = Staff.parse(db.get_staff(non_participants.pop())) roles = get_role(staff, meeting) assert (len(roles) == 0)
def get_or_create_staff(self, staff_json): staff_id = staff_json['id'] if staff_id in self.staffs_cache: return self.staffs_cache[staff_id] staff_entity = Staff(id=staff_id, name=staff_json['name'], abstract=staff_json['abstract'], portrait=staff_json['avatar']['large']) self.session.add(staff_entity) self.staffs_cache[staff_id] = staff_entity return staff_entity
def seed_db(token): """seeds the database with student, staff and channel information""" url = 'https://slack.com/api/users.list?token={}&pretty=1'.format(token) response = requests.get(url) js = response.json() for person in js['members']: person_id = person['id'] person_name = person['profile']['real_name'] slack_name = person['name'] is_staff = raw_input("Is {} a staff member? (y, n or i for ignore) ".format(person_name)) if is_staff == 'i': continue if is_staff == 'y': staff = Staff.query.filter_by(staff_id=person_id).first() work_day = raw_input("What day of the week is {}'s workday? ".format(person_name)) if work_day == '': work_day = False if staff: staff.work_day = work_day else: staff = Staff( staff_id=person_id, staff_name=person_name, work_day=work_day, staff_slack_name = slack_name ) db.session.add(staff) else: student = Student( student_id=person_id, student_name=person_name, student_slack_name=slack_name ) db.session.add(student) db.session.commit()
def load_Staff(): """Load staff information from staff.csv into database.""" print "staff" Staff.query.delete() for row in open("seed_data/staff"): row = row.strip() items = row.split(",") staff = Staff(staff_id=items[0], staff_role=items[1], fname=items[2], lname=items[3], email=items[4], username=items[5], password=items[6], work_phone=items[7]) db.session.add(staff) db.session.commit()
def login(address, secret): global public_key, secret_key, staff public_key = address secret_key = secret staff_dict = db.get_staff(address) if staff_dict is None: print("Unknown Staff!") try: staff = Staff.parse(staff_dict) except Exception as e: print("Error parsing staff!", e) if staff is None: print("Unknown Staff!") print("****************************************\n" "* C-MEET CLI (FOR TESTING) *\n" "****************************************") print("Connected to Meeting Server!") print("You are logged in as ", staff.name, "!\n") menu() print("Bye!") sio.disconnect()
from flask import json, request from flask_restful import Resource, reqparse, fields, marshal_with from model import Staff staff = [ Staff("Jack", "AA1111", "waiter", 100), Staff("Julia", "AA2222", "cook", 120), Staff("Mike", "AA3333", "security", 80), Staff("Wilma", "AA4444", "chambermaid", 80), Staff("Kate", "AA5555", "reception", 150) ] staff_structure = { "name": fields.String, "passport_id": fields.String, "position": fields.String, "salary": fields.Integer } parser = reqparse.RequestParser() parser.add_argument('passport_id') parser.add_argument('position') parser.add_argument('delete') class GetStaff(Resource): @marshal_with(staff_structure) def get(self): args = parser.parse_args() for employee in staff:
def s_reg(): # if logged in, redirect to profile if "user_id" in session: #if user in session is not the owner, redirect to profile page if session["user_name"] != owner_user: flash("Only owner is authorized to register a staff acount") customer = Customer.query.filter_by( customer_name=session['user_name']).first() staff = Staff.query.filter_by( staff_name=session['user_name']).first() #if person in session is staff redirect to their profile if staff is not None: return redirect( url_for("profile", username=session["user_name"])) #else person in session is customer, redirect to their profile else: return redirect( url_for("profile", username=session["user_name"])) #if user in session is the owner, redirect to staff registration page elif session["user_name"] == owner_user: print("helloworld") if request.method == "POST": customer = Customer.query.filter_by( customer_name=request.form["user"]).first() staff = Staff.query.filter_by( staff_name=request.form["user"]).first() if not request.form['user']: flash('You have to enter a username') return render_template("staffSignupPage.html") elif not request.form['email'] or \ '@' not in request.form['email']: flash('You have to enter a valid email address') return render_template("staffSignupPage.html") elif not request.form['pass']: flash('You have to enter a password') return render_template("staffSignupPage.html") #if name is already in customer or staff table elif customer is not None: flash("Username already taken!") return render_template("staffSignupPage.html") elif staff is not None: flash("Username already taken!") return render_template("staffSignupPage.html") elif request.form['user'] == owner_user: flash("Username already taken!") return render_template("staffSignupPage.html") #else add staff to the customer table else: db.session.add( Staff(request.form['user'], request.form['email'], generate_password_hash(request.form['pass']))) db.session.commit() flash( 'Staff successfully registered. The memeber can login now' ) return redirect(url_for("profile", username=owner_user)) else: return render_template("staffSignupPage.html") # if all else fails, offer to log them in flash("If you are the owner, login to register a staff acount") return redirect(url_for("login_controller"))
def room_message(event_string): """ Main function that handles all events that enter through the web socket """ # Parse json as dict try: event_json = json.loads(event_string) except ValueError as ve: log.error("Error Parsing room-message as JSON!") log.error(ve) traceback.print_tb(ve.__traceback__) return json.dumps( sign( get_error_ack( "unknown", "unknown", content=AckErrorContent( error_code=EventError.MALFORMED_EVENT, details='Cant parse message as JSON'))).to_json_dict()) # Validate JSON dict using schema ok, err_event = validate_schema(event_json) if not ok: log.error("Sending error msg") errormsg = json.dumps(sign(err_event).to_json_dict()) log.error("======== error_msg: " + errormsg) return errormsg # Parse dict as event object try: event = Event.parse(event_json) except KeyError as ve: log.error("Error Parsing room-message!") log.error(ve) traceback.print_tb(ve.__traceback__) return json.dumps( sign( get_error_ack("unknown", "unknown", content=AckErrorContent( error_code=EventError.MALFORMED_EVENT, details='Cant parse message as Event'))). to_json_dict()) # Check timestamp ok, err_event = validate_timestamp(event) if not ok: return json.dumps(sign(err_event).to_json_dict()) # Get the staff try: staff = Staff.parse(db.get_staff(event.by)) except KeyError as ke: log.error(ke) traceback.print_tb(ke.__traceback__) return json.dumps( sign( get_error_ack(event.id, event.meeting_id, content=AckErrorContent( error_code=EventError.STAFF_NOT_FOUND, details=''))).to_json_dict()) except TypeError as te: log.error(te) traceback.print_tb(te.__traceback__) return json.dumps( sign( get_error_ack(event.id, event.meeting_id, content=AckErrorContent( error_code=EventError.STAFF_NOT_FOUND, details=''))).to_json_dict()) # Get the meeting try: meeting = Meeting.parse(db.get_meeting(event.meeting_id)) except KeyError as ke: log.error(ke) traceback.print_tb(ke.__traceback__) return json.dumps( sign( get_error_ack(event.id, event.meeting_id, content=AckErrorContent( error_code=EventError.MEETING_NOT_FOUND, details=''))).to_json_dict()) except TypeError as te: log.error(te) traceback.print_tb(te.__traceback__) return json.dumps( sign( get_error_ack(event.id, event.meeting_id, content=AckErrorContent( error_code=EventError.MEETING_NOT_FOUND, details=''))).to_json_dict()) # Check signature, before trusting anything it says if event.type in [MeetingEventType.JOIN, MeetingEventType.START ]: # We check contract for join and start ok, err_event = validate_signature(event, staff, meeting, check_contract=True) if not ok: return json.dumps(sign(err_event).to_json_dict()) else: ok, err_event = validate_signature(event, staff, meeting) if not ok: return json.dumps(sign(err_event).to_json_dict()) # Get the roles roles = get_role(staff, meeting) # A preliminary authority check to see if the user can make any statements about the meeting ok, err_event = validate_preliminary_authority(event, roles) if not ok: return json.dumps(sign(err_event).to_json_dict()) # Get the event type event_type = MeetingEventType(event.type) ack_event = None ok = False end_meeting = False send_privately = False if event_type == MeetingEventType.START: ok, ack_event = start(event, staff, meeting, roles) if event_type == MeetingEventType.JOIN: ok, ack_event = join(event, staff, meeting, roles) if event_type == MeetingEventType.LEAVE: ok, ack_event = leave(event, staff, meeting) if event_type == MeetingEventType.POLL: ok, ack_event = poll(event, staff, meeting, roles) if event_type == MeetingEventType.VOTE: ok, ack_event = vote(event, staff, meeting, roles) if event_type == MeetingEventType.POLL_END: ok, ack_event = end_poll(event, staff, meeting, roles) if event_type == MeetingEventType.COMMENT or event_type == MeetingEventType.REPLY or event_type == MeetingEventType.DISAGREEMENT: ok, ack_event = comment_reply_disagreement(event, staff, meeting, roles) if event_type == MeetingEventType.DISCUSSION: ok, ack_event = discussion(event, staff, meeting, roles) if event_type == MeetingEventType.PATIENT_DATA_CHANGE: ok, ack_event = patient_data_change(event, staff, meeting, roles) if event_type == MeetingEventType.END: ok, ack_event = end(event, staff, meeting, roles) if ok: end_meeting = True if not ok: # If not ok we send the error ack event privately return json.dumps(sign(ack_event).to_json_dict()) else: # If an event has been referenced check_and_remove_ref_event(meeting, event.ref_event) # Add ack and event to unreferenced events add_event_as_unref(meeting, event) add_event_as_unref(meeting, ack_event) # Sign the ack signed_ack_event = sign(ack_event) if not send_privately: # Only Broadcast if the send_privately is set to False # Broadcast event send(json.dumps(event.to_json_dict()), broadcast_room=meeting.id) send(json.dumps(signed_ack_event.to_json_dict()), broadcast_room=meeting.id) record(event, meeting) record(signed_ack_event, meeting) if end_meeting: end_meeting_session(meeting, event, signed_ack_event) # Send the ack event to the user privately as well return json.dumps(signed_ack_event.to_json_dict())
def test_parse_and_convert_staff(): original_dict = db.get_all_staff()[0] parsed_object = Staff.parse(original_dict) generated_dict = parsed_object.to_json_dict() assert original_dict == generated_dict
def test_get_role_participant(): meeting = Meeting.parse(db.get_meeting(mid)) staff = Staff.parse(db.get_staff(meeting.staff[1])) roles = get_role(staff, meeting) assert (Role.PARTICIPANT in roles)
def test_get_role_host(): meeting = Meeting.parse(db.get_meeting(mid)) staff = Staff.parse(db.get_staff(meeting.host)) roles = get_role(staff, meeting) assert (Role.HOST in roles) and (Role.PARTICIPANT in roles)