Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Course materials #78

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions app/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
'''
This file is called by "from app import app" inside the app.py file.

It includes all the imports to be used in the app (from allImports import *).
It includes all the imports to be used in the app (from app.allImports import *).
It also includes all the application files that are used as "pages" in the app
(e.g., "from app import start" imports all the code in start.py that is behind the start.html webpage)
'''

from allImports import *
from app import allImports
from flask import Flask



app = Flask(__name__)
from app.allImports import *

# Include an import for every python file that is serving a webpage
#import your new python files here. It is not a part of the module until it is imported
Expand Down
4 changes: 3 additions & 1 deletion app/addCourse.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from allImports import *
from app.allImports import *
from app.logic import databaseInterface
from app.logic.getAuthUser import AuthorizedUser
from app.logic.redirectBack import redirect_url
from app.models import Semesters, Programs, Users


#Add Course
@app.route('/admin/courseManagement/addCourse',methods=["GET","POST"])
Expand Down
15 changes: 9 additions & 6 deletions app/allImports.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
from flask import flash
from flask import abort
from flask_admin import Admin

import sys
import pprint

from app import models
from models import * # all the database models
# from models import * # all the database models
from app.loadConfig import *
here = os.path.dirname(__file__)
cfg = load_config(os.path.join(here,'config.yaml'))

import sys
sys.dont_write_bytecode = True

def authUser(env):
Expand All @@ -41,7 +44,7 @@ def authUser(env):
@param {string} filename - the name of the file that should be in that directory
@return {string} filepath -returns the absolute path of the directory'''
'''TODO: ADD @PARAm for make dirs'''
def getAbsolutePath(relaitivePath,filename=None,makeDirs=False):
def getAbsolutePath(relaitivePath, filename=None, makeDirs=False):
filepath = os.path.join(sys.path[0],relaitivePath)
if makeDirs == True:
try:
Expand All @@ -59,8 +62,8 @@ def getAbsolutePath(relaitivePath,filename=None,makeDirs=False):
"A decorator is just a callable that takes a function as an argument and
returns a replacement function. See start.py for an example"
'''
app = Flask(__name__)
#from app import app
# app = Flask(__name__)
from app import app
app.config.from_object('settings')

# admin = Admin(app)
Expand Down
3 changes: 2 additions & 1 deletion app/archive.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from allImports import *
from app.allImports import *
from app.logic import databaseInterface
from app.logic.getAuthUser import AuthorizedUser
from app.logic.getAll import GetAll
from app.models import Semesters

@app.route("/archive/", defaults={'SEID': None}, methods = ["GET", "POST"])
@app.route("/archive/<SEID>", methods = ["GET", "POST"])
Expand Down
6 changes: 3 additions & 3 deletions app/config.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ courseManagementSidebar:
link: "/admin/courseManagement/removeCourse"

Headers:
Courses: ['Instructor','Course','Term','Syllabus Upload','Last Modified By']
Courses: ['Instructor','Course','Term','Syllabus Upload','Course Materials','Last Modified By']
Archive: ['Instructor','Course','Term','Syllabus Upload','Last Modified By']

fileOperations:
Expand Down Expand Up @@ -81,9 +81,9 @@ termInfo:
#10: 'Berea Bridge Program' # e.g. Berea Bridge Program 2016 = 201610

DEBUG:
#user: "[email protected]" #Admin Access
user: "[email protected]" #Admin Access
# user: "pearcej" #Division Chair Access
user: "jadudm" #Professor Access
# user: "jadudm" #Professor Access
# user: "nakazawam" #Program Access

contributors:
Expand Down
2 changes: 1 addition & 1 deletion app/contributors.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from allImports import *
from app.allImports import *
from app.logic import databaseInterface
from app.logic.getAuthUser import AuthorizedUser
from app.logic.getAll import GetAll
Expand Down
25 changes: 23 additions & 2 deletions app/courses.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from allImports import *
from app.allImports import *
#IMPORT LOGIC FILES
from app.logic import databaseInterface
from app.logic.getAuthUser import AuthorizedUser
from app.logic.getCourses import GetCourses
from app.logic.switch import switch
from app.logic.getAll import GetAll
from app.models import Semesters

@app.route("/courses", methods = ["GET"]) #SET A DEFAULT APP ROUTE
@app.route("/courses/<term>", methods = ["GET"]) #SET A DEFAULT APP ROUTE
Expand Down Expand Up @@ -34,6 +35,10 @@ def courses(term = 0):
programs_to_courses = two_dictionaries[1]
# MY COURSES SELECT QUERY
my_courses = getCourses.check_for_my_courses(currentSEID)
if my_courses and my_courses.courseMaterials:
print(my_courses.courseMaterials)
my_courses.courseMaterials = list(my_courses.courseMaterials)
print(my_courses.courseMaterials)
# RENDER CORRECT PAGE BASED ON ACCESS LEVEL
for case in switch(user_level):
if case('admin'):
Expand All @@ -48,7 +53,7 @@ def courses(term = 0):
break;
if case('division'):
division_key = user.DID
print division_key
print(division_key)
return render_template('courses/division.html',
cfg = cfg,
my_courses = my_courses,
Expand Down Expand Up @@ -81,3 +86,19 @@ def courses(term = 0):
abort(404)
render_template('error.html')

@app.route("/editCourseMaterials/<courseID>", methods = ["POST"])
def editCourseMaterials(courseID):
data = request.form.to_dict(flat=False)
print(courseID)
# courseMaterials = []
# if len(data) >= 0:
# for courseMaterialUsed in data:
# if courseMaterialUsed == "NoneRequired":
# break
# courseMaterials.append(courseMaterialUsed)
course = databaseInterface.get_course_info(courseID)
# print(str(courseMaterials))
course.courseMaterials = data
course.save()
print(course.courseMaterials)
return "", 200
2 changes: 1 addition & 1 deletion app/databaseAdmin.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from allImports import *
from app.allImports import *
from flask_admin.contrib.peewee import ModelView

class AuthenticatedUser(ModelView):
Expand Down
4 changes: 3 additions & 1 deletion app/deadlineDisplay.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from allImports import *
# from app import app
from app.allImports import *
from app.logic.getAuthUser import AuthorizedUser
import datetime
import time
from app.models import Deadline
#from datetime import datetime


Expand Down
5 changes: 3 additions & 2 deletions app/deadlineManagement.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from allImports import *
from app.allImports import *
from app.logic.getAuthUser import AuthorizedUser
from app.logic.redirectBack import redirect_url
import datetime
from app.models import Deadline


@app.route("/deadline/create", methods=["POST"])
Expand All @@ -15,7 +16,7 @@ def deadlineCreate():
# data contains
# deadlineDescription
data = request.form
date = datetime.datetime.strptime(data['deadlineDate'],"%m/%d/%Y").date()
date = datetime.datetime.strptime(data['deadlineDate'],"%m/%d/%Y").date()
deadline = Deadline.create(
description=data['deadlineDescription'],
date=date)
Expand Down
4 changes: 2 additions & 2 deletions app/deleteSyllabus.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from allImports import *
from app.allImports import *
import datetime
#IMPORT LOGIC FILES
from app.logic.getAuthUser import AuthorizedUser
Expand Down Expand Up @@ -32,7 +32,7 @@ def delete(CID):
update_last_modified.execute()
return redirect(redirect_url())

except Exception,e:
except Exception as e:
app.logger.info("{0} attempting to delete a syllabus.".format(str(e)))
message = "An error occured during the delete process of the file."
return render_template("error.html",
Expand Down
4 changes: 2 additions & 2 deletions app/divisionManagement.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from allImports import *
from app.allImports import *
from app.logic.getAuthUser import AuthorizedUser

from app.models import Divisions, Users

@app.route("/admin/divisionManagement/<did>", methods=["GET", "POST"])
def adminDivisionManagement(did):
Expand Down
8 changes: 4 additions & 4 deletions app/download.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import zipfile
#from Flask
from allImports import *
from app.allImports import *
from flask import send_file
from flask import send_from_directory
# From Logic
Expand All @@ -19,11 +19,11 @@ def download(CID):
page = r"/" + request.url.split("/")[-1]
try:
file_path = databaseInterface.get_course_download_file_path(CID)
print "This is file_path: {}".format(file_path)
print("This is file_path: {}".format(file_path))
message = "Download: {} has been downloaded".format(file_path)
log.writer("INFO", page, message)
return send_file(file_path, as_attachment=True)
except Exception,e:
except Exception as e:
app.logger.info("{0} attempting to download file.".format(str(e)))
message = "An error occured during the download process."
return render_template("error.html",
Expand Down Expand Up @@ -61,7 +61,7 @@ def downloadAll(SEID):
message = 'Download: {0} has been downloaded as a zip'.format(parent_folder)
log.writer("INFO", page, message)
return send_file(zip_path,as_attachment=True)
except Exception,e:
except Exception as e:
return render_template('error.html',
cfg = cfg,
message = e
Expand Down
3 changes: 2 additions & 1 deletion app/editAdmin.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from allImports import *
from app.allImports import *
from app.logic.getAuthUser import AuthorizedUser
from app.logic.redirectBack import redirect_url
from app.models import Users

def checkData(data,key):
user = None
Expand Down
5 changes: 4 additions & 1 deletion app/editDivision.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from allImports import *
from app.allImports import *
from app.logic.getAuthUser import AuthorizedUser
from app.logic.redirectBack import redirect_url
from app.models import Users


@app.route("/editDivision", methods=["POST"])
def editDivision():
authorizedUser = AuthorizedUser()
Expand Down
9 changes: 5 additions & 4 deletions app/editProgram.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from allImports import *
from app.allImports import *
from app.logic.getAuthUser import AuthorizedUser
from app.logic.redirectBack import redirect_url
from app.models import Users

@app.route("/editProgram", methods=["POST"])
def editProgram():
authorizedUser = AuthorizedUser()
Expand All @@ -27,9 +29,8 @@ def editProgram():
#LOOK THROUGH THE NEW CHAIR LIST
for user_name in newChairs:
#ADD THE USERNAMES TO THE PROGRAM CHAIR LIST
newChair = Users.get(Users.username == user_name)
print newChair.username
newChair.PID = pid
newChair = Users.get(Users.username == user_name)
newChair.PID = pid
newChair.save()
message = "USER: {0} has been added as a program chair for pid: {1}".format(user_name,pid)
log.writer("INFO", page, message)
Expand Down
2 changes: 1 addition & 1 deletion app/errorHandler.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from allImports import *
from app.allImports import *

@app.errorhandler(403)
def pageNotFound(e):
Expand Down
2 changes: 1 addition & 1 deletion app/index.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This is the home page for bcsr
from allImports import *
from app.allImports import *
@app.route("/", methods = ["GET"])
def start():
#TODO: FIND OUT HOW TO CATCH THE USERNAME FROM THE LOGIN PROCESS
Expand Down
4 changes: 2 additions & 2 deletions app/loadConfig.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

def load_config(file):
with open(file, 'r') as ymlfile:
cfg = yaml.load(ymlfile)
return cfg
cfg = yaml.load(ymlfile, Loader=yaml.FullLoader)
return cfg
2 changes: 1 addition & 1 deletion app/logic/databaseInterface.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from app.allImports import *
from app.models import *

def grab_current_semester():
semesters = Semesters.select()
Expand Down Expand Up @@ -81,7 +82,6 @@ def get_course_instructors(CID):
instructors_string = ''
instructors = UsersCourses.select().where(UsersCourses.CID == CID)
for instructor in instructors:
print instructor.username.username
instructors_string += instructor.username.username
return instructors_string

Expand Down
4 changes: 3 additions & 1 deletion app/logic/excelMaker.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import xlsxwriter
from app.allImports import *
import sys
from app.models import UsersCourses, Courses


def makeExcelFile(SEID):
filename = "bcsr-{}-missing-syllabi.xlsx".format(SEID)
path = getAbsolutePath(cfg['fileOperations']['dataPaths']['tmp'],filename,False)
path = getAbsolutePath(cfg['fileOperations']['dataPaths']['tmp'], filename, False)
workbook = xlsxwriter.Workbook(path)
workbook.set_properties({
'title': 'Missing Syllabi for {}'.format(SEID),
Expand Down
1 change: 1 addition & 0 deletions app/logic/getAuthUser.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'''Any function that is related to user information or authentication should
be located here'''
from app.allImports import *
from app.models import Users

class AuthorizedUser:
def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion app/logic/getCourses.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def check_for_my_courses(self,SEID):
try:
temp_courses = UsersCourses.get(UsersCourses.username == self.username)
my_courses = databaseInterface.grab_my_courses(self.username,SEID)
except DoesNotExist:
except Exception: # Using blanket exception, DoesNotExist no longer exists...
my_courses = None
return my_courses

4 changes: 1 addition & 3 deletions app/logic/getSystemManagement.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from app.allImports import *
from app.logic import databaseInterface
import time
from app.models import Semesters

class GetSystemManagement():
'''Purpose: This class should hold any method directly related to
Expand Down Expand Up @@ -31,7 +32,6 @@ def create_seid(self, data):
@key -year => {string}
@key -term => {integer}
'''
print 'inside create'
year = data['year']
term_key = str(data['term'])
#same year is a list of all term keys that go off the current year,
Expand All @@ -42,8 +42,6 @@ def create_seid(self, data):
seid = year + term_key
else:
seid = str(int(year)-1) + term_key

print "This is the SEID: " + str(seid)
return seid

def add_semester(self, data):
Expand Down
2 changes: 1 addition & 1 deletion app/logic/getUploads.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def check_path_exist(self,path):
os.makedirs(path)
app.logger.info("Directories made: {0}".format(path))
except OSError as e:
print e.errno
print(e.errno)
app.logger.error("Error making directories: {0}".format(e.errno))
pass
return 0
Expand Down
Loading