Cleanup this file before doing any work on it. Items addressed: * Move complex logic into template tags * Move related content closer together * Random whitespace annoyances
Signed-off-by: Stephen Finucane <stephen.finuc...@intel.com> --- patchwork/templates/patchwork/patch-list.html | 95 +++++++++++++++------------ patchwork/templatetags/project.py | 33 ++++++++++ 2 files changed, 85 insertions(+), 43 deletions(-) create mode 100644 patchwork/templatetags/project.py diff --git a/patchwork/templates/patchwork/patch-list.html b/patchwork/templates/patchwork/patch-list.html index 2528790..66149c3 100644 --- a/patchwork/templates/patchwork/patch-list.html +++ b/patchwork/templates/patchwork/patch-list.html @@ -1,6 +1,7 @@ {% load person %} {% load listurl %} {% load patch %} +{% load project %} {% load static %} {% load cycle from future %} @@ -30,8 +31,9 @@ {% if page.paginator.long_page and user.is_authenticated %} <div class="floaty"> - <a title="jump to form" href="#patchforms"><span - style="font-size: 120%">▾</span></a> + <a title="jump to form" href="#patchforms"> + <span style="font-size: 120%">▾</span> + </a> </div> {% endif %} @@ -55,11 +57,12 @@ $(document).ready(function() { <th> {% ifequal order.name "name" %} - <a class="colactive" - href="{% listurl order=order.reversed_name %}"><span - class="glyphicon glyphicon-chevron-{{ order.updown }}" - ></span></a> <a class="colactive" - href="{% listurl order=order.reversed_name %}">Patch</a> + <a class="colactive" href="{% listurl order=order.reversed_name %}"> + <span class="glyphicon glyphicon-chevron-{{ order.updown }}"></span> + </a> + <a class="colactive" href="{% listurl order=order.reversed_name %}"> + Patch + </a> {% else %} {% if not order.editable %} <a class="colinactive" href="{% listurl order="name" %}">Patch</a> @@ -70,9 +73,7 @@ $(document).ready(function() { </th> <th> - <span - title="{% for tag in project.tags %}{{tag.name}}{% if not forloop.last %} / {% endif %}{% endfor %}" - >{% for tag in project.tags %}{{tag.abbrev}}{% if not forloop.last %}/{% endif %}{% endfor %}</span> + {% project_tags %} </th> <th> @@ -81,11 +82,12 @@ $(document).ready(function() { <th> {% ifequal order.name "date" %} - <a class="colactive" - href="{% listurl order=order.reversed_name %}"><span - class="glyphicon glyphicon-chevron-{{ order.updown }}" - ></span></a> <a class="colactive" - href="{% listurl order=order.reversed_name %}">Date</a> + <a class="colactive" href="{% listurl order=order.reversed_name %}"> + <span class="glyphicon glyphicon-chevron-{{ order.updown }}"></span> + </a> + <a class="colactive" href="{% listurl order=order.reversed_name %}"> + Date + </a> {% else %} {% if not order.editable %} <a class="colinactive" href="{% listurl order="date" %}">Date</a> @@ -97,14 +99,17 @@ $(document).ready(function() { <th> {% ifequal order.name "submitter" %} - <a class="colactive" - href="{% listurl order=order.reversed_name %}"><span - class="glyphicon glyphicon-chevron-{{ order.updown }}" - ></span></a> <a class="colactive" - href="{% listurl order=order.reversed_name %}">Submitter</a> + <a class="colactive" href="{% listurl order=order.reversed_name %}"> + <span class="glyphicon glyphicon-chevron-{{ order.updown }}"></span> + </a> + <a class="colactive" href="{% listurl order=order.reversed_name %}"> + Submitter + </a> {% else %} {% if not order.editable %} - <a class="colinactive" href="{% listurl order="submitter" %}">Submitter</a> + <a class="colinactive" href="{% listurl order="submitter" %}"> + Submitter + </a> {% else %} <span class="colinactive">Submitter</span> {% endif %} @@ -113,11 +118,12 @@ $(document).ready(function() { <th> {% ifequal order.name "delegate" %} - <a class="colactive" - href="{% listurl order=order.reversed_name %}"><span - class="glyphicon glyphicon-chevron-{{ order.updown }}" - ></span></a> <a class="colactive" - href="{% listurl order=order.reversed_name %}">Delegate</a> + <a class="colactive" href="{% listurl order=order.reversed_name %}"> + <span class="glyphicon glyphicon-chevron-{{ order.updown }}"></span> + </a> + <a class="colactive" href="{% listurl order=order.reversed_name %}"> + Delegate + </a> {% else %} {% if not order.editable %} <a class="colinactive" href="{% listurl order="delegate" %}">Delegate</a> @@ -129,11 +135,12 @@ $(document).ready(function() { <th> {% ifequal order.name "state" %} - <a class="colactive" - href="{% listurl order=order.reversed_name %}"><span - class="glyphicon glyphicon-chevron-{{ order.updown }}" - ></span></a> <a class="colactive" - href="{% listurl order=order.reversed_name %}">State</a> + <a class="colactive" href="{% listurl order=order.reversed_name %}"> + <span class="glyphicon glyphicon-chevron-{{ order.updown }}"></span> + </a> + <a class="colactive" href="{% listurl order=order.reversed_name %}"> + State + </a> {% else %} {% if not order.editable %} <a class="colinactive" href="{% listurl order="state" %}">State</a> @@ -146,17 +153,19 @@ $(document).ready(function() { </tr> </thead> -{% if page.paginator.count %} <tbody> {% for patch in page.object_list %} <tr id="patch_row:{{patch.id}}"> - {% if user.is_authenticated %} - <td> + {% if user.is_authenticated %} + <td> <input type="checkbox" name="patch_id:{{patch.id}}"/> - </td> - {% endif %} - <td><a href="{% url 'patch-detail' patch_id=patch.id %}" - >{{ patch.name|default:"[no subject]"|truncatechars:100 }}</a></td> + </td> + {% endif %} + <td> + <a href="{% url 'patchwork.views.patch.patch' patch_id=patch.id %}"> + {{ patch.name|default:"[no subject]"|truncatechars:100 }} + </a> + </td> <td class="text-nowrap">{{ patch|patch_tags }}</td> <td class="text-nowrap">{{ patch|patch_checks }}</td> <td class="text-nowrap">{{ patch.date|date:"Y-m-d" }}</td> @@ -164,10 +173,15 @@ $(document).ready(function() { <td>{{ patch.delegate.username }}</td> <td>{{ patch.state }}</td> </tr> + {% empty %} + <tr> + <td colspan="8">No patches to display</td> + </tr> {% endfor %} </tbody> </table> +{% if page.paginator.count %} {% include "patchwork/pagination.html" %} <div class="patchforms" id="patchforms"> @@ -245,15 +259,10 @@ $(document).ready(function() { </div> {% endif %} - <div style="clear: both;"> </div> </div> -{% else %} - <tr> - <td colspan="6">No patches to display</td> - </tr> {% endif %} </form> diff --git a/patchwork/templatetags/project.py b/patchwork/templatetags/project.py new file mode 100644 index 0000000..689b486 --- /dev/null +++ b/patchwork/templatetags/project.py @@ -0,0 +1,33 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2016 Intel Corporation +# +# This file is part of the Patchwork package. +# +# Patchwork is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# Patchwork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Patchwork; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +from __future__ import absolute_import + +from django import template +from django.utils.safestring import mark_safe + + +register = template.Library() + + +@register.simple_tag(takes_context=True) +def project_tags(context): + return mark_safe('<span title="%s">%s</span>' % ( + ' / '.join([tag.name for tag in context['project'].tags]), + '/'.join([tag.abbrev for tag in context['project'].tags]))) -- 2.0.0 _______________________________________________ Patchwork mailing list Patchwork@lists.ozlabs.org https://lists.ozlabs.org/listinfo/patchwork