[PATCH 3/5] models, templates: Add sumbission relations
Daniel Axtens
dja at axtens.net
Fri Oct 18 20:10:51 AEDT 2019
Mete Polat <metepolat2000 at gmail.com> writes:
> From: Mete Polat <metepolat2000 at gmail.com>
>
> Introduces the ability to add relations between submissions. Relations
> are displayed in the details page of a submission under 'Related'.
> Related submissions located in another projects can be viewed as well.
>
> Signed-off-by: Mete Polat <metepolat2000 at gmail.com>
> ---
> .../migrations/0037_submission_relations.py | 28 +++++++++++
> patchwork/models.py | 9 ++++
> patchwork/templates/patchwork/submission.html | 48 +++++++++++++++++--
> patchwork/views/patch.py | 3 ++
> 4 files changed, 85 insertions(+), 3 deletions(-)
> create mode 100644 patchwork/migrations/0037_submission_relations.py
>
> diff --git a/patchwork/migrations/0037_submission_relations.py b/patchwork/migrations/0037_submission_relations.py
> new file mode 100644
> index 0000000..5aefc43
> --- /dev/null
> +++ b/patchwork/migrations/0037_submission_relations.py
> @@ -0,0 +1,28 @@
> +# Generated by Django 2.2.5 on 2019-10-07 19:58
> +
> +import datetime
> +from django.conf import settings
> +from django.db import migrations, models
> +import django.db.models.deletion
> +import patchwork.models
> +
> +
> +class Migration(migrations.Migration):
> +
> + dependencies = [
> + ('patchwork', '0036_project_commit_url_format'),
> + ]
> +
> + operations = [
> + migrations.CreateModel(
> + name='SubmissionRelation',
> + fields=[
> + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
> + ],
> + ),
> + migrations.AddField(
> + model_name='submission',
> + name='related',
> + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='submissions', related_query_name='submission', to='patchwork.SubmissionRelation'),
> + ),
> + ]
> diff --git a/patchwork/models.py b/patchwork/models.py
> index c198bc2..9521ce6 100644
> --- a/patchwork/models.py
> +++ b/patchwork/models.py
> @@ -374,6 +374,9 @@ class Submission(FilenameMixin, EmailMixin, models.Model):
> # submission metadata
>
> name = models.CharField(max_length=255)
> + related = models.ForeignKey(
> + 'SubmissionRelation', null=True, blank=True, on_delete=models.SET_NULL,
> + related_name='submissions', related_query_name='submission')
>
> @property
> def list_archive_url(self):
> @@ -848,6 +851,12 @@ class BundlePatch(models.Model):
> ordering = ['order']
>
>
> +class SubmissionRelation(models.Model):
> +
> + def __str__(self):
> + return ', '.join(s.name for s in self.submissions.all()) or '<Empty>'
> +
> +
> @python_2_unicode_compatible
> class Check(models.Model):
>
> diff --git a/patchwork/templates/patchwork/submission.html b/patchwork/templates/patchwork/submission.html
> index d0e9b56..e6b85ed 100644
> --- a/patchwork/templates/patchwork/submission.html
> +++ b/patchwork/templates/patchwork/submission.html
> @@ -9,7 +9,7 @@
>
> {% block body %}
> <script type="text/javascript">
> -function toggle_div(link_id, headers_id)
> +function toggle_div(link_id, headers_id, label_show, label_hide)
> {
> var link = document.getElementById(link_id)
> var headers = document.getElementById(headers_id)
> @@ -17,10 +17,10 @@ function toggle_div(link_id, headers_id)
> var hidden = headers.style['display'] == 'none';
>
> if (hidden) {
> - link.innerHTML = 'hide';
> + link.innerHTML = label_hide || 'hide';
> headers.style['display'] = 'block';
> } else {
> - link.innerHTML = 'show';
> + link.innerHTML = label_show || 'show';
> headers.style['display'] = 'none';
> }
>
> @@ -105,6 +105,48 @@ function toggle_div(link_id, headers_id)
> (detailed view)
> </a>
> </ul>
> + <a href="{% url 'patch-list' project_id=project.linkname %}?series={{ submission.series.id }}">
> + (Detailed view)
> + </a>
> + </div>
You've added (detailed view) / (Detailed view) twice here.
Regards,
Daniel
> + </td>
> + </tr>
> +{% endif %}
> +{% if submission.related %}
> + <tr>
> + <th>Related</th>
> + <td>
> + <a id="togglerelated"
> + href="javascript:toggle_div('togglerelated', 'related')"
> + >show</a>
> + <div id="related" class="submissionlist" style="display:none;">
> + <ul>
> + {% for sibling in submission.related.submissions.all %}
> + <li>
> + {% if sibling.id != submission.id and sibling.project == submission.project %}
> + <a href="{% url 'patch-detail' project_id=sibling.project.linkname msgid=sibling.url_msgid %}">
> + {{ sibling.name|default:"[no subject]"|truncatechars:100 }}
> + </a>
> + {% endif %}
> + </li>
> + {% endfor %}
> + {% if related_outside %}
> + <a id="togglerelatedoutside"
> + href="javascript:toggle_div('togglerelatedoutside', 'relatedoutside', 'show from other projects')"
> + >show from other projects</a>
> + <div id="relatedoutside" class="submissionlist" style="display:none;">
> + <ul>
> + {% for sibling in related_outside %}
> + <li>
> + <a href="{% url 'patch-detail' project_id=sibling.project.linkname msgid=sibling.url_msgid %}">
> + {{ sibling.name|default:"[no subject]"|truncatechars:100 }}
> + </a> (in {{ sibling.project }})
> + </li>
> + {% endfor %}
> + </ul>
> + </div>
> + {% endif %}
> + </ul>
> </div>
> </td>
> </tr>
> diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py
> index f34053c..84b8659 100644
> --- a/patchwork/views/patch.py
> +++ b/patchwork/views/patch.py
> @@ -110,12 +110,15 @@ def patch_detail(request, project_id, msgid):
> comments = comments.only('submitter', 'date', 'id', 'content',
> 'submission')
>
> + related_outside = patch.related.submissions.exclude(project=patch.project)
> +
> context['comments'] = comments
> context['checks'] = patch.check_set.all().select_related('user')
> context['submission'] = patch
> context['patchform'] = form
> context['createbundleform'] = createbundleform
> context['project'] = patch.project
> + context['related_outside'] = related_outside
>
> return render(request, 'patchwork/submission.html', context)
>
> --
> 2.20.1 (Apple Git-117)
>
> _______________________________________________
> Patchwork mailing list
> Patchwork at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork
More information about the Patchwork
mailing list