Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I509 #3

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions patchwork/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,55 @@ def save(self, instance, commit=True):
if commit:
instance.save()
return instance


class SeriesBulkUpdatePatchesForm(forms.Form):
action = 'update'
archived = OptionalBooleanField(
choices=[
('*', 'no change'),
('True', 'Archived'),
('False', 'Unarchived'),
],
coerce=lambda x: x == 'True',
empty_value='*',
)

def __init__(self, project, *args, **kwargs):
super(SeriesBulkUpdatePatchesForm, self).__init__(*args, **kwargs)
self.fields['delegate'] = OptionalModelChoiceField(
queryset=_get_delegate_qs(project=project), required=False
)
self.fields['state'] = OptionalModelChoiceField(
queryset=State.objects.all()
)

def save(self, series, request):
update_values = {}
data = self.cleaned_data

for name, obj in self.fields.items():
value = data[name]
if not obj.is_no_change(value):
update_values[name] = value

patches = Patch.objects.filter(series=series)
err = bulk_update_patches(patches, request, update_values)

return err


def bulk_update_patches(patches, request, values_to_update):
errors = []
for patch in patches:
if not patch.is_editable(request.user):
errors.append(
"You don't have permissions to edit patch '%s'" % patch.name
)
continue

if len(errors) > 0:
return errors

patches.update(**values_to_update)
return errors
41 changes: 41 additions & 0 deletions patchwork/templates/patchwork/series-detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% extends "base.html" %}

{% load humanize %}
{% load syntax %}
{% load person %}
{% load patch %}
{% load static %}
{% load utils %}

{% block title %}{{series.name}}{% endblock %}

{% block body %}

<div>
<h1>{{ series.name }}</h1>
</div>

<table class="patch-meta">
<tr>
<th>Cover Letter</th>
<td>{{ series.cover_letter.content|default:"No cover letter available" }}</td>
</tr>
<tr>
<th>Date</th>
<td>{{ series.date }}</td>
</tr>
<tr>
<th>Submitter</th>
<td>{{ series.submitter }}</td>
</tr>
<tr>
<th>Total</th>
<td>{{ series.patches }}</td>
</tr>
</table>
<br>
<h2>Patches:</h2>
<br>
{% include "patchwork/partials/patch-list.html" %}

{% endblock %}
99 changes: 99 additions & 0 deletions patchwork/templates/patchwork/series-list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{% extends "base.html" %}

{% load person %}
{% load static %}

{% block title %}{{project.name}}{% endblock %}
{% block series_active %}active{% endblock %}

{% block body %}

{% load person %}
{% load listurl %}
{% load patch %}
{% load project %}
{% load static %}

{% include "patchwork/partials/pagination.html" %}

<input type="hidden" name="form" value="serieslistform"/>
<input type="hidden" name="project" value="{{project.id}}"/>

<table id="serieslist" class="table table-hover table-extra-condensed table-striped pw-list" data-toggle="checkboxes" data-range="true">
<thead>
<tr>
{% if user.is_authenticated and user.profile.show_ids %}
<th>
ID
</th>
{% endif %}

<th>
Version
</th>

<th>
<span class="colinactive">Series</span>
</th>

<th>
<span class="colinactive">Cover Letter</span>
</th>

<th>
<span class="colinactive">Number of Patches</span>
</th>

<th>
<span class="colinactive">Date</span>
</th>

<th>
<span class="colinactive">Submitter</span>
</th>

<th>
<span class="colinactive"> Edit patches </span>
</th>
</tr>
</thead>

<tbody>
{% for series in series_list %}
<tr id="series_row:{{series.id}}">
{% if user.is_authenticated and user.profile.show_ids %}
<td>
<button type="button" class="btn btn-xs btn-copy" data-clipboard-text="{{ series.id }}" title="Copy to Clipboard">
{{ series.id }}
</button>
</td>
{% endif %}
<td>
{{ series.version|default:"-"}}
</td>
<td>
<a href="{% url 'series-detail' series_id=series.id %}">
{{ series.name|default:"[no subject]"|truncatechars:100 }}
</a>
</td>
<td>{{ series.cover_letter.content|default:"No cover letter available" }}</td>
<td>{{ series.received_total}}</td>
<td class="text-nowrap">{{ series.date|date:"Y-m-d" }}</td>
<td>{{ series.submitter|personify:project }}</td>
<td>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type='submit' name="save" value="{{ series.id }}">Save</button>
</form>
</td>
</tr>
{% empty %}
<tr>
<td colspan="8">No series to display</td>
</tr>
{% endfor %}
</tbody>
</table>

{% endblock %}
16 changes: 16 additions & 0 deletions patchwork/templates/patchwork/submission.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@
<h1>{{ submission.name }}</h1>
</div>

<div class="btn-group pull-right">
<a class="btn btn-default {% if not next_submission %} disabled {% endif %}"
{% if next_submission %} href="{% url 'patch-detail' project_id=project.linkname msgid=next_submission.encoded_msgid %}" {% endif %}>
next
</a>
</div>

<div class="btn-group pull-right">
<a
class="btn btn-default {% if not previous_submission %} disabled {% endif %}"
{% if previous_submission %} href="{% url 'patch-detail' project_id=project.linkname msgid=previous_submission.encoded_msgid %}" {% endif %}
>
previous
</a>
</div>

<table id="patch-meta" class="patch-meta" data-submission-type={{submission|verbose_name_plural|lower}} data-submission-id={{submission.id}}>
<tr>
<th>Message ID</th>
Expand Down
84 changes: 84 additions & 0 deletions patchwork/tests/views/test_series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Patchwork - automated patch tracking system
# Copyright (C) 2012 Jeremy Kerr <[email protected]>
#
# SPDX-License-Identifier: GPL-2.0-or-later

from datetime import datetime as dt

from django.test import TestCase
from django.urls import reverse

from patchwork.models import Patch
from patchwork.models import Person
from patchwork.tests.utils import create_patch
from patchwork.tests.utils import create_cover
from patchwork.tests.utils import create_person
from patchwork.tests.utils import create_project
from patchwork.tests.utils import create_series
from patchwork.tests.utils import create_user


class SeriesList(TestCase):
def setUp(self):
self.project = create_project()
self.user = create_user()
self.person_1 = Person.objects.get(user=self.user)
self.person_2 = create_person()
self.series_1 = create_series(project=self.project)
self.series_2 = create_series(project=self.project)
create_cover(project=self.project, series=self.series_1)

for i in range(5):
create_patch(
submitter=self.person_1,
project=self.project,
series=self.series_1,
date=dt(2014, 3, 16, 13, 4, 50, 155643),
)
create_patch(
submitter=self.person_2,
project=self.project,
series=self.series_2,
date=dt(2014, 3, 16, 13, 4, 50, 155643),
)

# with open('output.html', "w", encoding="utf-8") as file:
# file.write(response.content.decode('utf-8'))

def test_series_list(self):
requested_url = reverse(
'series-list',
kwargs={'project_id': self.project.linkname},
)
response = self.client.get(requested_url)

self.assertEqual(response.status_code, 200)

def test_update_series_list_unauth(self):
requested_url = reverse(
'series-list',
kwargs={'project_id': self.project.linkname},
)

data = {'save': self.series_1.id, 'archived': 'True', 'state': '*'}
response = self.client.post(requested_url, data)

self.assertContains(
response, 'You don&#x27;t have permissions to edit patch'
)

def test_update_series_list(self):
requested_url = reverse(
'series-list',
kwargs={'project_id': self.project.linkname},
)

data = {'save': self.series_1.id, 'archived': 'True', 'state': '*'}
self.client.login(
username=self.user.username, password=self.user.username
)
_ = self.client.post(requested_url, data)

patches = Patch.objects.filter(series=self.series_1)
for patch in patches:
self.assertEqual(patch.archived, True)
10 changes: 10 additions & 0 deletions patchwork/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
patch_views.patch_list,
name='patch-list',
),
path(
'project/<project_id>/series-list/',
series_views.series_list,
name='series-list',
),
path(
'project/<project_id>/bundles/',
bundle_views.bundle_list,
Expand Down Expand Up @@ -110,6 +115,11 @@
name='comment-redirect',
),
# series views
path(
'series/<int:series_id>/',
series_views.series_detail,
name='series-detail',
),
path(
'series/<int:series_id>/mbox/',
series_views.series_mbox,
Expand Down
14 changes: 14 additions & 0 deletions patchwork/views/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ def patch_detail(request, project_id, msgid):
context['related_same_project'] = related_same_project
context['related_different_project'] = related_different_project

try:
context['previous_submission'] = Patch.objects.get(
series=patch.series, number=patch.number - 1
)
except Patch.DoesNotExist:
context['previous_submission'] = None

try:
context['next_submission'] = Patch.objects.get(
series=patch.series, number=patch.number + 1
)
except Patch.DoesNotExist:
context['next_submission'] = None

return render(request, 'patchwork/submission.html', context)


Expand Down
Loading