Skip to content

Commit

Permalink
Merge pull request #1246 from BCStudentSoftwareDevTeam/empty-course-row
Browse files Browse the repository at this point in the history
Removed rows from canceled course proposals
  • Loading branch information
BrianRamsay authored Jul 31, 2024
2 parents ed8a060 + 870a896 commit 6bd7229
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
13 changes: 10 additions & 3 deletions app/controllers/serviceLearning/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
from app.models.attachmentUpload import AttachmentUpload
from app.logic.utils import selectSurroundingTerms, getFilesFromRequest
from app.logic.fileHandler import FileHandler
from app.logic.serviceLearningCourses import getSLProposalInfoForUser, withdrawProposal, renewProposal, updateCourse, createCourse, approvedCourses
from app.logic.serviceLearningCourses import getSLProposalInfoForUser, withdrawProposal, renewProposal, updateCourse, createCourse, approvedCourses, deleteCourseObject
from app.logic.downloadFile import *
from app.logic.utils import getRedirectTarget, setRedirectTarget
from app.controllers.serviceLearning import serviceLearning_bp


@serviceLearning_bp.route('/serviceLearning/courseManagement', methods = ['GET'])
@serviceLearning_bp.route('/serviceLearning/courseManagement/<username>', methods = ['GET'])
def serviceCourseManagement(username=None):
Expand Down Expand Up @@ -88,9 +87,17 @@ def slcEditProposal(courseID):
def slcCreateCourse():
"""will give a new course ID so that it can redirect to an edit page"""
course = createCourse(g.current_user)

return redirect(url_for('serviceLearning.slcEditProposal', courseID = course.id))

@serviceLearning_bp.route('/serviceLearning/canceledProposal', methods=['POST'])
def slcCancelProposal():
courseID = request.form.get('courseID')
course = Course.get_by_id(courseID)
if not course.courseName and not course.courseAbbreviation:
CourseQuestion.delete().where(CourseQuestion.course == course).execute()
course.delete_instance()
return "Proposal Canceled"


@serviceLearning_bp.route('/serviceLearning/exit', methods=['GET'])
def slcExitView():
Expand Down
10 changes: 7 additions & 3 deletions app/logic/serviceLearningCourses.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ def withdrawProposal(courseID) -> None:
except DoesNotExist:
print(f"File, {AttachmentUpload.fileName}, does not exist.")

# delete course object
# deletes course
deletedCourse = deleteCourseObject(courseID=courseID)

createActivityLog(f"Withdrew SLC proposal: {deletedCourse}")

def deleteCourseObject(courseID):
course: Course = Course.get(Course.id == courseID)
courseName: str = course.courseName
questions: List[CourseQuestion] = CourseQuestion.select().where(CourseQuestion.course == course)
Expand All @@ -216,8 +221,7 @@ def withdrawProposal(courseID) -> None:
course.delete_instance(recursive=True)
for note in notes:
note.delete_instance()

createActivityLog(f"Withdrew SLC proposal: {courseName}")
return courseName

def createCourse(creator: str="No user provided") -> Course:
"""
Expand Down
10 changes: 9 additions & 1 deletion app/static/js/slcNewProposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ $(document).ready(function(e) {
});

$("#cancelButton").on("click", function() {
window.location.replace($(this).val());
var cancelButton = $(this)
$.ajax({
url: '/serviceLearning/canceledProposal',
method: 'POST',
data: {courseID : document.getElementById('courseID').value},
success: function(response) {
window.location.replace(cancelButton.val());
}
})
});

$("#saveContinue").on("click", function() {
Expand Down
2 changes: 1 addition & 1 deletion app/templates/serviceLearning/slcProposal.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,5 @@ <h3 class="text-center pb-4">Status:
</div>
</div>
</div>
<input value={{course.id}} name="courseID" hidden/>
<input value={{course.id}} id="courseID" name="courseID" hidden/>
</div>

0 comments on commit 6bd7229

Please sign in to comment.