Newer
Older
self.helper.add_input(
Submit("submit", _("Update")))
if participation.status != participation_status.active:
self.helper.add_input(
Submit("approve", _("Approve"), css_class="btn-success"))
if participation.status == participation_status.requested:
self.helper.add_input(
Submit("deny", _("Deny"), css_class="btn-danger"))
elif participation.status == participation_status.active:
self.helper.add_input(
Submit("drop", _("Drop"), css_class="btn-danger"))
def clean_user(self):
user = self.cleaned_data["user"]
if not self.add_new:
return user
if user.status == user_status.active:
return user
raise forms.ValidationError(
_("This user has not confirmed his/her email."))
# type: () -> Participation
inst = super(EditParticipationForm, self).save()
(ParticipationPermission.objects
.filter(participation=self.instance)
.delete())
pps = []
for perm in self.cleaned_data["individual_permissions"]:
pp = ParticipationPermission(
participation=self.instance,
permission=perm)
pp.save()
pps.append(pp)
self.instance.individual_permissions.set(pps)
class Meta:
model = Participation
exclude = (
"role",
"course",
)
widgets = {
"user": UserSearchWidget,
}
@course_view
def edit_participation(pctx, participation_id):
# type: (CoursePageContext, int) -> http.HttpResponse
if not pctx.has_permission(pperm.edit_participation):
raise PermissionDenied()
request = pctx.request
num_participation_id = int(participation_id)
if num_participation_id == -1:
participation = Participation(
course=pctx.course,
status=participation_status.active)
add_new = True
else:
participation = get_object_or_404(Participation, id=num_participation_id)
add_new = False
if participation.course.id != pctx.course.id:
raise SuspiciousOperation("may not edit participation in different course")
if request.method == 'POST':
form = EditParticipationForm(
add_new, pctx, request.POST, instance=participation)
reset_form = False
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
try:
if form.is_valid():
if "submit" in request.POST:
form.save()
messages.add_message(request, messages.SUCCESS,
_("Changes saved."))
elif "approve" in request.POST:
send_enrollment_decision(participation, True, pctx.request)
# FIXME: Double-saving
participation = form.save()
participation.status = participation_status.active
participation.save()
reset_form = True
messages.add_message(request, messages.SUCCESS,
_("Successfully enrolled."))
elif "deny" in request.POST:
send_enrollment_decision(participation, False, pctx.request)
# FIXME: Double-saving
participation = form.save()
participation.status = participation_status.denied
participation.save()
reset_form = True
messages.add_message(request, messages.SUCCESS,
_("Successfully denied."))
elif "drop" in request.POST:
# FIXME: Double-saving
participation = form.save()
participation.status = participation_status.dropped
participation.save()
reset_form = True
messages.add_message(request, messages.SUCCESS,
_("Successfully dropped."))
except IntegrityError as e:
messages.add_message(request, messages.ERROR,
_("A data integrity issue was detected when saving "
"this participation. Maybe a participation for "
"this user already exists? (%s)")
% str(e))
if reset_form:
form = EditParticipationForm(
add_new, pctx, instance=participation)
form = EditParticipationForm(add_new, pctx, instance=participation)
return render_course_page(pctx, "course/generic-course-form.html", {
"form_description": _("Edit Participation"),
"form": form
})
# }}}