Skip to content

Instantly share code, notes, and snippets.

@mazulo
Created May 17, 2016 11:06
Show Gist options
  • Save mazulo/9b301d831ab3814cda66e611b5638ceb to your computer and use it in GitHub Desktop.
Save mazulo/9b301d831ab3814cda66e611b5638ceb to your computer and use it in GitHub Desktop.
fix bug in simplemooc
# 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