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()
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"))