Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
jalex0823 committed Nov 10, 2023
1 parent 197eccc commit bc12966
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import traceback
from flask_sqlalchemy import SQLAlchemy
import werkzeug.exceptions

app = Flask(__name__, static_folder='static')
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('SQLALCHEMY_DATABASE_URI')
Expand All @@ -26,28 +27,30 @@ class ITPersonnel(db.Model):

@app.route('/')
def home():
try:
personnel = ITPersonnel.query.all()
departments = ITDepartments.query.all()
return render_template('index.html', personnel=personnel, departments=departments)
except Exception as e:
app.logger.error(f"Error occurred: {e}\n{traceback.format_exc()}")
return "An error occurred", 500
personnel = ITPersonnel.query.all()
departments = ITDepartments.query.all()
return render_template('index.html', personnel=personnel, departments=departments)

@app.route('/assign-rights', methods=['POST'])
def assign_rights():
try:
for key, value in request.form.items():
if key.startswith('privileges_'):
last_name = key[len('privileges_'):]
personnel = ITPersonnel.query.get(last_name)
if personnel:
personnel.Database_Privileges = value
db.session.commit()
return 'Rights assigned successfully'
except Exception as e:
app.logger.error(f"Error occurred: {e}\n{traceback.format_exc()}")
return f"An error occurred: {str(e)}", 500
for key, value in request.form.items():
if key.startswith('privileges_'):
last_name = key[len('privileges_'):]
personnel = ITPersonnel.query.get(last_name)
if personnel:
personnel.Database_Privileges = value
db.session.commit()
return 'Rights assigned successfully'

@app.errorhandler(Exception)
def handle_exception(e):
# pass through HTTP errors
if isinstance(e, werkzeug.exceptions.HTTPException):
return e

# now you're handling non-HTTP exceptions only
app.logger.error(f"Error occurred: {e}\n{traceback.format_exc()}")
return "An error occurred", 500

if __name__ == '__main__':
app.debug = True
Expand Down

0 comments on commit bc12966

Please sign in to comment.