Exemplo n.º 1
0
    def getTeacher(self):
        global g_Database
        rows = g_Database.fetchAll('SELECT * FROM teacher WHERE personID=' +
                                   str(self.personID))

        if (not len(rows)):
            return None

        teacher = Teacher()
        teacher.read_row(rows[0])
        return teacher
	def submit_all():
		result = askquestion(title="Confirmation", message= "Do you want to process?")
		if result == "yes":
			person = Person()
			person.lname = input_lastname.get(1.0, "end-1c")
			person.fname = input_firstname.get(1.0, "end-1c")
			person.birthday = datetime.date(birthYear.get(), months.index(birthMonth.get()) + 1, birthDay.get())
			person.nationality = selected_nationality.get()
			person.gender = selected_gender.get()
			person.streetNumber = str(input_houseNo.get(1.0, "end-1c")) + str(input_houseNo2.get(1.0, "end-1c"))
			person.streetname = input_street.get(1.0, "end-1c")
			person.city = input_city.get(1.0, "end-1c")
			person.postalCode = str(input_postal.get(1.0, "end-1c")) + str(input_postal2.get(1.0, "end-1c"))
			person.phone = input_phoneNumber.get(1.0, "end-1c")
			person.email = input_email.get(1.0, "end-1c")
			person.insert()

			teacher = Teacher()
			teacher.personID = person.personID
			teacher.salary = input_salary.get(1.0, "end-1c")

			person.userName = (person.lname + str(teacher.teacherID))
			person.userPass = "******"
			person.update()

			get_counsellor = selected_counsellor.get()
			if (get_counsellor == "Yes"):
				teacher.studycouncelor = 'Y'
			else:
				teacher.studycouncelor = 'N'

			teacher.insert()

			ui.AdminWindowTeachers.admin_window_teachers(window, return_function) #avoid circular import
Exemplo n.º 3
0
def get_current_user():
    """Returns an object of Student or Teacher class, whose credentials are currently saved in session."""
    if session['logged_in']:
        if session['type'] == 'S':
            return Student.get(Student.username == session['username'])
        elif session['type'] == 'T':
            return Teacher.get(Teacher.username == session['username'])
Exemplo n.º 4
0
    def test_teacher_create_class(self):
        """Can teacher create a class?"""

        import pdb
        pdb.set_trace()

        new_teacher = Teacher(username="******",
                              password="******",
                              fname="Walt",
                              lname="Disney")
        db.session.add(new_teacher)
        db.session.commit()

        teacher_id = Teacher.query.filter_by(
            username='******').one().teacher_id

        with app.test_client() as c:
            with c.session_transaction() as sess:
                sess['teacher_id'] = teacher_id

        create_class_info = {
            'registration code': "999",
            'name': "6th Period Band",
            'type_class': "marching_band"
        }
        result = self.client.post("/create-class",
                                  data=create_class_info,
                                  follow_redirects=True)
        self.assertIn("6th Period Band", result.data)
Exemplo n.º 5
0
def teacher(id):
    if current_user.role_name != 'AdminUser':
        return render_error(403)
    if id == 'new':
        t = Teacher()
    else:
        try:
            id = int(id)
        except ValueError:
            return render_error(400)
        t = db.session.query(Teacher).filter(Teacher.id == id).one_or_none()
        if t is None:
            return render_error(404)

    form = TeacherForm(request.form if request.method == 'POST' else None, obj=t)

    if form.button_delete.data:
        form.validate()
        if db.session.query(CurriculumUnit).filter(CurriculumUnit.teacher_id == t.id).count() > 0:
            form.button_delete.errors.append('Невозможно удалить преподавателя, к которому привязаны единицы учебного плана')
        if len(form.button_delete.errors) == 0:
            db.session.delete(t)
            db.session.commit()
            db.session.flush()
            return redirect(url_for('teachers'))

    if form.button_save.data and form.validate():
        form.populate_obj(t)
        db.session.add(t)
        db.session.commit()
        if id == 'new':
            db.session.flush()
            return redirect(url_for('teacher', id=t.id))

    return render_template('teacher.html', teacher=t, form=form)
class TeacherDAO:
    teacherTable = {
        "trung":
        Teacher("TC1", "Nguyen Quoc Hoang Trung", True, "30-04-1997", "Math"),
    }

    location = "database/teacherTable"

    def createTable(self):
        # if file existed
        if Path(self.location).is_file():
            return

        f = open(self.location, "wb")
        f.write(pickle.dumps(self.teacherTable))
        f.close()

    def readFromFile(self):
        f = open(self.location, "rb")
        table = pickle.loads(f.read())
        return table

    def selectAll(self):
        return self.readFromFile()

    def selectOne(self, id):
        table = self.readFromFile()

        if id in table:
            teacher = table[id]
            return teacher

        return None
Exemplo n.º 7
0
    def update_values(self):
        from model import Teacher

        query = Teacher.all()
        for teacher in query:
            teacher.admin = False
            teacher.put()

        self.write_response_plain_text("OK")
    def get(self):
        from model import Teacher
        self.load_search_party_context(user_type="teacher")
        
        # Close any active session the user has since s/he is trying to login
        if self.session.is_active():
            self.session.terminate()

        # Get the teacher's record
        if not self.is_teacher:
            teacher = Teacher(key_name=self.user.user_id()) # key is user ID of authenticated Google user
            teacher.user = self.user
            teacher.put()
            self.set_person(teacher)

        # Create a new session ID, for added security.
        self.session.regenerate_id()

        # Greet with nickname of authenticated Google user.
        page = self.request.get('page', 'teacher_dashboard')
        self.redirect_with_msg('Teacher Logged in.  Hello, %s.'%self.person.user.nickname(), dst='/'+page)
    def _attempt_to_identify_as_teacher(self):
        from model import Teacher
        from google.appengine.api import users

        self.user = users.get_current_user()  # authenticated Google user
        authenticated_google_user = self.user

        # Teacher is identified solely by their Google account.  If they're logged into
        # the Google account, then they're logged into Search Party.

        if authenticated_google_user is None:
            teacher = None
        else:
            teacher = Teacher.get_by_key_name(authenticated_google_user.user_id())

        return teacher
Exemplo n.º 10
0
def create_teacher(fname, lname, email, password, zipcode=None, bio=None, 
    mobile_number=None, days_of_week=None,teaching_experience_in_hours=None,
    pay_rate_per_hour=None, pod_id=None, img_url=None,covid_risk_profile_id=None):
    """Add a new teacher to the teachers table and return the teacher."""

    teacher = Teacher(fname=fname, lname=lname, email=email, password=password,
        zipcode=zipcode, bio=bio, mobile_number=mobile_number,
        days_of_week=days_of_week,
        teaching_experience_in_hours=teaching_experience_in_hours,
        pay_rate_per_hour=pay_rate_per_hour, 
        pod_id=pod_id,img_url=img_url,
        covid_risk_profile_id=covid_risk_profile_id)

    db.session.add(teacher)
    db.session.commit()

    return teacher
def generateTeacher(is_admin=False):
    person = generatePerson()

    teacher = Teacher()
    teacher.salary = random.randint(2500, 6500)
    teacher.studycouncelor = random.choice(['Y', 'N'])
    teacher.personID = person.personID
    teacher.insert()

    if is_admin:
        person.userName = "******"
    else:
        person.userName = (person.lname + str(teacher.teacherID))
    person.userPass = "******"
    person.email = (person.lname + "." + person.fname + "@diemenacademy.nl")
    person.update()
    return teacher
Exemplo n.º 12
0
def admin_add_user(role, fields):
    if role.lower() == 'student':
        user = Student()
    elif role.lower() == 'teacher':
        user = Teacher()
    elif role.lower() == 'admin':
        user = Admin()
    else:
        raise APIError('Invalid role')

    fields['password'] = hash_password(fields['password'])
    for key, value in fields.items():
        if not value:
            continue
        user.__setattr__(key, value)

    db.session.add(user)
    db.session.commit()
    return user.dict
Exemplo n.º 13
0
def load_teachers(teachers_filename):
    """Load teachers into database."""

    print "Teacher"

    for i, row in enumerate(open(teachers_filename)):
        username, password, fname, lname = row.split("|")

        teacher = Teacher(username=username,
                          password=password,
                          fname=fname,
                          lname=lname)

        db.session.add(teacher)

        if i % 10 == 0:
            print i

    db.session.commit()
    def load_user(self):
        self.client_id = self.request.get('from', None)
        import client_id_utils
        self.person_type = client_id_utils.person_type_for_client_id(self.client_id)
        assert self.person_type in ("student", "teacher")

        self.person = None
        person_key = client_id_utils.person_key_for_client_id(self.client_id)
        if self.person_type == "teacher":
            from model import Teacher
            self.person = Teacher.get_by_key_name(person_key)
        else:
            from model import Student
            lesson_code = client_id_utils.lesson_code_for_client_id(self.client_id)
            student_key = "::".join((person_key, lesson_code))
            self.person = Student.get_by_key_name(student_key)
            
        if self.person is None:
            from helpers import log
            log("***** ERROR: Person not found for client_id {0}".format(self.client_id))
Exemplo n.º 15
0
def teacher_login_():
    form = TeacherLoginForm()
    if form.validate_on_submit():
        try:
            teacher = Teacher.get(username=form.username.data)
            # adequate salt is stored in the password itself
            stored_password = teacher.password.encode('utf-8')
            password_to_check = form.password.data.encode('utf-8')
            password = hashpw(password_to_check, stored_password)
            if password != stored_password:
                raise WrongPassword('Wrong password')
        except WrongPassword:
            flash('Wrong password')
        except Teacher.DoesNotExist:
            flash('Wrong username or password')
        else:
            authorize_teacher(teacher)
            return redirect(url_for('teacher_profile'))
    flash_errors(form)
    return render_template('teacher_login.html', form=form)
Exemplo n.º 16
0
def teacher_register_process():
    """Process registration."""

    # Get form variables
    username = request.form["username"]
    password = request.form["password"]
    fname = request.form["fname"]
    lname = request.form["lname"]

    # Create new teacher object
    new_teacher = Teacher(username=username,
                          password=password,
                          fname=fname,
                          lname=lname)

    # Add teacher to database
    db.session.add(new_teacher)
    db.session.commit()

    #flash confirmation, log teacher in, redirect to teacher profile
    flash("Teacher {} {} added.".format(fname, lname))
    session["teacher_id"] = new_teacher.teacher_id
    return redirect("/teachers/{}".format(session["teacher_id"]))
Exemplo n.º 17
0
        teacher_phone= "",
        teacher_password=hash_input("abaker"),
    )

]

for rec in teacher_records:


    # Check to see if your student exists, if so, skip
    if my_teacher := session.query(Teacher).filter_by(teacher_email=rec['teacher_email']).first():
        print(f'Teacher {my_teacher} already exists. Skipping')
        continue

    # Otherwise – create the teacher
    my_teacher = Teacher(**rec)

    # add them to the session
    session.add(my_teacher)

# commit the session
session.commit()




# ------------------------------------------------------------------------------
# CREATE STUDENTS

# Create a list of records for our student
student_records = [
Exemplo n.º 18
0
import torch.distributed

torch.cuda.set_device(curdevice)


def Log(message: str):
    if curdevice == 0:
        print(message)


from model import DehazeSR, Teacher

train_teacher = args.train_teacher
if train_teacher:
    model = Teacher()
else:
    model = DehazeSR()

model_teacher_name = args.teacher
model_checkpoint_name = args.checkpoint_name

checkpoint_file = args.checkpoint

if checkpoint_file is not None:
    _filepath = f"checkpoints/{checkpoint_file}"
    print(f'loading model from {_filepath}')
    state_dict = torch.load(_filepath, map_location='cpu')['model']

Log('setup')
if torch.cuda.is_available():
Exemplo n.º 19
0
def admin_window_teachers(window, return_function):
    clear_window(window)
    whole_window = Canvas(window, width=500, height=700, bg="#EBEBE9")
    whole_window.create_rectangle(0,
                                  0,
                                  500,
                                  70,
                                  fill="#006386",
                                  outline="#006386")
    whole_window.pack()
    header_label = Label(window,
                         text="An Overview",
                         fg="#e6b800",
                         font="Arial 30",
                         bg="#006386")
    header_label.place(x=150, y=15)

    create_data_text = Button(text="+ Create new data",
                              fg="#e6b800",
                              font="Arial 12 bold",
                              bg="#2F4F4F",
                              width=15,
                              cursor=get_handcursor(),
                              highlightbackground="#006386",
                              command=partial(createNew_teacher, window,
                                              return_function))
    create_data_text.place(x=10, y=80, height=35)

    header_label1 = Label(window,
                          text="#",
                          fg="#e6b800",
                          font="Arial 10 bold",
                          bg="#006386")
    header_label1.place(x=10, y=130, width=30, height=30)
    header_label2 = Label(window,
                          text="Lastname",
                          fg="#e6b800",
                          font="Arial 10 bold",
                          bg="#006386")
    header_label2.place(x=40, y=130, width=140, height=30)
    header_label3 = Label(window,
                          text="Firstname",
                          fg="#e6b800",
                          font="Arial 10 bold",
                          bg="#006386")
    header_label3.place(x=180, y=130, width=140, height=30)
    header_label4 = Label(window,
                          text="Action",
                          fg="#e6b800",
                          font="Arial 10 bold",
                          bg="#006386")
    header_label4.place(x=320, y=130, width=165, height=30)

    teachers = Teacher.load_all()
    num_pos_y = 160
    #initial_num = 0
    y_position = 163
    for i in range(len(teachers)):
        person = teachers[i].getPerson()
        number_label = Label(window,
                             text=(i + 1),
                             fg="#00293c",
                             font="Arial 10")
        number_label.place(x=10, y=num_pos_y, width=30, height=30)
        #initial_num += 1
        teacherL_label = Label(window,
                               text=person.lname,
                               fg="#00293c",
                               font="Arial 10",
                               height=2,
                               width=15)
        teacherL_label.place(x=40, y=num_pos_y, width=140, height=30)

        teacherF_label = Label(window,
                               text=person.fname,
                               fg="#00293c",
                               font="Arial 10",
                               height=2,
                               width=15)
        teacherF_label.place(x=180, y=num_pos_y, width=140, height=30)

        bg_label = Label(window)
        bg_label.place(x=320, y=num_pos_y, width=165, height=30)
        num_pos_y += 30

        view_button = Button(window,
                             text="View",
                             font="Arial 10",
                             fg="#006386",
                             bg="#ccd9ff",
                             highlightbackground="#ccd9ff",
                             cursor=get_handcursor(),
                             height=1,
                             width=4,
                             relief=FLAT,
                             command=partial(teacher_view, window,
                                             return_function, teachers[i],
                                             person))
        view_button.place(x=330, y=y_position, height=25)
        edit_button = Button(window,
                             text="Edit",
                             font="Arial 10",
                             fg="#006386",
                             bg="#fff2cc",
                             highlightbackground="#fff2cc",
                             cursor=get_handcursor(),
                             height=1,
                             width=4,
                             relief=FLAT,
                             command=partial(teacher_edit, window,
                                             return_function, teachers[i],
                                             person))
        edit_button.place(x=380, y=y_position, height=25)

        def confirm_deletion(teacher):
            result = askquestion(title="Delete Data",
                                 message="Do you want to process?",
                                 icon="warning")
            if result == "yes":
                person = teacher.getPerson()
                teacher.delete()
                person.delete()
                admin_window_teachers(window, return_function)

        delete_button = Button(window,
                               text="Delete",
                               font="Arial 10",
                               fg="#006386",
                               bg="#ffcccc",
                               highlightbackground="#ffcccc",
                               cursor=get_handcursor(),
                               height=1,
                               width=5,
                               relief=FLAT,
                               command=partial(confirm_deletion, teachers[i]))
        delete_button.place(x=430, y=y_position, height=25)
        y_position += 30

    go_back(window, return_function)
    sign_out(window)
Exemplo n.º 20
0
#______________________functions for creating table records___________________________#
def create_teacher(teacher_fname, teacher_lname, teacher_email, teacher_phone,
                   teacher_password):
    """Creates a new teacher record"""

    # Check if email is already in use:
    if teacher := db.session.query(Teacher).filter_by(
            teacher_email=teacher_email).first():
        # Either return False which will cause an error – or return the teacher – in which
        # case, your method should be renamed `get_or_create_teacher()`
        return False

    teacher = Teacher(teacher_fname=teacher_fname,
                      teacher_lname=teacher_lname,
                      teacher_email=teacher_email,
                      teacher_phone=teacher_phone,
                      teacher_password=teacher_password)

    db.session.add(teacher)
    db.session.commit()

    # refresh to get the teacher with all their data
    db.session.refresh(teacher)

    return teacher


def create_student(student_fname, student_lname, student_email, program_name,
                   instrument, student_password, student_phone, teacher_id):
    """Creates a new student record"""
Exemplo n.º 21
0
                hour = Hour(code=k, name=v)
                db.session.add(hour)

            for k, v in data.week.items():
                day = Day(code=k, name=v)
                db.session.add(day)

            for k, v in data.goals.items():
                goal = Goal(code=k, name=v)
                db.session.add(goal)

            for k, v in data.times.items():
                time = Time(code=k, name=v)
                db.session.add(time)

            for t in data.teachers:
                teacher = Teacher(id=t['id'],
                                  name=t['name'],
                                  about=t['about'],
                                  rating=t['rating'],
                                  picture=t['picture'],
                                  price=t['price'],
                                  free=t['free'])
                db.session.add(teacher)
                for g in t['goals']:
                    new_goal = Goal.query.filter(Goal.code == g).first()
                    teacher.goals.append(new_goal)

            db.session.commit()
    app.run()