fix #336. The admin could not edit the supporters from applications
This commit is contained in:
parent
4873cd7163
commit
998fb3e1ee
@ -212,9 +212,6 @@ def edit(request, application_id=None):
|
|||||||
del_supporters = True
|
del_supporters = True
|
||||||
original_supporters = []
|
original_supporters = []
|
||||||
if is_manager:
|
if is_manager:
|
||||||
if application: # Edit application
|
|
||||||
for s in application.supporter.all():
|
|
||||||
original_supporters.append(s)
|
|
||||||
application = managerform.save(commit=False)
|
application = managerform.save(commit=False)
|
||||||
elif application_id is None:
|
elif application_id is None:
|
||||||
application = Application(submitter=request.user)
|
application = Application(submitter=request.user)
|
||||||
@ -229,28 +226,20 @@ def edit(request, application_id=None):
|
|||||||
trivial_change = False
|
trivial_change = False
|
||||||
application.save(request.user, trivial_change=trivial_change)
|
application.save(request.user, trivial_change=trivial_change)
|
||||||
if is_manager:
|
if is_manager:
|
||||||
# log added supporters
|
|
||||||
supporters_added = []
|
|
||||||
for s in application.supporter.all():
|
|
||||||
if s not in original_supporters:
|
|
||||||
try:
|
try:
|
||||||
supporters_added.append(unicode(s.profile))
|
new_supporters = set(managerform.cleaned_data['supporter'])
|
||||||
except Profile.DoesNotExist:
|
except KeyError:
|
||||||
|
# The managerform has no field for the supporters
|
||||||
pass
|
pass
|
||||||
if len(supporters_added) > 0:
|
else:
|
||||||
log_added = ", ".join(supporters_added)
|
old_supporters = set(application.supporter.all())
|
||||||
application.writelog(_("Supporter: +%s") % log_added, request.user)
|
# add new supporters
|
||||||
# log removed supporters
|
for supporter in new_supporters.difference(old_supporters):
|
||||||
supporters_removed = []
|
application.support(supporter)
|
||||||
for s in original_supporters:
|
# remove old supporters
|
||||||
if s not in application.supporter.all():
|
for supporter in old_supporters.difference(new_supporters):
|
||||||
try:
|
application.unsupport(supporter)
|
||||||
supporters_removed.append(unicode(s.profile))
|
|
||||||
except Profile.DoesNotExist:
|
|
||||||
pass
|
|
||||||
if len(supporters_removed) > 0:
|
|
||||||
log_removed = ", ".join(supporters_removed)
|
|
||||||
application.writelog(_("Supporter: -%s") % log_removed, request.user)
|
|
||||||
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:
|
||||||
@ -280,10 +269,9 @@ def edit(request, application_id=None):
|
|||||||
if application_id is None:
|
if application_id is None:
|
||||||
initial = {'submitter': str(request.user.id)}
|
initial = {'submitter': str(request.user.id)}
|
||||||
else:
|
else:
|
||||||
initial = {}
|
initial = {'supporter': application.supporter.all()}
|
||||||
managerform = managerformclass(initial=initial, \
|
managerform = managerformclass(
|
||||||
instance=application, \
|
initial=initial, instance=application, prefix="manager")
|
||||||
prefix="manager")
|
|
||||||
else:
|
else:
|
||||||
managerform = None
|
managerform = None
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user