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,15 +233,19 @@ 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:
# add new supporters # The managerform has no field for the supporters
for supporter in new_supporters.difference(old_supporters): pass
application.support(supporter) else:
# remove old supporters old_supporters = set(application.supporters)
for supporter in old_supporters.difference(new_supporters): # add new supporters
application.unsupport(supporter) for supporter in new_supporters.difference(old_supporters):
application.support(supporter)
# remove old supporters
for supporter in old_supporters.difference(new_supporters):
application.unsupport(supporter)
if application_id is None: if application_id is None:
messages.success(request, _('New application was successfully created.')) messages.success(request, _('New application was successfully created.'))
else: else:
@ -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: