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

Removed rows from canceled course proposals #1246

Merged
merged 10 commits into from
Jul 31, 2024
Merged
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()
BrianRamsay marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is not needed, the line right after describes what is going on pretty well in my opinion

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/>
BrianRamsay marked this conversation as resolved.
Show resolved Hide resolved
</div>
Loading