8000 allow users to self accept nominations made on their behalf · python/pythondotorg@255b034 · GitHub
[go: up one dir, main page]

Skip to content

Commit 255b034

Browse files
committed
allow users to self accept nominations made on their behalf
1 parent 211edf6 commit 255b034

File tree

5 files changed

+61
-5
lines changed

5 files changed

+61
-5
lines changed

nominations/forms.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,14 @@ def clean_self_nomination(self):
5151
)
5252

5353
return data
54+
55+
56+
class NominationAcceptForm(forms.ModelForm):
57+
class Meta:
58+
model = Nomination
59+
fields = (
60+
"accepted",
61+
)
62+
help_texts = {
63+
"accepted": "If selected, this nomination will be considered accepted and displayed once nominations are public.",
64+
}

nominations/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ def get_edit_url(self):
208208
kwargs={"election": self.election.slug, "pk": self.pk},
209209
)
210210

211+
def get_accept_url(self):
212+
return reverse(
213+
"nominations:nomination_accept",
214+
kwargs={"election": self.election.slug, "pk": self.pk},
215+
)
216+
211217
def editable(self, user=None):
212218
if (
213219
self.nominee

nominations/urls.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@
2020
path('<slug:election>/<int:pk>/edit/', views.NominationEdit.as_vi 10000 ew(),
2121
name="nomination_edit",
2222
),
23+
path('<slug:election>/<int:pk>/accept/', views.NominationAccept.as_view(),
24+
name="nomination_accept",
25+
),
2326
]

nominations/views.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from django.contrib import messages
2+
from django.contrib.auth.mixins import UserPassesTestMixin
3+
24
from django.views.generic import CreateView, UpdateView, DetailView, ListView
35
from django.urls import reverse
46
from django.http import Http404
57

68
from pydotorg.mixins import LoginRequiredMixin
79

810
from .models import Nomination, Nominee, Election
9-
from .forms import NominationForm, NominationCreateForm
11+
from .forms import NominationForm, NominationCreateForm, NominationAcceptForm
1012

1113

1214
class ElectionsList(ListView):
@@ -119,10 +121,40 @@ def get_context_data(self, **kwargs):
119121
return context
120122

121123

122-
class NominationEdit(LoginRequiredMixin, NominationMixin, UpdateView):
124+
class NominationEdit(LoginRequiredMixin, NominationMixin, UserPassesTestMixin, UpdateView):
123125
model = Nomination
124126
form_class = NominationForm
125127

128+
def test_func(self):
129+
return self.request.user == self.get_object().nominator
130+
131+
def get_success_url(self):
132+
next_url = self.request.POST.get("next")
133+
if next_url:
134+
return next_url
135+
136+
elif self.object.pk:
137+
return reverse(
138+
"nominations:nomination_detail",
139+
kwargs={"election": self.object.election.slug, "pk": self.object.id},
140+
)
141+
142+
else:
143+
return super().get_success_url()
144+
145+
def get_context_data(self, **kwargs):
146+
context = super().get_context_data(**kwargs)
147+
return context
148+
149+
150+
class NominationAccept(LoginRequiredMixin, NominationMixin, UserPassesTestMixin, UpdateView):
151+
model = Nomination
152+
form_class = NominationAcceptForm
153+
template_name_suffix = '_accept_form'
154+
155+
def test_func(self):
156+
return self.request.user == self.get_object().nominee.user
157+
126158
def get_success_url(self):
127159
next_url = self.request.POST.get("next")
128160
if next_url:

templates/nominations/nomination_detail.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
<header class="article-header">
1515
<h1 class="page-title">Nomination for {{ nomination.name }} in {{ nomination.election.name }} Election</h1>
1616
</header>
17-
{% if nomination.nominee == request.user %}
17+
{% if nomination.nominee.user == request.user %}
1818
<center>
19-
<i>You are the nominee for this nomination.</i>
19+
<i>You are the nominee for this nomination.</i><br>
20+
<i>It is currently accepted!</i></br>
2021
{% if editable %}
21-
<a href="{{ nomination.get_edit_url }}">Edit</a>
22+
<a href="{{ nomination.get_accept_url }}">Change Acceptance</a>
2223
{% else %}
2324
<i>It is no longer editable as nominations are closed.</i>
2425
{% endif %}
@@ -44,6 +45,9 @@ <h1 class="page-title">Nomination for {{ nomination.name }} in {{ nomination.ele
4445
<li><b>Other Affiliations</b>: {{ nomination.other_affiliations }}</li>
4546
<li><b>Previous Board Service</b>: {{ nomination.previous_board_service }}</li>
4647
<li><b>Nominated By</b>: {{ nomination.nominator.first_name }} {{ nomination.nominator.last_name }}</li>
48+
{% if nomination.nominee.user == request.user %}
49+
<li><b>Accepted:</b> {{ nomination.accepted }}</li>
50+
{% endif %}
4751
</ul>
4852
</div>
4953
<div>

0 commit comments

Comments
 (0)
0