From fff9cf9c5537d9f758a9e30fcb18df800c70f051 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 18 Oct 2014 15:17:56 -0500 Subject: Convert bulk of package details page to Jinja2 We wrap the whole thing in a Django template so we don't have to convert our base template to Jinja2 (or have one for each templating engine). This also simplifies the static stuff so we can just keep using the Django tags. Signed-off-by: Dan McGee --- packages/templatetags/package_extras.py | 26 ++-- templates/packages/details.html | 225 +------------------------------- templates/packages/details.html.jinja | 221 +++++++++++++++++++++++++++++++ 3 files changed, 239 insertions(+), 233 deletions(-) create mode 100644 templates/packages/details.html.jinja diff --git a/packages/templatetags/package_extras.py b/packages/templatetags/package_extras.py index 2784546d..f6d6ee73 100644 --- a/packages/templatetags/package_extras.py +++ b/packages/templatetags/package_extras.py @@ -6,6 +6,9 @@ from django import template from django.utils.html import escape +from django_jinja import library + +from main.templatetags import pgp register = template.Library() @@ -14,11 +17,11 @@ def link_encode(url, query): # massage the data into all utf-8 encoded strings first, so urlencode # doesn't barf at the data we pass it query = {k: unicode(v).encode('utf-8') for k, v in query.items()} - data = urlencode(query).replace('&', '&') + data = urlencode(query) return "%s?%s" % (url, data) -@register.filter +@library.filter def url_unquote(original_url): try: url = original_url @@ -79,7 +82,7 @@ def pkg_details_link(pkg, link_title=None, honor_flagged=False): return link % (pkg.get_absolute_url(), pkg.pkgname, link_content) -@register.simple_tag +@library.global_function def maintainer_link(user): if user: # TODO don't hardcode @@ -92,7 +95,7 @@ def maintainer_link(user): return '' -@register.simple_tag +@library.global_function def packager_link(user): if user: # TODO don't hardcode @@ -105,7 +108,12 @@ def packager_link(user): return '' -@register.simple_tag +@library.global_function +def pgp_key_link(key_id, link_text=None): + return pgp.pgp_key_link(key_id, link_text) + + +@library.global_function def scm_link(package, operation): parts = (package.repo.svn_root, operation, package.pkgbase) linkbase = ( @@ -114,8 +122,8 @@ def scm_link(package, operation): return linkbase % tuple(urlquote(part.encode('utf-8')) for part in parts) -@register.simple_tag -def get_wiki_link(package): +@library.global_function +def wiki_link(package): url = "https://wiki.archlinux.org/index.php/Special:Search" data = { 'search': package.pkgname, @@ -123,7 +131,7 @@ def get_wiki_link(package): return link_encode(url, data) -@register.simple_tag +@library.global_function def bugs_list(package): url = "https://bugs.archlinux.org/" data = { @@ -134,7 +142,7 @@ def bugs_list(package): return link_encode(url, data) -@register.simple_tag +@library.global_function def bug_report(package): url = "https://bugs.archlinux.org/newtask" data = { diff --git a/templates/packages/details.html b/templates/packages/details.html index c4c1f6b2..7a0f8e88 100644 --- a/templates/packages/details.html +++ b/templates/packages/details.html @@ -1,234 +1,11 @@ {% extends "base.html" %} {% load static from staticfiles %} -{% load package_extras %} -{% load pgp %} {% block title %}Arch Linux - {{ pkg.pkgname }} {{ pkg.full_version }} ({{ pkg.arch.name }}){% endblock %} {% block navbarclass %}anb-packages{% endblock %} -{% load package_extras %} {% block content %} -
- -

{{ pkg.pkgname }} {{ pkg.full_version }}

- - - -
- - - - - - - -
- -
- - - - - - - - - {% ifequal pkg.pkgname pkg.pkgbase %} - {% with pkg.split_packages as splits %}{% if splits %} - - - - - {% endif %}{% endwith %} - {% else %} - - - {% with pkg.base_package as base %}{% if base %} - - {% else %} - - {% endif %}{% endwith %} - - {% endifequal %} - - - - - - - - - - - {% with pkg.groups.all as groups %}{% if groups %} - - - - - {% endif %}{% endwith %} - {% with pkg.provides.all as all_related %}{% if all_related %} - - - - - {% endif %}{% endwith %} - {% with pkg.replaces.all as all_related %}{% if all_related %} - - - - - {% endif %}{% endwith %} - {% with pkg.conflicts.all as all_related %}{% if all_related %} - - - - - {% endif %}{% endwith %} - {% with pkg.reverse_conflicts as rev_conflicts %}{% if rev_conflicts %} - - - - - {% endif %}{% endwith %} - - - {% with pkg.maintainers as maints %} - - {% endwith %} - - - - - - - - - - - - - {% if pkg.signature %} - - - - - - {% else %} - - - {% endif %} - - - - {% if user.is_authenticated %}{% with pkg.flag_request as flag_request %}{% if flag_request %} - - - {% endif %}{% endwith %}{% endif %} -
Architecture:{{ pkg.arch.name }}
Repository:{{ pkg.repo.name|capfirst }}
Split Packages:{% for s in splits %}{% pkg_details_link s %}{% if not forloop.last %}, {% endif %}{% endfor %}
Base Package:{% pkg_details_link base %}{{ pkg.pkgbase }}
Description:{{ pkg.pkgdesc|default:"" }}
Upstream URL:{% if pkg.url %}{% endif %}
License(s):{{ pkg.licenses.all|join:", " }}
Groups:{% for g in groups %} - {{ g.name }}{% if not forloop.last %}, {% endif %}{% endfor %} -
Provides:{% include "packages/details_relatedto.html.jinja" %}
Replaces:{% include "packages/details_relatedto.html.jinja" %}
Conflicts:{% include "packages/details_relatedto.html.jinja" %}
Reverse Conflicts:{% for conflict in rev_conflicts %} - {% pkg_details_link conflict %}{% if not forloop.last %}, {% endif %}{% endfor %}
Maintainers:{% if maints %} - {% for m in maints %} - {% maintainer_link m %}
- {% endfor %} - {% else %}Orphan{% endif %} -
Package Size:{{ pkg.compressed_size|filesizeformat }}
Installed Size:{{ pkg.installed_size|filesizeformat }}
Last Packager:{% with pkg.packager as pkgr %}{% if pkgr %}{% packager_link pkgr %}{% else %}{{ pkg.packager_str }}{% endif %}{% endwith %}
Build Date:{{ pkg.build_date|date:"DATETIME_FORMAT" }} UTC
Signed By:{% with pkg.signer as signer %}{% if signer %}{% pgp_key_link pkg.signature.key_id signer.get_full_name %}{% else %}Unknown ({% pgp_key_link pkg.signature.key_id %}){% endif %}{% endwith %}
Signature Date:{{ pkg.signature.creation_time|date:"DATETIME_FORMAT" }} UTC
Signed By:Unsigned
Last Updated:{{ pkg.last_update|date:"DATETIME_FORMAT" }} UTC
Last Flag Request:From {{ flag_request.who }} on {{ flag_request.created|date }}:
-
{{ flag_request.message|linebreaksbr|default:"{no message}" }}
-
- -
- {% with pkg.get_depends as deps %} -
-

- Dependencies ({{deps|length}})

- {% if deps %}
    - {% for depend in deps %}{% include "packages/details_depend.html.jinja" %}{% endfor %} -
{% endif %} -
- {% endwith %} - {% with pkg.get_requiredby as rqdby %} -
-

- Required By ({{rqdby|length}})

- {% if rqdby %}
    - {% for req in rqdby %}{% include "packages/details_requiredby.html.jinja" %}{% endfor %} -
{% endif %} -
- {% endwith %} -
-

- Package Contents

- -
-
-
+{% include "packages/details.html.jinja" %} {% endblock %} {% block script_block %} diff --git a/templates/packages/details.html.jinja b/templates/packages/details.html.jinja new file mode 100644 index 00000000..7ca5629c --- /dev/null +++ b/templates/packages/details.html.jinja @@ -0,0 +1,221 @@ +{% import 'packages/details_link.html.jinja' as details %} +
+

{{ pkg.pkgname }} {{ pkg.full_version }}

+ + + +
+ + + + + + + +
+ +
+ + + + + + + + + {% if pkg.pkgname == pkg.pkgbase %} + {% with splits = pkg.split_packages() %}{% if splits %} + + + + + {% endif %}{% endwith %} + {% else %} + + + {% with base = pkg.base_package %}{% if base %} + + {% else %} + + {% endif %}{% endwith %} + + {% endif %} + + + + + + + + + + + {% with groups = pkg.groups.all() %}{% if groups %} + + + + + {% endif %}{% endwith %} + {% with all_related = pkg.provides.all() %}{% if all_related %} + + + + + {% endif %}{% endwith %} + {% with all_related = pkg.replaces.all() %}{% if all_related %} + + + + + {% endif %}{% endwith %} + {% with all_related = pkg.conflicts.all() %}{% if all_related %} + + + + + {% endif %}{% endwith %} + {% with rev_conflicts = pkg.reverse_conflicts() %}{% if rev_conflicts %} + + + + + {% endif %}{% endwith %} + + + {% with maints = pkg.maintainers %} + + {% endwith %} + + + + + + + + + + + + + {% if pkg.signature %} + + + + + + {% else %} + + + {% endif %} + + + + {% if user.is_authenticated %}{% with flag_request = pkg.flag_request() %}{% if flag_request %} + + + {% endif %}{% endwith %}{% endif %} +
Architecture:{{ pkg.arch.name }}
Repository:{{ pkg.repo.name|capfirst }}
Split Packages:{% for s in splits %}{{ details.details_link(s) }}{% if not loop.last %}, {% endif %}{% endfor %}
Base Package:{{ details.details_link(base) }}{{ pkg.pkgbase }}
Description:{{ pkg.pkgdesc|default("") }}
Upstream URL:{% if pkg.url %}{% endif %}
License(s):{{ pkg.licenses.all()|join(", ") }}
Groups:{% for g in groups %} + {{ g.name }}{% if not loop.last %}, {% endif %}{% endfor %} +
Provides:{% include "packages/details_relatedto.html.jinja" %}
Replaces:{% include "packages/details_relatedto.html.jinja" %}
Conflicts:{% include "packages/details_relatedto.html.jinja" %}
Reverse Conflicts:{% for conflict in rev_conflicts %} + {{ details.details_link(conflict) }}{% if not loop.last %}, {% endif %}{% endfor %}
Maintainers:{% if maints %} + {% for m in maints %} + {{ maintainer_link(m)|safe }}
+ {% endfor %} + {% else %}Orphan{% endif %} +
Package Size:{{ pkg.compressed_size|filesizeformat }}
Installed Size:{{ pkg.installed_size|filesizeformat }}
Last Packager:{% with pkgr = pkg.packager %}{% if pkgr %}{{ packager_link(pkgr)|safe }}{% else %}{{ pkg.packager_str }}{% endif %}{% endwith %}
Build Date:{{ pkg.build_date|date("DATETIME_FORMAT") }} UTC
Signed By:{% with signer = pkg.signer %}{% if signer %}{{ pgp_key_link(pkg.signature.key_id, signer.get_full_name())|safe }}{% else %}Unknown ({{ pgp_key_link(pkg.signature.key_id)|safe }}){% endif %}{% endwith %}
Signature Date:{{ pkg.signature.creation_time|date("DATETIME_FORMAT") }} UTC
Signed By:Unsigned
Last Updated:{{ pkg.last_update|date("DATETIME_FORMAT") }} UTC
Last Flag Request:From {{ flag_request.who() }} on {{ flag_request.created|date }}:
+
{{ flag_request.message|linebreaksbr|default("{no message}") }}
+
+ +
+ {% with deps = pkg.get_depends() %} +
+

+ Dependencies ({{deps|length}})

+ {% if deps %}
    + {% for depend in deps %}{% include "packages/details_depend.html.jinja" %}{% endfor %} +
{% endif %} +
+ {% endwith %} + {% with rqdby = pkg.get_requiredby() %} +
+

+ Required By ({{rqdby|length}})

+ {% if rqdby %}
    + {% for req in rqdby %}{% include "packages/details_requiredby.html.jinja" %}{% endfor %} +
{% endif %} +
+ {% endwith %} +
+

+ Package Contents

+ +
+
+
-- cgit v1.2.3-54-g00ecf