user-api: fix an error with deactivated supporters in application

This commit is contained in:
Oskar Hahn 2012-08-04 12:46:32 +02:00
parent 14bf6d0a35
commit 8da09bb985

View File

@ -233,9 +233,13 @@ def edit(request, application_id=None):
trivial_change = False trivial_change = False
application.save(user2djangouser(request.user), trivial_change=trivial_change) application.save(user2djangouser(request.user), trivial_change=trivial_change)
if is_manager: if is_manager:
# TODO: Deal with the case, that the form has no field 'supporters' try:
old_supporters = set(application.supporters)
new_supporters = set(managerform.cleaned_data['supporter']) new_supporters = set(managerform.cleaned_data['supporter'])
except KeyError:
# The managerform has no field for the supporters
pass
else:
old_supporters = set(application.supporters)
# add new supporters # add new supporters
for supporter in new_supporters.difference(old_supporters): for supporter in new_supporters.difference(old_supporters):
application.support(supporter) application.support(supporter)
@ -271,8 +275,8 @@ def edit(request, application_id=None):
if application_id is None: if application_id is None:
initial = {'submitter': user2djangouser(request.user).uid} initial = {'submitter': user2djangouser(request.user).uid}
else: else:
initial = {'submitter': application.submitter.uid} initial = {'submitter': application.submitter.uid,
initial['supporter'] = [supporter.uid for supporter in application.supporters] 'supporter': [supporter.uid for supporter in application.supporters]}
managerform = managerformclass(initial=initial, managerform = managerformclass(initial=initial,
instance=application, prefix="manager") instance=application, prefix="manager")
else: else: