diff --git a/app/config/default.yml b/app/config/default.yml index 9734f7efe..4b2dcc73f 100644 --- a/app/config/default.yml +++ b/app/config/default.yml @@ -25,6 +25,8 @@ ldap: files: base_path: 'app/static/files' + image_path: 'app/static/images' + program_attachment_path: 'programattachments' email_attachment_path: 'emailattachments' event_attachment_path: 'eventattachments' course_attachment_path: 'courseattachments' diff --git a/app/controllers/admin/userManagement.py b/app/controllers/admin/userManagement.py index 80239f5fd..ee0e316cf 100644 --- a/app/controllers/admin/userManagement.py +++ b/app/controllers/admin/userManagement.py @@ -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,25 @@ 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/', 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) 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') + flash('Error while updating program info.','warning') abort(500,'Error while updating program.') abort(403) diff --git a/app/logic/fileHandler.py b/app/logic/fileHandler.py index 18746e78e..3fb7636a8 100644 --- a/app/logic/fileHandler.py +++ b/app/logic/fileHandler.py @@ -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,7 +32,8 @@ 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)) except AttributeError: pass except FileExistsError: @@ -33,9 +41,10 @@ def getFileFullPath(self, newfilename=''): 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: + + # 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) + currentProgramID = fileName + saveFileToFilesystem = currentProgramID + else: saveFileToFilesystem = file.filename + if saveFileToFilesystem: self.makeDirectory() file.save(self.getFileFullPath(newfilename=saveFileToFilesystem)) + except AttributeError: pass diff --git a/app/logic/landingPage.py b/app/logic/landingPage.py index a2d49d3ac..2def7672a 100644 --- a/app/logic/landingPage.py +++ b/app/logic/landingPage.py @@ -19,10 +19,10 @@ def getManagerProgramDict(user): for program in programs: managerProgramDict[program] = {"managers": "", "image": os.path.join('static', 'images/logos/celts_symbol.png')} - with os.scandir("./app/static/images/landingPage") as it: + with os.scandir("./app/static/files/programattachments") as it: for entry in it: - if entry.name.split('.')[0] == f'{program.programName}': - managerProgramDict[program]["image"] = os.path.join('static', f'images/landingPage/{entry.name}') + if entry.name.split('.')[0] == f'{program.id}': + managerProgramDict[program]["image"] = os.path.join('static', f'files/programattachments/{entry.name}') break for row in managerRows: if managerProgramDict[row.program]["managers"] == "": diff --git a/app/logic/userManagement.py b/app/logic/userManagement.py index 9f66e940c..b075ce90e 100644 --- a/app/logic/userManagement.py +++ b/app/logic/userManagement.py @@ -3,9 +3,11 @@ from app.models.programManager import ProgramManager from app.models.program import Program from app.models.eventTemplate import EventTemplate +from app.models.attachmentUpload import AttachmentUpload from flask import g, session from app.logic.createLogs import createActivityLog from playhouse.shortcuts import model_to_dict +from app.logic.fileHandler import FileHandler def addCeltsAdmin(user): user = User.get_by_id(user) @@ -38,20 +40,52 @@ def removeCeltsStudentStaff(user): createActivityLog(f'Removed {user.firstName} {user.lastName} from a CELTS student staff member'+ (f', and as a manager of {programManagerRoles}.' if programManagerRoles else ".")) +def changeProgramInfo(programId, + attachment, + programName= None, + programDescription = None, + partner = None, + contactEmail=None, + contactName= None, + location = None, + instagramUrl = None, + facebookUrl = None, + bereaUrl = None): + -def changeProgramInfo(newProgramName, newContactEmail, newContactName, newLocation, programId): - """Updates the program info with a new sender and email.""" + """Updates the program info and logs that change""" program = Program.get_by_id(programId) - updatedProgram = Program.update({Program.programName:newProgramName, Program.contactEmail: newContactEmail, Program.contactName:newContactName, Program.defaultLocation:newLocation}).where(Program.id==programId) + if attachment: + addFile: FileHandler = FileHandler(attachment, programId=programId) + addFile.saveFiles() + updatedProgram = Program.update( + { Program.programName:programName, + Program.programDescription: programDescription, + Program.partner: partner, + Program.contactEmail: contactEmail, + Program.contactName: contactName, + Program.defaultLocation: location, + Program.instagramUrl:instagramUrl, + Program.facebookUrl: facebookUrl, + Program.bereaUrl: bereaUrl + } + ).where(Program.id==programId) updatedProgram.execute() - if newProgramName != program.programName: - createActivityLog(f"{program.programName} Program Name was changed to: {newProgramName}") - if newContactEmail != program.contactEmail: - createActivityLog(f"{program.programName} Contact Email was changed to: {newContactEmail}") - if newContactName != program.contactName: - createActivityLog(f"{program.programName} Contact Name was changed to: {newContactName}") - if newLocation != program.defaultLocation: - createActivityLog(f"{program.programName} Location was changed to: {newLocation}") + + + if programName != program.programName: + createActivityLog(f"{program.programName} Program Name was changed to: {programName}") + if programDescription != program.programDescription: + createActivityLog(f"{program.programName} Description was changed to: {programDescription}") + if partner != program.partner: + createActivityLog(f"{program.programName} Program Partner was changed to: {partner}") + if contactEmail != program.contactEmail: + createActivityLog(f"{program.programName} Contact Email was changed to: {contactEmail}") + if contactName != program.contactName: + createActivityLog(f"{program.programName} Contact Name was changed to: {contactName}") + if location != program.defaultLocation: + createActivityLog(f"{program.programName} Location was changed to: {location}") + return (f'Program email info updated') @@ -69,4 +103,4 @@ def getAllowedTemplates(currentUser): if currentUser.isCeltsAdmin: return EventTemplate.select().where(EventTemplate.isVisible==True).order_by(EventTemplate.name) else: - return [] \ No newline at end of file + return [] diff --git a/app/models/attachmentUpload.py b/app/models/attachmentUpload.py index bf71c9e46..e8b1e8b09 100644 --- a/app/models/attachmentUpload.py +++ b/app/models/attachmentUpload.py @@ -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() diff --git a/app/models/partner.py b/app/models/partner.py deleted file mode 100644 index ba93c6c34..000000000 --- a/app/models/partner.py +++ /dev/null @@ -1,4 +0,0 @@ -from app.models import* - -class Partner(baseModel): - partnerName = CharField() diff --git a/app/models/program.py b/app/models/program.py index 89f692512..0a2f33b11 100644 --- a/app/models/program.py +++ b/app/models/program.py @@ -1,7 +1,6 @@ from app.models import* from app.models.term import Term from app.models.courseStatus import CourseStatus -from app.models.partner import Partner class Program(baseModel): programName = CharField() @@ -9,7 +8,7 @@ class Program(baseModel): facebookUrl = TextField(null=True) bereaUrl = TextField(null=True) programDescription = TextField() - partner = ForeignKeyField(Partner, null=True) + partner = CharField(null=True) isStudentLed = BooleanField(default=False) isBonnerScholars = BooleanField(default=False) isOtherCeltsSponsored = BooleanField(default=False) diff --git a/app/static/css/base.css b/app/static/css/base.css index f8992eaac..fbb24c615 100644 --- a/app/static/css/base.css +++ b/app/static/css/base.css @@ -17,7 +17,7 @@ .toast-container{ top: 0; - z-index: 11; + z-index: 1060; } .form-control.invalid, diff --git a/app/static/css/programManagement.css b/app/static/css/programManagement.css new file mode 100644 index 000000000..7a8717b6e --- /dev/null +++ b/app/static/css/programManagement.css @@ -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 */ +} + diff --git a/app/static/files/programattachments/1.jpg b/app/static/files/programattachments/1.jpg new file mode 100644 index 000000000..fdf327229 Binary files /dev/null and b/app/static/files/programattachments/1.jpg differ diff --git a/app/static/files/programattachments/10.jpg b/app/static/files/programattachments/10.jpg new file mode 100644 index 000000000..fd4257a27 Binary files /dev/null and b/app/static/files/programattachments/10.jpg differ diff --git a/app/static/images/landingPage/Berea Buddies.jpg b/app/static/files/programattachments/2.jpg similarity index 100% rename from app/static/images/landingPage/Berea Buddies.jpg rename to app/static/files/programattachments/2.jpg diff --git a/app/static/images/landingPage/Adopt-a-Grandparent.jpg b/app/static/files/programattachments/3.jpg similarity index 100% rename from app/static/images/landingPage/Adopt-a-Grandparent.jpg rename to app/static/files/programattachments/3.jpg diff --git a/app/static/files/programattachments/4.jpeg b/app/static/files/programattachments/4.jpeg new file mode 100644 index 000000000..20e6f05e4 Binary files /dev/null and b/app/static/files/programattachments/4.jpeg differ diff --git a/app/static/files/programattachments/5.jpg b/app/static/files/programattachments/5.jpg new file mode 100644 index 000000000..063dbb7b2 Binary files /dev/null and b/app/static/files/programattachments/5.jpg differ diff --git a/app/static/files/programattachments/6.jpg b/app/static/files/programattachments/6.jpg new file mode 100644 index 000000000..f836397c3 Binary files /dev/null and b/app/static/files/programattachments/6.jpg differ diff --git a/app/static/files/programattachments/7.jpeg b/app/static/files/programattachments/7.jpeg new file mode 100644 index 000000000..59fdc0bb6 Binary files /dev/null and b/app/static/files/programattachments/7.jpeg differ diff --git a/app/static/files/programattachments/8.jpeg b/app/static/files/programattachments/8.jpeg new file mode 100644 index 000000000..6c7d1c447 Binary files /dev/null and b/app/static/files/programattachments/8.jpeg differ diff --git a/app/static/images/landingPage/Berea Teen Mentoringg.jpeg b/app/static/images/landingPage/Berea Teen Mentoringg.jpeg new file mode 100644 index 000000000..59fdc0bb6 Binary files /dev/null and b/app/static/images/landingPage/Berea Teen Mentoringg.jpeg differ diff --git a/app/static/js/base.js b/app/static/js/base.js index 5aa7c39af..2f7cba327 100644 --- a/app/static/js/base.js +++ b/app/static/js/base.js @@ -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(`
`) @@ -191,16 +191,22 @@ function handleFileSelection(fileInputId){ } let trashNum = ($(objectContainerId+ " .row").length) var fullTrashId = "#trash" + trashNum - $(objectContainerId).append(" \ -
\ - \ -
" + fileName + "
\ -
\ -
\ - \ -
\ -
\ -
") + let fileHTML = " \ +
\ + \ +
" + fileName + "
\ +
\ +
\ + \ +
\ +
\ +
" + 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{ - msgToast("File with filename '" + file.name + "' has already been added to this event") + if (single){ + $(objectContainerId).html(fileHTML) + } + else{ + msgToast("File with filename '" + file.name + "' has already been added to this event") + } } } $(fileBoxId).prop('files', getSelectedFiles()); diff --git a/app/static/js/displayFilesMacro.js b/app/static/js/displayFilesMacro.js index 49c04951c..070f9b59b 100644 --- a/app/static/js/displayFilesMacro.js +++ b/app/static/js/displayFilesMacro.js @@ -1,7 +1,8 @@ $(document).ready(function(){ $("a.fileName").tooltip(); - $(".removeAttachment").on("click", function(){ + $(".removeAttachment").on("click", function(e){ + e.preventDefault(); let fileId = $(this).data("id"); let deleteLink = $(this).data("delete-url"); let fileData = { diff --git a/app/static/js/userManagement.js b/app/static/js/userManagement.js index aeee1312d..02a924e9f 100644 --- a/app/static/js/userManagement.js +++ b/app/static/js/userManagement.js @@ -43,6 +43,28 @@ $(document).ready(function(){ $(".term-btn").on("click", function(){ submitTerm(); }); + $('[data-bs-toggle="modal"]').on('click', function() { + // Get the JSON data from the data-programinfo attribute + const programInfo = JSON.parse($(this).attr('data-programinfo')); + // Directly populate modal fields + $("#programName").val(programInfo.programName); + $("#programDescription").val(programInfo.programDescription); + $("#partner").val(programInfo.partner); + $("#contactEmail").val(programInfo.contactEmail); + $("#contactName").val(programInfo.contactName); + $("#location").val(programInfo.location); + $("#programid").val(programInfo.programid) + $("#instagramUrl").val(programInfo.instagramUrl); + $("#facebookUrl").val(programInfo.facebookUrl); + $("#bereaUrl").val(programInfo.bereaUrl); + $('#modalProgramImage').val(''); + $('#modalProgramImageContainer').html(''); + + handleFileSelection('modalProgramImage', true); + // Update the form action URL dynamically + let updateForm = $('#updateProgramForm'); + updateForm.attr('action', "/admin/updateProgramInfo/" + programInfo.programid); + }); }); function submitRequest(method, username){ let data = { diff --git a/app/templates/admin/userManagement.html b/app/templates/admin/userManagement.html index f196df1c5..9926a69ef 100644 --- a/app/templates/admin/userManagement.html +++ b/app/templates/admin/userManagement.html @@ -4,6 +4,14 @@ {% block scripts %} {{super()}} + + +{% endblock %} + +{% block styles %} + {{super()}} + + {% endblock %} {% block app_content %} @@ -14,7 +22,6 @@ {% endmacro %} -

Admin Management

@@ -117,33 +124,123 @@

{% set focus = "open" if visibleAccordion == "program" else "collapsed" %} -

- {% set show = "show" if visibleAccordion == "program" else "" %} -
-
- - - - - - - - {% for program in programs %} - - - - - - - - - - {% endfor %} -
Program NameContact EmailContact NameLocation
+ + + {% set show = "show" if visibleAccordion == "program" else "" %} +
+
+
+
+
Programs
+
+ + {% for program in programs %} +
+
+ {{ program.programName }} +
+
+ +
+
+ {% endfor %} +
-
+ + + + -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/database/migrate_db.sh b/database/migrate_db.sh index 344d5a1c3..7a4804a03 100755 --- a/database/migrate_db.sh +++ b/database/migrate_db.sh @@ -43,7 +43,7 @@ pem add app.models.eventTemplate.EventTemplate pem add app.models.eventParticipant.EventParticipant pem add app.models.interest.Interest pem add app.models.note.Note -pem add app.models.partner.Partner +# pem add app.models.partner.Partner pem add app.models.program.Program pem add app.models.user.User pem add app.models.programBan.ProgramBan diff --git a/database/oneOff/insert-program-attachments.sql b/database/oneOff/insert-program-attachments.sql new file mode 100644 index 000000000..9876e91c1 --- /dev/null +++ b/database/oneOff/insert-program-attachments.sql @@ -0,0 +1,12 @@ +INSERT INTO attachmentupload + (event_id, course_id, program_id, isDisplayed, fileName) +VALUES + (null, null, 1, FALSE, '1.jpg'), + (null, null, 2, FALSE, '2.jpg'), + (null, null, 3, FALSE, '3.jpg'), + (null, null, 4, FALSE, '4.jpeg'), + (null, null, 5, FALSE, '5.jpg'), + (null, null, 6, FALSE, '6.jpg'), + (null, null, 7, FALSE, '7.jpeg'), + (null, null, 8, FALSE, '8.jpeg'), + (null, null, 10, FALSE, '10.jpg') diff --git a/database/test_data.py b/database/test_data.py index 24a09370e..b182858cf 100644 --- a/database/test_data.py +++ b/database/test_data.py @@ -428,11 +428,12 @@ "facebookUrl": None, "bereaUrl": None, "programDescription": "Each year 200 people stand in line to get into Woods-Penniman for the Annual Empty Bowls Event sponsored by the Berea College ceramics students and CELTS. Students, faculty, staff and community members each pay $10 for a beautiful bowl, soup and the privilege of helping those in need in our community.", + "partner": None, "isStudentLed": False, "isBonnerScholars": False, "isOtherCeltsSponsored": False, "contactEmail": "", - "contactName": "" + "contactName": "", }, { "id": 2, @@ -441,11 +442,12 @@ "facebookUrl": "https://www.facebook.com/BereaBuddies", "bereaUrl": "https://www.berea.edu/centers/center-for-excellence-in-learning-through-service/programs/berea-buddies", "programDescription": "The Berea Buddies program is dedicated to establishing long-term mentorships between Berea youth (Little Buddies) and Berea College students (Big Buddies). Volunteers serve children by offering them friendship and quality time. Big and Little Buddies meet each other every Monday or Tuesday during the academic year, except on school and national holidays, to enjoy structured activities around campus.", + "partner": None, "isStudentLed": True, "isBonnerScholars": False, "isOtherCeltsSponsored": False, "contactEmail": "bereabuddies@berea.edu", - "contactName": "" + "contactName": "", }, { @@ -455,11 +457,12 @@ "facebookUrl": "https://www.facebook.com/profile.php?id=100085958053273", "bereaUrl": "https://www.berea.edu/centers/center-for-excellence-in-learning-through-service/programs/adopt-a-grandparent", "programDescription": "Adopt-a-Grandparent (AGP) is an outreach program for Berea elders. The program matches college student volunteers with residents of local long-term care centers. Volunteers visit with residents for at least an hour per week, and participate in special monthly programs.", + "partner": None, "isStudentLed": True, "isBonnerScholars": False, "isOtherCeltsSponsored": False, "contactEmail": "", - "contactName": "" + "contactName": "", }, { "id": 4, @@ -468,11 +471,12 @@ "facebookUrl": "https://www.facebook.com/peoplewhocareBC", "bereaUrl": "https://www.berea.edu/centers/center-for-excellence-in-learning-through-service/programs/people-who-care-program", "programDescription":"People Who Care (PWC) helps to connect Berea College students with organizations and opportunities that promote change through advocacy, education, action, and direct community service. Volunteers may serve at local shelters, work with the Fair Trade University Campaign, or help to raise awareness about local issues like domestic violence, homelessness, fair trade, and AIDS awareness education. Students are welcome to participate as volunteers in PWC’s projects.", + "partner": None, "isStudentLed": True, "isBonnerScholars": False, "isOtherCeltsSponsored": False, "contactEmail": "", - "contactName": "" + "contactName": "", }, { "id": 5, @@ -481,11 +485,12 @@ "facebookUrl": None, "bereaUrl": "https://www.berea.edu/centers/center-for-excellence-in-learning-through-service/bonner-scholars-program", "programDescription": "The Bonner Scholars Program is a unique opportunity for students who want to combine a strong commitment to service with personal growth, teamwork, leadership development, and scholarship. Students who have completed an application for the Berea College class of 2026 may apply to be a Bonner Scholar.", + "partner": None, "isStudentLed": False, "isBonnerScholars": True, "isOtherCeltsSponsored": False, "contactEmail": "", - "contactName": "" + "contactName": "", }, { "id": 6, @@ -494,11 +499,12 @@ "facebookUrl": "https://www.facebook.com/profile.php?id=100068874352425", "bereaUrl": "https://www.berea.edu/centers/center-for-excellence-in-learning-through-service/programs/habitat-for-humanity", "programDescription": "Through the work of Habitat for Humanity International, thousands of low-income families have found hope through affordable housing. Hard work and volunteering have resulted in the organization sheltering more than two million people worldwide.", + "partner": None, "isStudentLed": True, "isBonnerScholars": False, "isOtherCeltsSponsored": False, "contactEmail": "", - "contactName": "" + "contactName": "", }, { "id": 7, @@ -507,11 +513,12 @@ "facebookUrl": "https://www.facebook.com/BereaTeenMentoring", "bereaUrl": "https://www.berea.edu/centers/center-for-excellence-in-learning-through-service/programs/berea-teen-mentoring", "programDescription": "Berea Teen Mentoring (BTM) brings Berea community youth, from ages 13-18, into a group setting for mentorship and enrichment programs. Staff members are assisted during the weekly program by Berea College student volunteers, who act as mentors for these program participants. The mission of the program is to stimulate and cultivate personal growth for young adults in the Berea community.", + "partner": None, "isStudentLed": True, "isBonnerScholars": False, "isOtherCeltsSponsored": False, "contactEmail": "", - "contactName": "" + "contactName": "", }, { "id": 8, @@ -520,11 +527,12 @@ "facebookUrl": "https://www.facebook.com/HOPBerea", "bereaUrl": "https://www.berea.edu/centers/center-for-excellence-in-learning-through-service/programs/hispanic-outreach-program", "programDescription": "The Hispanic Outreach Program (HOP) is a service-learning effort which brings together CELTS, several community organizations, and the Department of Foreign Languages at Berea College. HOP aims to build bridges among the Spanish-speaking and English-speaking residents of Madison County.", + "partner": None, "isStudentLed": True, "isBonnerScholars": False, "isOtherCeltsSponsored": False, "contactEmail": "", - "contactName": "" + "contactName": "", }, { "id": 9, @@ -533,11 +541,12 @@ "facebookUrl": "https://www.facebook.com/BereaCollegeCELTS", "bereaUrl": "https://www.berea.edu/centers/center-for-excellence-in-learning-through-service", "programDescription": "This program hosts a myriad of different celts sponsored events that are not owned by any other program.", + "partner": None, "isStudentLed": False, "isBonnerScholars": False, "isOtherCeltsSponsored": True, "contactEmail": "", - "contactName": "" + "contactName": "", }, { "id": 10, @@ -546,11 +555,12 @@ "facebookUrl": "https://www.facebook.com/CELTSbereatutoring", "bereaUrl": "https://www.berea.edu/centers/center-for-excellence-in-learning-through-service/programs/berea-tutoring", "programDescription": "Berea Tutoring provides an encouraging atmosphere for local students who need help in achieving academic success, and for college volunteers who want to learn more about teaching or volunteering. Our mission is to increase conceptual understanding in academic subject areas, enrich educational experiences, and build self-confidence by providing college-aged tutors to local school children.", + "partner": None, "isStudentLed": True, "isBonnerScholars": False, "isOtherCeltsSponsored": False, "contactEmail": "", - "contactName": "" + "contactName": "", } ] Program.insert_many(programs).on_conflict_replace().execute() @@ -1456,12 +1466,50 @@ files = [ { + "program": None, + "course": None, "event": 1, "fileName":"Map1.pdf" }, { "event": 2, "fileName" : "adfsfdhqwre_;ldgfk####l;kgfdg.jpg" + }, + { + "program": 1, + "fileName": "1.jpg" + }, + { + "program": 2, + "fileName": "2.jpg" + }, + { + "program": 3, + "fileName": "3.jpg" + }, + { + "program": 4, + "fileName": "4.jpeg" + }, + { + "program": 5, + "fileName": "5.jpg" + }, + { + "program": 6, + "fileName": "6.jpg" + }, + { + "program": 7, + "fileName": "7.jpeg" + }, + { + "program": 8, + "fileName": "8.jpeg" + }, + { + "program": 10, + "fileName": "10.jpg" } ] AttachmentUpload.insert_many(files).on_conflict_replace().execute() diff --git a/tests/code/test_landingPage.py b/tests/code/test_landingPage.py index 438be0ca1..e5d197a3c 100644 --- a/tests/code/test_landingPage.py +++ b/tests/code/test_landingPage.py @@ -50,7 +50,7 @@ def test_managerProgramDict(): with mainDB.atomic() as transaction: user = User.get(User.username == "ramsayb2") dict = getManagerProgramDict(user) - assert os.path.join('static', 'images/landingPage/Hunger Initiatives.jpg') in dict[Program.get(Program.programName == "Hunger Initiatives")]["image"] + assert os.path.join('static', 'files/programattachments/1.jpg') in dict[Program.get(Program.programName == "Hunger Initiatives")]["image"] noImageProgram = Program.create(programName = "Program with No Image", isStudentLed = False, diff --git a/tests/code/test_userManagement.py b/tests/code/test_userManagement.py index 38fcdaaea..829393c9e 100644 --- a/tests/code/test_userManagement.py +++ b/tests/code/test_userManagement.py @@ -1,4 +1,5 @@ import pytest +import io from flask import g from app import app from app.logic.userManagement import * @@ -8,6 +9,9 @@ from app.logic.volunteers import setProgramManager from peewee import DoesNotExist from app.models import mainDB +import os +import time +from werkzeug.datastructures import FileStorage @pytest.mark.integration def test_modifyCeltsAdmin(): @@ -81,29 +85,62 @@ def test_modifyCeltsStudentStaff(): @pytest.mark.integration def test_changeProgramInfo(): with mainDB.atomic() as transaction: - - programId = 3 - eventName = "Test Event Name" - contactName = "New Test Name" - contactEmail = 'newtest@email' - location = "Danforth Tech" - currentProgramInfo = Program.get_by_id(programId) - - assert currentProgramInfo.programName == "Adopt-a-Grandparent" + baseProgramData = { + "programName" : "Test Program Name", + "programDescription" : "This is the original test description", + "partner" : "Original Test Partner", + "contactName" : "", + "contactEmail" : '', + "location" : "", + "instagramUrl" : "", + "bereaUrl" : "", + "facebookUrl" : "" + } + + desiredProgramData = { + "programName" : "Test Program Name", + "programDescription" : "This is a test Description", + "partner" : "Test Partner", + "contactName" : "New Test Name", + "contactEmail" : 'newtest@email', + "location" : "Danforth Tech", + "instagramUrl" : "www.instagram.com", + "bereaUrl" : "www.berea.edu", + "facebookUrl" : "www.facebook.com" + } + newProgram = Program.create(**baseProgramData) + + currentProgramInfo = Program.get_by_id(newProgram.id) + currentProgramID = currentProgramInfo.id + + AttachmentUpload.create(program=currentProgramID, fileName=f'{currentProgramID}.jpg') + + assert currentProgramInfo.programName == desiredProgramData["programName"] + assert currentProgramInfo.programDescription != desiredProgramData['programDescription'] + assert currentProgramInfo.partner != desiredProgramData['partner'] assert currentProgramInfo.contactName == "" assert currentProgramInfo.contactEmail == "" assert currentProgramInfo.defaultLocation == "" + assert currentProgramInfo.instagramUrl != None + assert currentProgramInfo.bereaUrl != None + assert currentProgramInfo.facebookUrl != None + with app.test_request_context(): g.current_user = "ramsayb2" - changeProgramInfo(eventName, contactEmail, contactName, location, programId) - - currentProgramInfo = Program.select().where(Program.id==programId).get() - - assert currentProgramInfo.programName == eventName - assert currentProgramInfo.contactName == contactName - assert currentProgramInfo.contactEmail == contactEmail - assert currentProgramInfo.defaultLocation == location + changeProgramInfo(currentProgramID, None, **desiredProgramData) + + currentProgramInfo = Program.select().where(Program.id==currentProgramID).get() + + assert currentProgramInfo.programName == desiredProgramData["programName"] + assert currentProgramInfo.programDescription == desiredProgramData["programDescription"] + assert currentProgramInfo.partner == desiredProgramData["partner"] + assert currentProgramInfo.contactName == desiredProgramData["contactName"] + assert currentProgramInfo.contactEmail == desiredProgramData["contactEmail"] + assert currentProgramInfo.defaultLocation == desiredProgramData["location"] + assert currentProgramInfo.instagramUrl == desiredProgramData["instagramUrl"] + assert currentProgramInfo.facebookUrl == desiredProgramData["facebookUrl"] + assert currentProgramInfo.bereaUrl == desiredProgramData["bereaUrl"] transaction.rollback() @@ -130,7 +167,7 @@ def test_updatedProgramManager(): # Remove the user that was added as a Program Manager setProgramManager(user, program, "remove") assert ProgramManager.get_or_none(program = program, user = user) is None - + transaction.rollback() @pytest.mark.integration