def setUp(self):
        # set up the test DB
        self.db = tested_db
        self.db.create_all()
        self.db.session.add(Professor(id=1, title="Teacher Assistant", student_id=1))
        self.db.session.add(Professor(id=2, title="Professor", student_id=2))
        self.db.session.commit()

        self.app = tested_app.test_client()
Exemple #2
0
def profile_update(net_id):
    if not current_user.net_id == net_id:
        return redirect("/", code=301)

    result = request.form
    if current_user.is_student:
        user = Student.get_student_by_netid(net_id)
        new_email = result["email"] or (net_id + "@cornell.edu")
        new_year = result["user_year"] or "Freshman"
        new_description = result["user_description"] or ""
        courses = result["courses"] or ""

        error = False
        _, email = parseaddr(new_email)
        if not email or '@' not in email:
            flash('A valid email is required.')
            error = True

        if new_year not in ("Freshman", "Sophomore", "Junior", "Senior",
                            "Graduate", "Post-graduate"):
            flash('A valid year is required')
            error = True

        if error:
            return redirect("/profile/" + str(net_id))

        Student.update_student(net_id,
                               email=email,
                               major=user.major,
                               year=new_year,
                               resume=None,
                               description=new_description,
                               favorited_projects=None,
                               courses=courses)
    else:
        error = False
        if " " not in result.get('name', None).strip():
            flash('Please give a first and last name.')
            error = True

        _, email = parseaddr(result.get('email', ''))
        if not email or '@' not in email:
            flash('A valid email is required.')
            error = True

        if error:
            return redirect("/profile/" + str(net_id))

        Professor.update_professor(net_id,
                                   name=result.get('name', None),
                                   email=result.get('user_email', None),
                                   website=result.get('website', ''),
                                   office=result.get('office_loc', ''))
    return redirect("/profile/" + net_id, code=302)
Exemple #3
0
def criar_professor(request):
    if request.method == 'POST':
        form = ProfessorForm(request.POST)
        if form.is_valid():
            with transaction.commit_on_success():
                user = form.save()
                user.user_permissions.add(Permission.objects.get(codename = "professor"))
                professor = Professor(user = user)
                professor.save()
                return render_to_response ('private/mensagem_generica.html',{'link':'/aluno', 'msg':'Professor Cadastrado!'},  context_instance=RequestContext(request))
    else:
        form = ProfessorForm()
    return render_to_response('private/professor/professor_form.html', {'form':form}, context_instance=RequestContext(request))
Exemple #4
0
def admin():
    form = ProfessorForm()
    form2 = CollegeForm()

    if form.add_professor.data and form.validate_on_submit():
        professor = Professor(first_name=form.first_name.data,
                              last_name=form.last_name.data,
                              department=form.department.data,
                              college=College.query.filter_by(
                                  college_acronym=form.college.data).first())
        db.session.add(professor)
        db.session.commit()
        flash('Professor Added')
        return redirect(url_for('professor', profname=professor.first_name))

    if form2.add_college.data and form2.validate_on_submit():
        college = College(college_name=form2.college_name.data,
                          college_acronym=form2.college_acronym.data,
                          state=form2.state.data)
        db.session.add(college)
        db.session.commit()
        flash('College Added')
        return redirect(url_for('main'))

    return render_template("admin.html", form=form, form2=form2, title='Admin')
def init_db():
    from models import Professor, SchoolClass
    # Base.metadata.drop_all(bind=engine)
    Base.metadata.create_all(bind=engine)

    # Check for any courses in database
    # TODO: Figure out the clean way to check if the database is empty
    count = 0
    check = db_session.query(SchoolClass)
    for course in check:
        count += 1

    if count != 0:
        return

    print("initializing database from 'data.json'")
    try:
        course_data = json.load(open('data.json'))
    except IOError:
        print("put the initial course data into data.json")

    courses = course_data['courses']
    for course in courses:
        prof_names = course['faculty']
        # Todo: Handle multiple teachers well
        prof_name = prof_names[0]
        prof = Professor.query.filter_by(name=prof_name).first()
        if prof is None:
            prof = Professor(name=prof_name)
            db_session.add(prof)
        if course['schedule'] != []:
            start_time = course['schedule'][0]['startTime']
            end_time = course['schedule'][0]['endTime']
            days = course['schedule'][0]['days']
            if days == []:
                days = ""
        else:
            start_time = None
            end_time = None
            days = None
        course = SchoolClass(department=course['department'],
                             number=course['courseNumber'],
                             suffix=course['courseCodeSuffix'],
                             school=course['school'],
                             section=course['section'],
                             name=course['courseName'],
                             professor=prof,
                             open_seats=course['openSeats'],
                             total_seats=course['totalSeats'],
                             course_status=course['courseStatus'],
                             days=days,
                             start_time=start_time,
                             end_time=end_time,
                             credits=course['quarterCredits'],
                             start_date=course['startDate'],
                             end_date=course['endDate'])
        db_session.add(course)

    db_session.commit()
Exemple #6
0
def profile(net_id):
    if not current_user.net_id == net_id:
        return redirect("/", code=301)

    favorited_projects = None
    active_collection = None
    inactive_collection = None

    if current_user.is_student:
        favorited_projects = Student.get_student_favorited_projects(net_id)
        Professor.annotate_posts(favorited_projects)
    else:
        active_collection, _, _ = Post.get_posts(professor_id=net_id,
                                                 active_only=True,
                                                 compressed=True)
        inactive_collection, _, _ = Post.get_posts(professor_id=net_id,
                                                   inactive_only=True,
                                                   compressed=True)

        Professor.annotate_posts(active_collection)
        Professor.annotate_posts(inactive_collection)

    return render_template('profile.html',
                           title=current_user.name + "'s Profile",
                           base_url=app.config['BASE_URL'],
                           profile=current_user,
                           all_courses=app.config['COURSES'],
                           favorited_projects=favorited_projects,
                           active_collection=active_collection,
                           inactive_collection=inactive_collection)
Exemple #7
0
def posts():
    phrase = request.args.get('phrase', '')
    search_tags = request.args.get('search_tags', '')
    page = int(request.args.get('page', 1))
    courses = current_user.is_student and request.args.get('courses', False)

    url_params = []
    if search_tags:
        search_tags = ','.join(t for t in search_tags.split(',')
                               if t in app.config['TAGS'])
        url_params.append('search_tags=%s' % search_tags)
    if phrase:
        url_params.append('phrase=%s' % phrase)
    if courses:
        url_params.append('courses=%s' % courses.lower())
    search_url = '&%s' % '&'.join(url_params)

    posts, has_next, total_number_of_pages = Post.get_posts(
        page=page,
        compressed=True,
        tags=search_tags,
        keywords=phrase,
        active_only=True,
        required_courses=current_user.courses if bool(courses) else None)
    Professor.annotate_posts(posts)

    return render_template("index.html",
                           title='Home',
                           user=current_user,
                           base_url=app.config['BASE_URL'],
                           posts=posts,
                           search=True,
                           tags=app.config['TAGS'],
                           total_number_of_pages=total_number_of_pages,
                           checked='checked' if bool(courses) else '',
                           phrase=phrase,
                           search_tags=search_tags,
                           page=page,
                           has_next_page=has_next,
                           search_url=search_url)
Exemple #8
0
def showpost(post_id):
    post = Post.get_post_by_id(post_id)
    if not post or (not post.is_active
                    and not current_user.net_id == post.professor_id):
        return redirect('/')

    post = post.serialize
    post['professor_name'] = Professor.get_professor_by_netid(
        post['professor_id']).name

    return render_template('full_post.html',
                           base_url=app.config['BASE_URL'],
                           post=post)
Exemple #9
0
def put_professor():
    # get the name first, if no name then fail
    title = request.form.get("title")
    if not title:
        return make_response(jsonify({"code": 403,
                                      "msg": "Cannot put student. Missing mandatory fields."}), 403)
    professor_id = request.form.get("id")
    if not professor_id:
        p = Professor(title=title)
    else:
        p = Professor(id=professor_id, title=title, student_id=professor_id)

    db.session.add(p)
    try:
        db.session.commit()
    except sqlalchemy.exc.SQLAlchemyError as e:
        error = "Cannot put student. "
        print(app.config.get("DEBUG"))
        if app.config.get("DEBUG"):
            error += str(e)
        return make_response(jsonify({"code": 404, "msg": error}), 404)
    return jsonify({"code": 200, "msg": "success"})
Exemple #10
0
def reference():
    Entry = namedtuple('Entry', ['professor_email'])
    ref_value = Reference.load(current_user.id)
    if ref_value.ref_list:
        data = {'ref_list': []}
        for professor_email in ref_value.ref_list:
            data['ref_list'].append(Entry(professor_email))
        form = ReferenceListForm(data=data)
    else:
        form = ReferenceListForm()
    if form.validate_on_submit():
        if form.add.data:
            if bool(form.professor_email.data) and Professor.load(form.professor_email.data) is not None:
                ref_value.add(form.professor_email.data)
                flash('Reference added', 'success')
                commit()
            else:
                flash('Invalid email', 'danger')
            return redirect(url_for('reference.reference'))
        else:
            for index in range(len(form.ref_list)):
                if form.ref_list[index].save.data:
                    if bool(form.ref_list[index].professor_email.data) and Professor.load(
                            form.ref_list[index].professor_email.data) is not None:
                        ref_value.update(index, form.ref_list[index].professor_email.data)
                        commit()
                        flash('Updated successfully', 'success')
                    else:
                        flash('Invalid email', 'danger')
                    return redirect(url_for('reference.reference'))
                if form.ref_list[index].delete.data:
                    ref_value.delete(index)
                    commit()
                    flash('Deleted successfully', 'success')
                    return redirect(url_for('reference.reference'))
    return render_template('reference.html', form=form)
Exemple #11
0
def login(request):
	if request.session.get('professor', False):
		return render_to_response(DIR + 'professor.html', {'professor' : request.session['professor']}, context_instance=RequestContext(request))
			
	if request.method == "POST":
		login = request.POST['login']
		senha = request.POST['senha']
		
		if login == "" or senha == "":
			return render_to_response(DIR + "erro.html", {})
		else:
		
			try:
				p = Professor.objects.get(login=login,senha=senha)
				request.session['professor'] = p
				return render_to_response(DIR + 'professor.html', { 'professor' : request.session['professor'] }, context_instance=RequestContext(request))
			except:
				return render_to_response(DIR + 'erro.html', {} )
	else:
		form = Professor();
		
	return render_to_response(DIR + "login.html", {'form': form}, context_instance=RequestContext(request))
Exemple #12
0
# 40: Orientação de Estágio
# 41: Projeto Integrado
# 42: Sistemas Embarcados

# 8o Período
# 43: Administração de Comércio Eletrônico
# 44: Empreendedorismo
# 45: Infraestrutura de Tecnologia da Informação
# 46: Inovação e Novas Tecnologias
# 47: Optativa
# 48: Perícia em Informática
# 49: Processamento de Imagens
# 50: TCC


rc = Professor(id=1, sigla='RC', ch_max=10, disciplinas=[1], preferencias=[[1, 1, 1, 1, 1], [1, 1, 1, 1, 1]])
es = Professor(id=2, sigla='ES', ch_max=10, disciplinas=[2, 5], preferencias=[[1, 1, 1, 1, 1], [1, 1, 1, 1, 1]])
br = Professor(id=3, sigla='BR', ch_max=8, disciplinas=[3], preferencias=[[1, 1, 1, 1, 1], [1, 1, 1, 1, 1]])
cr = Professor(id=4, sigla='CR', ch_max=5, disciplinas=[4], preferencias=[[-1, 1, 1, -1, 1], [-1, -1, 1, -1, 1]])
ar = Professor(id=5, sigla='AR', ch_max=6, disciplinas=[6], preferencias=[[1, 1, 1, -1, -1], [1, 1, 1, -1, -1]])
dm = Professor(id=6, sigla='DM', ch_max=6, disciplinas=[7], preferencias=[[1, 1, 1, 1, 1], [1, 1, 1, 1, 1]])


professores = [
    rc, es, br, cr, ar, dm
]



class Bootstrap:
 def setUp(self):
     sys.path.insert(0, "../../src")
     from models import Professor
     self.sohee = Professor("*****@*****.**", "sohee2017")
     self.bob = Professor("*****@*****.**", "please", "Bob the Builder")
Exemple #14
0
def project():
    Entry = namedtuple(
        'Entry', ['title', 'professors', 'start', 'end', 'text_description'])
    project_value = Project.load(current_user.id)
    if project_value.project_list:
        data = {'project_list': []}
        for project_dict in project_value.project_list:
            data['project_list'].append(
                Entry(project_dict['title'],
                      "\n".join(project_dict['professor_list']),
                      project_dict['start_date'], project_dict['end_date'],
                      project_dict['description']))
        form = ProjectListForm(data=data)
    else:
        form = ProjectListForm()
    if form.validate_on_submit():
        if form.add.data:
            if bool(form.title.data) and bool(form.professors.data):
                prof_list = [
                    prof.strip("\r")
                    for prof in form.professors.data.split('\n')
                ]
                if prof_list[-1] == '':
                    del prof_list[-1]
                check = True
                for prof in prof_list:
                    if Professor.load(prof) is None:
                        check = False
                if check:
                    project_dict = {
                        'title': form.title.data,
                        'professor_list': set(prof_list),
                        'start_date': form.start.data,
                        'end_date': form.end.data,
                        'description': form.text_description.data
                    }
                    project_value.add(project_dict)
                    flash('Project added', 'success')
                    commit()
                else:
                    flash('Bad emails', 'danger')
            else:
                flash('Empty field', 'danger')
            return redirect(url_for('project.project'))
        else:
            for index in range(len(form.project_list)):
                if form.project_list[index].save.data:
                    if bool(form.project_list[index].title.data) and bool(
                            form.project_list[index].professors.data):
                        prof_list = [
                            prof.strip("\r") for prof in form.
                            project_list[index].professors.data.split('\n')
                        ]
                        if prof_list[-1] == '':
                            del prof_list[-1]
                        check = True
                        for prof in prof_list:
                            if Professor.load(prof) is None:
                                check = False
                        if check:
                            project_dict = {
                                'title':
                                form.project_list[index].title.data,
                                'professor_list':
                                set(prof_list),
                                'start_date':
                                form.project_list[index].start.data,
                                'end_date':
                                form.project_list[index].end.data,
                                'description':
                                form.project_list[index].text_description.data
                            }
                            project_value.update(index, project_dict)
                            commit()
                            flash('Updated successfully', 'success')
                        else:
                            flash('Bad emails', 'danger')
                    else:
                        flash('Empty field', 'danger')
                    return redirect(url_for('project.project'))
                if form.project_list[index].delete.data:
                    project_value.delete(index)
                    commit()
                    flash('Deleted successfully', 'success')
                    return redirect(url_for('project.project'))
    return render_template('project.html', form=form)
def create_prof():
    name = request.json["name"]
    new_prof = Professor(name=name)
    db.session.add(new_prof)
    db.session.commit()
    return jsonify("{} was created".format(new_prof))
Exemple #16
0
    "theme": {
        "Unit Total":
        '7 Units',
        'Requirements':
        "Choose seven courses total from Social & Behavioral Sciences and Humanities. A maximum of five courses may be chosen from a single category."
    },
    "honors": {
        'Unit Total':
        'Two or More Quarters of Independent Study',
        'Requirements':
        'Cumulative GPA of 3.50 or higher, At least three units of advanced study'
    }
}

professors_dictionary = {
    'Alshurafa': Professor(['395'], 4.07),
    'Argall': Professor(['301', '469'], 5.00),
    'Birnbaum': Professor(['337', '338', '395'], 3.70),
    'Bustamante': Professor(['343', '345', '395'], 5.07),
    'Campanoni': Professor(['322', '395'], 5.40),
    'Xin Chen': Professor(['340', '350', '354', '395'], 4.99),
    'Yan Chen': Professor(['395'], 4.35),
    'Cossairt': Professor(['395', '395'], 5.15),
    'De': Professor(['335', '395'], 5.02),
    'Dinda': Professor(['213', '339', '340', '395', '441'], 4.43),
    'Downey': Professor(['349', '395', '474'], 4.75),
    'Duggan': Professor(['339', '395'], 4.15),
    'Findler': Professor(['321', '395', '395'], 5.21),
    'Forbus': Professor(['344', '370', '371'], 4.69),
    'G. Memik': Professor(['361'], 4.74),
    'Gergle': Professor(['395'], 5.28),