Add basic proposal acceptance admin view
This commit is contained in:
parent
7248b40a60
commit
b22cdef2b8
5 changed files with 291 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
|||
from django import forms
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.utils import timezone
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
|
@ -132,3 +133,95 @@ class GovernmentPlanUpdateProposalForm(forms.ModelForm):
|
|||
}
|
||||
plan.save(update_fields=["proposals"])
|
||||
return plan
|
||||
|
||||
|
||||
class GovernmentPlanUpdateAcceptProposalForm(GovernmentPlanUpdateProposalForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.plan = kwargs.pop("plan")
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def get_proposals(self):
|
||||
data = dict(self.plan.proposals)
|
||||
user_ids = self.plan.proposals.keys()
|
||||
user_map = {
|
||||
str(u.id): u for u in get_user_model().objects.filter(id__in=user_ids)
|
||||
}
|
||||
status_dict = dict(PlanStatus.choices)
|
||||
rating_dict = dict(PlanRating.choices)
|
||||
for user_id, v in data.items():
|
||||
v["user"] = user_map[user_id]
|
||||
data[user_id]["data"]["rating_label"] = rating_dict.get(
|
||||
data[user_id]["data"]["rating"]
|
||||
)
|
||||
data[user_id]["data"]["status_label"] = status_dict.get(
|
||||
data[user_id]["data"]["status"]
|
||||
)
|
||||
return data
|
||||
|
||||
def save(
|
||||
self,
|
||||
proposal_id=None,
|
||||
delete_proposals=None,
|
||||
delete_unconfirmed=False,
|
||||
delete_reason="",
|
||||
):
|
||||
import ipdb
|
||||
|
||||
ipdb.set_trace()
|
||||
update = super(forms.ModelForm, self).save(commit=False)
|
||||
update.plan = self.plan
|
||||
|
||||
if delete_proposals is None:
|
||||
delete_proposals = []
|
||||
if proposal_id:
|
||||
proposals = self.get_proposals()
|
||||
proposal_user = proposals[proposal_id]["user"]
|
||||
update.user = proposal_user
|
||||
# if proposal_user != user:
|
||||
# proposal_user.send_mail(
|
||||
# _("Changes to public body “{}” have been applied").format(pb.name),
|
||||
# _(
|
||||
# "Hello,\n\nYou can find the changed public body here:"
|
||||
# "\n\n{url}\n\nAll the Best,\n{site_name}"
|
||||
# ).format(
|
||||
# url=pb.get_absolute_domain_url(), site_name=settings.SITE_NAME
|
||||
# ),
|
||||
# priority=False,
|
||||
# )
|
||||
delete_proposals.append(proposal_id)
|
||||
for pid in delete_proposals:
|
||||
if pid in self.plan.proposals:
|
||||
del self.plan.proposals[pid]
|
||||
if not self.plan.proposals:
|
||||
self.plan.proposals = None
|
||||
self.plan.save(update_fields=["proposals"])
|
||||
|
||||
# if delete_unconfirmed:
|
||||
# self.delete_proposal(pb, user, delete_reason)
|
||||
# return None
|
||||
|
||||
update.save()
|
||||
# PublicBody.change_proposal_accepted.send(sender=pb, user=user)
|
||||
return update
|
||||
|
||||
# def delete_proposal(self, pb, user, delete_reason=""):
|
||||
# LogEntry.objects.log_action(
|
||||
# user_id=user.id,
|
||||
# content_type_id=ContentType.objects.get_for_model(pb).pk,
|
||||
# object_id=pb.pk,
|
||||
# object_repr=str(pb),
|
||||
# action_flag=DELETION,
|
||||
# )
|
||||
|
||||
# creator = pb.created_by
|
||||
# if creator:
|
||||
# creator.send_mail(
|
||||
# _("Your public body proposal “%s” was rejected") % pb.name,
|
||||
# _(
|
||||
# "Hello,\n\nA moderator has rejected your proposal for a new "
|
||||
# "public body.\n\n{delete_reason}\n\nAll the Best,\n{site_name}"
|
||||
# ).format(delete_reason=delete_reason, site_name=settings.SITE_NAME),
|
||||
# priority=False,
|
||||
# )
|
||||
# PublicBody.proposal_rejected.send(sender=pb, user=user)
|
||||
# pb.delete()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue