Skip to content

Commit 68295ef

Browse files
committed
feat: add review intentions to patch view
1 parent d9a8e56 commit 68295ef

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

patchwork/templates/patchwork/submission.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,35 @@ <h2>Message</h2>
266266
</pre>
267267
</div>
268268

269+
<h2>Users intending to review</h2>
270+
{% if intentions %}
271+
<ul>
272+
{% for intention in intentions %}
273+
<li>
274+
{{ intention.user.username }} ({{ intention.user.email }}) - Review expiration date: {{ intention.review_expiry_date }}
275+
</li>
276+
{% endfor %}
277+
</ul>
278+
{% else %}
279+
<p>No users have declared interest in reviewing this patch.</p>
280+
{% endif %}
281+
282+
{% if planning_to_review %}
283+
<form id="declare-review-form" method="post">
284+
{% csrf_token %}
285+
Current review intention expires in {{ review_expiry_date }}
286+
<br>
287+
<input type="hidden" name="action" value="remove-review">
288+
<input type="submit" class="patch-form-submit btn btn-primary" value="Remove review interest">
289+
</form>
290+
{% else %}
291+
<form id="declare-review-form" method="post">
292+
{% csrf_token %}
293+
<input type="hidden" name="action" value="add-review">
294+
<input type="submit" class="patch-form-submit btn btn-primary" value="Declare review interest">
295+
</form>
296+
{% endif %}
297+
269298
{% for item in comments %}
270299
{% if forloop.first %}
271300
<h2>Comments</h2>

patchwork/views/patch.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from patchwork.models import Bundle
1818
from patchwork.models import Cover
1919
from patchwork.models import Patch
20+
from patchwork.models import PatchReviewIntention
2021
from patchwork.models import Project
2122
from patchwork.views import generic_list
2223
from patchwork.views.utils import patch_to_mbox
@@ -102,6 +103,30 @@ def patch_detail(request, project_id, msgid):
102103
'Failed to add patch "%s" to bundle "%s": '
103104
'patch is already in bundle' % (patch.name, bundle.name),
104105
)
106+
elif action == 'add-review':
107+
if request.user.is_authenticated:
108+
PatchReviewIntention.objects.get_or_create(
109+
patch=patch,
110+
user=request.user
111+
)
112+
patch.has_planned_review = patch.planning_to_review.exists()
113+
patch.save()
114+
115+
messages.success(request, "You have declared interest in reviewing this patch.")
116+
else:
117+
messages.error(request, "You must be logged in to declare review interest.")
118+
119+
elif action == 'remove-review':
120+
if request.user.is_authenticated:
121+
PatchReviewIntention.objects.filter(
122+
patch=patch,
123+
user=request.user
124+
).delete()
125+
patch.has_planned_review = patch.planning_to_review.exists()
126+
patch.save()
127+
messages.success(request, "You have removed your interest in reviewing this patch.")
128+
else:
129+
messages.error(request, "You must be logged in to remove review interest.")
105130

106131
# all other actions require edit privs
107132
elif not editable:
@@ -116,6 +141,17 @@ def patch_detail(request, project_id, msgid):
116141
if request.user.is_authenticated:
117142
context['bundles'] = request.user.bundles.all()
118143

144+
intentions = PatchReviewIntention.objects.filter(patch=patch)
145+
146+
context['intentions'] = intentions
147+
context['planning_to_review'] = False
148+
context['review_expiry_date'] = None
149+
for intention in intentions:
150+
intention.review_expiry_date = intention.last_time_marked_for_review + patch.state.review_intention_expiration_time
151+
if intention.user == request.user:
152+
context['planning_to_review'] = True
153+
context['review_expiry_date'] = intention.last_time_marked_for_review + patch.state.review_intention_expiration_time
154+
119155
comments = patch.comments.all()
120156
comments = comments.select_related('submitter')
121157
comments = comments.only(

0 commit comments

Comments
 (0)