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

Update python 3 #167

Open
wants to merge 7 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
36 changes: 18 additions & 18 deletions application/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
# Import all of the controllers for your application
from application.controllers import *
from application.config import config
from absolutepath import getAbsolutePath
from application.absolutepath import getAbsolutePath
# from application.models import *

# We need to track session information for using the
# admin console. This is not fully understood yet.
# The admin console does not work without it, though.
import uuid
if config.flask.secretKey in ["UUID", "RANDOM"]:
if config['flask']['secretKey']in ["UUID", "RANDOM"]:
app.secret_key = uuid.uuid4()
else:
app.secret_key = "secretsecretsecret"
Expand All @@ -42,7 +42,7 @@ def index(self):
return redirect("/", code = 302)

admin = admin.Admin(app,
name = config.application.title,
name = config["application"]["title"],
index_view = RoleVerifiedAdminIndexView(),
template_mode = 'bootstrap3')
from application.models import classes
Expand All @@ -56,27 +56,27 @@ def index(self):
# under Apache/Shibboleth
import os
from application.logic.validation import getUsernameFromEnv as gUFE
config.flask.username = gUFE()
config["flask"]["username"] = gUFE()



# This hook ensures that a connection is opened to handle any queries
# generated by the request. Opens every database, which is not ideal,
# but because we don't know which will be used...
@app.before_request
def _db_connect():
for db in config.databases.dynamic:
theDB = config.databases.dynamic[db].theDB
theDB.connect()
# @app.before_request
# def _db_connect():
# for db in config["databases"]["dynamic"]:
# theDB = config["databases"]["dynamic"][db][theDB]
# theDB.connect()

# This hook ensures that the connection is closed when we've finished
# processing the request.
@app.teardown_appcontext
def _db_close(exc):
for db in config.databases.dynamic:
theDB = config.databases.dynamic[db].theDB
if not theDB.is_closed():
theDB.close()
# # This hook ensures that the connection is closed when we've finished
# # processing the request.
# @app.teardown_appcontext
# def _db_close(exc):
# for db in config["databases"]["dynamic"]:
# theDB = config["databases"]["dynamic"][db]
# if not theDB.is_closed():
# theDB.close()


def authUser(env):
Expand All @@ -85,7 +85,7 @@ def authUser(env):
# we need to sanitize the environment variable
# TODO: this looks like a function that can be taken out
return env[envK].split("@")[0].split('/')[-1].lower()
elif ("DEBUG" in config) and config.sys["debug"]:
elif ("DEBUG" in config) and config["sys"]["debug"]:
old_username = config["DEBUG"]["user"]
converted_user = config["DEBUG"]["user"].split('@')[0].split('/')[-1].lower()
#TODO: log
Expand Down
88 changes: 40 additions & 48 deletions application/config.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,44 @@
# See the configure documentation for more about
# this library.
# http://configure.readthedocs.io/en/latest/#
from configure import Configuration
from absolutepath import getAbsolutePath

# The configure library provides a pretty interface to our
# configuration data. This module doesn't do anything other
# than
config_path = getAbsolutePath('config/config.yaml')
config = Configuration.from_file(config_path).configure()

# Added for splitting up Add New Chemical form config from config
chemConfig_path = getAbsolutePath('config/chemicalConfig.yaml')
chemConfig = Configuration.from_file(chemConfig_path).configure()

# Added for add container page
contConfig_path = getAbsolutePath('config/containerConfig.yaml')
contConfig = Configuration.from_file(contConfig_path).configure()

# Added for check in page
checkInConfig_path = getAbsolutePath('config/checkInConfig.yaml')
checkInConfig = Configuration.from_file(checkInConfig_path).configure()

# Added for check out page
checkOutConfig_path = getAbsolutePath('config/OutConfig.yaml')
checkOutConfig = Configuration.from_file(checkOutConfig_path).configure()

#Added for UserAcess page
userConfig_path = getAbsolutePath('config/useraccessConfig.yaml')
userConfig = Configuration.from_file(userConfig_path).configure()

# Added for Manage Location Page
locationConfig_path = getAbsolutePath('config/locationConfig.yaml')
locationConfig = Configuration.from_file(locationConfig_path).configure()

# Populates database with all locations added to locations.yaml
addLocationConfig_path = getAbsolutePath('config/locations.yaml')
addLocationConfig = Configuration.from_file(addLocationConfig_path).configure()

# Populates database with all locations added to reports.yaml
reportConfig_path = getAbsolutePath('config/reports.yaml')
reportConfig = Configuration.from_file(reportConfig_path).configure()

# This adds the application's base directory to the
# configuration object, so that the rest of the application
# can reference it.
import yaml
import os
config.sys.base_dir = os.path.abspath(os.path.dirname(__file__))

# Read and parse the config.yaml file
with open('config/config.yaml', 'r') as f:
config = yaml.safe_load(f)

# Read and parse the chemicalConfig.yaml file
with open('config/chemicalConfig.yaml', 'r') as f:
chemConfig = yaml.safe_load(f)

# Read and parse the containerConfig.yaml file
with open('config/containerConfig.yaml', 'r') as f:
contConfig = yaml.safe_load(f)

# Read and parse the checkInConfig.yaml file
with open('config/checkInConfig.yaml', 'r') as f:
checkInConfig = yaml.safe_load(f)

# Read and parse the OutConfig.yaml file
with open('config/OutConfig.yaml', 'r') as f:
checkOutConfig = yaml.safe_load(f)

# Read and parse the useraccessConfig.yaml file
with open('config/useraccessConfig.yaml', 'r') as f:
userConfig = yaml.safe_load(f)

# Read and parse the locationConfig.yaml file
with open('config/locationConfig.yaml', 'r') as f:
locationConfig = yaml.safe_load(f)

# Read and parse the locations.yaml file
with open('config/locations.yaml', 'r') as f:
addLocationConfig = yaml.safe_load(f)

# Read and parse the reports.yaml file
with open('config/reports.yaml', 'r') as f:
reportConfig = yaml.safe_load(f)

# Add the application's base directory to the config object
config['sys']['base_dir'] = os.path.abspath(os.path.dirname(__file__))

from application import app
from application.customFilters import filters
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/allCont/AddChemicalController.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def AddChemical():
auth = AuthorizedUser()
user = auth.getUser()
userLevel = auth.userLevel()
print user.username, userLevel
print (user.username, userLevel)

if userLevel == "admin" or userLevel == "systemAdmin":
if request.method == "GET":
Expand Down Expand Up @@ -49,5 +49,5 @@ def checkName():
if chemical is not None:
return jsonify({'required':True}) #Build the json dict for a success
except:
print "This should log something..."
print( "This should log something...")
return jsonify({'required':False})
2 changes: 1 addition & 1 deletion application/controllers/allCont/AddUserController.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def AddUser():
userLevel = auth.userLevel()
if userLevel == -1 or user == -1:
abort(403)
print user.username, userLevel
print (user.username, userLevel)
if userLevel == "admin":
if request.method == "POST":
status, flashMessage, flashFormat = createUser(request.form, user.username, True) # createUser function located in usersModel.py
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/allCont/CheckInController.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def CheckIn():
auth = AuthorizedUser()
user = auth.getUser()
userLevel = auth.userLevel()
print user.username, userLevel
print (user.username, userLevel)

if userLevel == "admin" or userLevel == "systemAdmin":
storageList = getStorages()
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/allCont/CheckOutController.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def CheckOut():
auth = AuthorizedUser()
user = auth.getUser()
userLevel = auth.userLevel()
print user.username, userLevel
print (user.username, userLevel)

if userLevel == "admin" or userLevel == "systemAdmin":
storageList = getStorages()
Expand Down
3 changes: 1 addition & 2 deletions application/controllers/allCont/ChemTableController.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def ChemTable():
userLevel = auth.userLevel()
if userLevel == -1 or user == -1:
abort(403)
print user.username, userLevel
print (user.username, userLevel)

contDict = contCount(getChemicals())
containers = getAllDataAboutContainers()
Expand All @@ -29,7 +29,6 @@ def ChemTable():
config = config,
containers = containers,
contDict = contDict,
quote = quote,
authLevel = userLevel)

@app.route("/getEditData/", methods = ['GET']) #AJAX call to get data for edit chemical form
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/allCont/ContainerInfoController.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def maContainerInfo(chemId, barcodeId):
auth = AuthorizedUser()
user = auth.getUser()
userLevel = auth.userLevel()
print user.username, userLevel
print (user.username, userLevel)

if userLevel == "admin" or userLevel == "systemAdmin":
chemical = getChemical(chemId)
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/allCont/HomeController.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def adminHome():
userLevel = auth.userLevel()
if user == -1:
render_template("views/UnathorizedView.html")
print user.username, userLevel
print (user.username, userLevel)

if userLevel == "admin" or userLevel == "systemAdmin":
buildings = getBuildings()
Expand Down Expand Up @@ -60,7 +60,7 @@ def adminHome():
flash(flashMessage, flashFormat)
elif data['location'] == "Storage": #If the form is editing a storage
if data['action'] == 'edit':
print data
print (data)
storage = Storages.get(Storages.sId == data['id']) #Get storage location to be edited and change all information to what was in form
for i in data:
setattr(storage, i, data[i])
Expand Down
6 changes: 3 additions & 3 deletions application/controllers/allCont/ReportController.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def report():
if userLevel == 'admin' or userLevel == 'superUser' or userLevel == 'systemAdmin':
if request.method == "GET":
allBuild = getBuildings()
inputs = [None] * len(reportConfig.ReportTypes.Inputs)
for key in reportConfig.ReportTypes.Inputs:
index = reportConfig.ReportTypes.Inputs[key]
inputs = [None] * len(reportConfig["ReportTypes"]["Inputs"])
for key in reportConfig["ReportTypes"]["Inputs"]:
index = reportConfig["ReportTypes"]["Inputs"][key]
inputs[index] = key
return render_template("views/ReportView.html",
authLevel = userLevel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def RequestUserAccess():
userLevel = auth.userLevel()
if userLevel == -1 or user == -1:
abort(403)
print user.username, userLevel
print (user.username, userLevel)

if request.method == "POST":
status, flashMessage, flashFormat = createUser(request.form, user.username, False)
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/allCont/UserApprovalController.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def UserApproval():
userLevel = auth.userLevel()
if userLevel == -1 or user == -1:
abort(403)
print user.username, userLevel
print (user.username, userLevel)

if userLevel == "admin":
if request.method == "POST":
Expand All @@ -35,7 +35,7 @@ def UserApproval():
flash(flashMessage, flashFormat)
elif 'denyButton' in data:
#TODO: delete users that were denied
print data['denyButton']
print (data['denyButton'])
for user in usersList:
try:
query = Users.delete().where(Users.userId == user)
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/allCont/ViewChemicalController.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def ViewChemical(chemId):
userLevel = auth.userLevel()
if userLevel == -1 or user == -1:
abort(403)
print user.username, userLevel
print (user.username, userLevel)
hazardList = getChemicalHazards(chemId)

try:
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/allCont/ViewUserController.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def ViewUser():
userLevel = auth.userLevel()
if userLevel == -1 or user == -1:
abort(403)
print user.username, userLevel
print (user.username, userLevel)
usersList = Users.select().where(Users.approve == True)
if request.method == "POST":
data = request.form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def maDelete(location, lId):
userLevel = auth.userLevel()
if userLevel == -1 or user == -1:
abort(403)
print user.username, userLevel
print (user.username, userLevel)
if userLevel == "admin":
state = 0
if request.method == "GET": #Calls delete queries based on what type of location is being deleted.
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/allCont/migrateChemController.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def migrateChem():
auth = AuthorizedUser()
user = auth.getUser()
userLevel = auth.userLevel()
print user.username, userLevel
print (user.username, userLevel)

#locdict = Batch.select().dicts().get() This was used for datamodel testing
if userLevel == 'admin' or userLevel == "systemAdmin":
Expand Down Expand Up @@ -81,7 +81,7 @@ def renderCorrectTemplate(barcode):
#Try and Retrieve Container and Chemical Informatoin from CISPro
if state != MIGRATED:
containerObj = getCisProContainer(inputBar)
print containerObj
print (containerObj)
if containerObj == False:
flash("Container " + inputBar + " Is Not In CISPro Database", "list-group-item list-group-item-danger")
state = UNKNOWN
Expand Down
2 changes: 1 addition & 1 deletion application/customFilters/filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime

def formatDateTime(value, format="%m-%d-%Y"):
print type(value)
print (type(value))
return value.strftime(format)
# return datetime.datetime.strptime(value, "%Y-%m-%d %H:%M:%S.%f")
4 changes: 2 additions & 2 deletions application/logic/\
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def genLocationReport(loc_id):
"""
Returns a file of all chemicals and containers in a location
"""
print loc_id
print (loc_id)
#for cont in getChemInStor(loc_id):
# print cont.chemId.name
#for cont in getChemInRoom(loc_id):
Expand All @@ -26,7 +26,7 @@ def genLocationReport(loc_id):
#for cont in getChemInBuild(loc_id):
# print cont.barcodeId
for cont in getIBFlamLiquids():
print cont.barcodeId
print (cont.barcodeId)
return 0

def genHazardReport(building):
Expand Down
11 changes: 6 additions & 5 deletions application/logic/genBarcode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import date

def genBarcode(lstBcode):

"""Takes a barcode and creates and returns the next one
Input: Str in the form '16100024'
Output: Str in the form '16100025"""
Expand All @@ -9,15 +10,15 @@ def genBarcode(lstBcode):

if len(month) < 2:
#if month is less then 10 add a 0 to the front to make it match in len
month = '0' + month
month = '0' + month

if lstBcode[0:2] == year: #If the last barcode was made in current year
#The year is correct
if lstBcode[2:4] == month: #If the last barcode was made in current month
#The month is also correct so we increment the count
newbar = year + month + increment(lstBcode[4:8])
if lstBcode[2:4] == month: #If the last barcode was made in current month
#The month is also correct so we increment the count
newbar = year + month + increment(lstBcode[4:8])
else:
newbar = year + month + "0000"
newbar = year + month + "0000"
else:
newbar = year + month +"0000"
return newbar
Expand Down
Loading