-
Notifications
You must be signed in to change notification settings - Fork 8
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
Refactor Program Management section of Admin Settings #1281
base: development
Are you sure you want to change the base?
Changes from all commits
f850ec3
d5fe95d
ebf80d2
0053012
874a913
d1f035a
230ee45
decdb3d
19c1b2c
be36260
a7eb026
e40eb96
19040fd
4702612
f8a6a2a
14b3eca
4089296
7f27709
abc75f0
7f472f9
7067204
ddcae6f
f1280c6
8545c4e
52d56ab
04c7f87
4a663bd
16407d5
0399f4b
3f99551
7f219b5
d631b1f
2aaf254
bfe21fe
2aaf332
6a7af85
91d55b6
a1ca894
cdbc950
e1ff16b
38fbf19
9831544
f4a42d6
dca0ec5
5ce9768
bd5bed9
adc1087
57fee5b
b58673b
f092bba
57da6e1
7d7fb9a
002d470
eea8a51
fd01a4b
8469369
b951929
2cee41f
9b4f88a
0ef65d2
b2cc118
0e722f3
6fec1f8
32ea25b
ad19716
88deb54
41c076f
e748af3
b0e8f7c
b7e9ebe
0532b1f
bc63549
29a569a
bec01f7
0946087
d24650d
63c0521
dddf311
eab7d05
9e3015d
d62dcf9
75678ae
e157b91
d619cb4
ea32a18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
from app.logic.userManagement import changeProgramInfo | ||
from app.logic.utils import selectSurroundingTerms | ||
from app.logic.term import addNextTerm, changeCurrentTerm | ||
from app.logic.fileHandler import FileHandler | ||
from app.models.attachmentUpload import AttachmentUpload | ||
|
||
@admin_bp.route('/admin/manageUsers', methods = ['POST']) | ||
def manageUsers(): | ||
|
@@ -48,43 +50,32 @@ def manageUsers(): | |
flash(user.firstName + " " + user.lastName + " is no longer a CELTS Student Staff", 'success') | ||
return ("success") | ||
|
||
@admin_bp.route('/addProgramManagers', methods=['POST']) | ||
def addProgramManagers(): | ||
eventData = request.form | ||
try: | ||
return addProgramManager(eventData['username'],int(eventData['programID'])) | ||
except Exception as e: | ||
print(e) | ||
flash('Error while trying to add a manager.','warning') | ||
abort(500,"'Error while trying to add a manager.'") | ||
|
||
@admin_bp.route('/removeProgramManagers', methods=['POST']) | ||
def removeProgramManagers(): | ||
eventData = request.form | ||
try: | ||
return removeProgramManager(eventData['username'],int(eventData['programID'])) | ||
except Exception as e: | ||
print(e) | ||
flash('Error while removing a manager.','warning') | ||
abort(500,"Error while trying to remove a manager.") | ||
@admin_bp.route('/deleteProgramFile', methods=['POST']) | ||
def deleteProgramFile(): | ||
programFile=FileHandler(programId=request.form["programID"]) | ||
programFile.deleteFile(request.form["fileId"]) | ||
return "" | ||
|
||
@admin_bp.route('/admin/updateProgramInfo/<programID>', methods=['POST']) | ||
def updateProgramInfo(programID): | ||
"""Grabs info and then outputs it to logic function""" | ||
programInfo = request.form # grabs user inputs | ||
if g.current_user.isCeltsAdmin: | ||
try: | ||
changeProgramInfo(programInfo["programName"], #calls logic function to add data to database | ||
programInfo["contactEmail"], | ||
programInfo["contactName"], | ||
programInfo["location"], | ||
programID) | ||
programInfo = request.form # grabs user inputs | ||
uploadedFile = request.files.get('modalProgramImage') | ||
changeProgramInfo(programID, uploadedFile, **programInfo) | ||
|
||
associatedAttachments = list(AttachmentUpload.select().where(AttachmentUpload.program == programID).execute()) | ||
|
||
filePaths = FileHandler(programId=programID).retrievePath(associatedAttachments) | ||
|
||
|
||
file_paths = {filename: path_info[0] for filename, path_info in filePaths.items()} | ||
flash("Program updated", "success") | ||
return redirect(url_for("admin.userManagement", accordion="program")) | ||
except Exception as e: | ||
print(e) | ||
flash('Error while updating program info.','warning') | ||
print("error: ", e) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get rid of the ``"print("error: ", e)" `we don't need it. |
||
flash('Error while updating program info.','warning') | ||
abort(500,'Error while updating program.') | ||
abort(403) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,25 @@ | |
from flask import redirect, url_for | ||
from app import app | ||
from app.models.attachmentUpload import AttachmentUpload | ||
from app.models.program import Program | ||
import glob | ||
|
||
class FileHandler: | ||
def __init__(self, files=None, courseId=None, eventId=None): | ||
self.files = files | ||
self.path = app.config['files']['base_path'] | ||
def __init__(self, files=None, courseId=None, eventId=None, programId=None): | ||
self.files = files | ||
if not isinstance(self.files, list): | ||
self.files = [self.files] | ||
self.path = app.config['files']['base_path'] | ||
self.courseId = courseId | ||
self.eventId = eventId | ||
self.programId = programId | ||
if courseId: | ||
self.path = os.path.join(self.path, app.config['files']['course_attachment_path'], str(courseId)) | ||
elif eventId: | ||
self.path = os.path.join(self.path, app.config['files']['event_attachment_path']) | ||
|
||
elif programId: | ||
self.path = os.path.join(self.path, app.config['files']['program_attachment_path']) | ||
|
||
def makeDirectory(self): | ||
try: | ||
extraDir = str(self.eventId) if self.eventId else "" | ||
|
@@ -25,17 +32,19 @@ def makeDirectory(self): | |
|
||
def getFileFullPath(self, newfilename=''): | ||
try: | ||
filePath = (os.path.join(self.path, newfilename)) | ||
if self.eventId or self.courseId or self.programId: | ||
filePath = (os.path.join(self.path, newfilename)) | ||
Kafui123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
except AttributeError: | ||
pass | ||
except FileExistsError: | ||
pass | ||
return filePath | ||
|
||
def saveFiles(self, saveOriginalFile=None): | ||
try: | ||
try: | ||
for file in self.files: | ||
saveFileToFilesystem = None | ||
|
||
if self.eventId: | ||
attachmentName = str(saveOriginalFile.id) + "/" + file.filename | ||
isFileInEvent = AttachmentUpload.select().where(AttachmentUpload.event_id == self.eventId, | ||
|
@@ -49,11 +58,27 @@ def saveFiles(self, saveOriginalFile=None): | |
if not isFileInCourse: | ||
AttachmentUpload.create(course=self.courseId, fileName=file.filename) | ||
saveFileToFilesystem = file.filename | ||
elif self.programId: | ||
|
||
Kafui123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# remove the existing file | ||
deleteFileObject = AttachmentUpload.get_or_none(program=self.programId) | ||
if deleteFileObject: | ||
self.deleteFile(deleteFileObject.id) | ||
|
||
# add the new file | ||
fileType = file.filename.split('.')[-1] | ||
fileName = f"{self.programId}.{fileType}" | ||
AttachmentUpload.create(program=self.programId, fileName=fileName) | ||
current_programID = fileName | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be camelCase |
||
saveFileToFilesystem = current_programID | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think using snake_case for variable naming is better. |
||
else: | ||
saveFileToFilesystem = file.filename | ||
|
||
if saveFileToFilesystem: | ||
self.makeDirectory() | ||
file.save(self.getFileFullPath(newfilename=saveFileToFilesystem)) | ||
|
||
except AttributeError: | ||
pass | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
from app.models import* | ||
from app.models.event import Event | ||
from app.models.course import Course | ||
from app.models.program import Program | ||
from app.models.otherExperience import OtherExperience | ||
|
||
|
||
class AttachmentUpload(baseModel): | ||
event = ForeignKeyField(Event, null=True) | ||
course = ForeignKeyField(Course, null=True) | ||
program = ForeignKeyField(Program, null=True) | ||
isDisplayed = BooleanField(default=False) | ||
fileName = CharField() | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
|
||
.toast-container{ | ||
top: 0; | ||
z-index: 11; | ||
z-index: 1060; | ||
} | ||
|
||
.form-control.invalid, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.modal { | ||
position: fixed; | ||
left: 50%; | ||
top: 50%; | ||
transform: translate(-50%, -50%); | ||
/* Removed incorrect translate */ | ||
} | ||
|
||
.modal-dialog-scrollable { | ||
max-height: calc(100vh - 200px); | ||
overflow-y: auto; | ||
} | ||
|
||
|
||
.info { | ||
overflow-y: auto; | ||
margin-top: -20px; | ||
} | ||
|
||
.cellSpacing { | ||
margin: 5px; | ||
padding: 10px; | ||
} | ||
|
||
.programHeader { | ||
border-bottom: 1px solid black; | ||
font-weight: bold; | ||
} | ||
|
||
.borderless { | ||
border: 0; | ||
} | ||
|
||
.rightJustify { | ||
position: absolute; | ||
right: 10px; /* Added px to right */ | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,7 +158,7 @@ function getSelectedFiles(){ | |
return _fileHolder.files; | ||
} | ||
|
||
function handleFileSelection(fileInputId){ | ||
function handleFileSelection(fileInputId, single=false){ | ||
var fileBoxId = "#" + fileInputId | ||
var attachedObjectContainerId = fileInputId + "Container" | ||
$(fileBoxId).after(`<div id="`+attachedObjectContainerId+`" class="py-0 px-0"></div>`) | ||
|
@@ -191,16 +191,22 @@ function handleFileSelection(fileInputId){ | |
} | ||
let trashNum = ($(objectContainerId+ " .row").length) | ||
var fullTrashId = "#trash" + trashNum | ||
$(objectContainerId).append(" \ | ||
<div class='border row p-0 m-0' id='attachedFilesRow" +trashNum+"'> \ | ||
<i class='col-auto fs-3 px-3 bi " + iconClass + "'></i> \ | ||
<div id='attachedFile" + trashNum + "' data-filename='" + file.name + "' class='fileName col-auto pt-2'>" + fileName + "</div> \ | ||
<div class='col' style='text-align:right'> \ | ||
<div class='btn btn-danger fileHolder p-1 my-1 mx-1' id='trash" + trashNum + "' data-filenum='" + trashNum + "'>\ | ||
<span class='bi bi-trash fs-6'></span>\ | ||
</div>\ | ||
</div> \ | ||
</div>") | ||
let fileHTML = " \ | ||
<div class='border row p-0 m-0' id='attachedFilesRow" +trashNum+"'> \ | ||
<i class='col-auto fs-3 px-3 bi " + iconClass + "'></i> \ | ||
<div id='attachedFile" + trashNum + "' data-filename='" + file.name + "' class='fileName col-auto pt-2'>" + fileName + "</div> \ | ||
<div class='col' style='text-align:right'> \ | ||
<div class='btn btn-danger fileHolder p-1 my-1 mx-1' id='trash" + trashNum + "' data-filenum='" + trashNum + "'>\ | ||
<span class='bi bi-trash fs-6'></span>\ | ||
</div>\ | ||
</div> \ | ||
</div>" | ||
if (single) { | ||
$(objectContainerId).html(fileHTML) | ||
} | ||
else { | ||
$(objectContainerId).append(fileHTML) | ||
} | ||
$(fullTrashId).data("file", file); | ||
$(fullTrashId).data("file-container-id", attachedObjectContainerId); | ||
$(fullTrashId).on("click", function() { | ||
|
@@ -212,7 +218,12 @@ function handleFileSelection(fileInputId){ | |
$(fileBoxId).data("file-num", $(fileBoxId).data("file-num") + 1) | ||
} | ||
else{ | ||
if (single){ | ||
$(objectContainerId).html(fileHTML) | ||
} | ||
else{ | ||
msgToast("File with filename '" + file.name + "' has already been added to this event") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation |
||
} | ||
} | ||
} | ||
$(fileBoxId).prop('files', getSelectedFiles()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
"filePaths"
variable and the"file_paths"
variable should be both camelcase. The also should have different variable names.