Created
May 17, 2016 11:06
-
-
Save mazulo/9b301d831ab3814cda66e611b5638ceb to your computer and use it in GitHub Desktop.
fix bug in simplemooc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# old | |
@login_required | |
def undo_enrollment(request, slug): | |
course = get_object_or_404(Course, slug=slug) | |
enrollment = get_object_or_404( | |
Enrollment, | |
user=request.user, | |
course=course | |
) | |
if request.method == 'POST': | |
enrollment.delete() | |
messages.success(request, 'Sua inscrição foi cancelada com sucesso.') | |
return redirect('accounts:dashboard') | |
template = 'courses/undo_enrollment.html' | |
context = { | |
'enrollment': enrollment, | |
'course': course | |
} | |
return render(request, template, context) | |
# new | |
@login_required | |
def undo_enrollment(request, slug): | |
course = get_course_by_instance(slug, Course, CourseTRB) | |
content_type = ContentType.objects.get_for_model(course) | |
enrollment = get_object_or_404( | |
Enrollment, | |
user=request.user, | |
content_type=content_type, | |
object_id=course.id | |
) | |
if request.method == 'POST': | |
enrollment.delete() | |
messages.success(request, 'Sua inscrição foi cancelada com sucesso.') | |
return redirect('accounts:dashboard') | |
template = 'courses/undo_enrollment.html' | |
context = { | |
'enrollment': enrollment, | |
'course': course | |
} | |
return render(request, template, context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment