From fe20aff2bb32a7e2a691f2f78b5cd617ed618243 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 18 Oct 2014 12:45:51 -0500 Subject: Disable eggs template loader --- settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/settings.py b/settings.py index 368dcb73..cc1f3a53 100644 --- a/settings.py +++ b/settings.py @@ -61,7 +61,6 @@ TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.eggs.Loader', 'django.template.loaders.app_directories.Loader', ) -- cgit v1.2.3-54-g00ecf From f4a6eff33815a713b1141ea94a872bd7c6233699 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 18 Oct 2014 13:38:54 -0500 Subject: Install and wire up django-jinja Signed-off-by: Dan McGee --- requirements.txt | 2 ++ requirements_prod.txt | 2 ++ settings.py | 8 ++++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index eff75bad..e2b49aba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,8 +2,10 @@ -e git+git://github.com/SmileyChris/django-countries.git@a2c924074dbe2f0b9b3059bf70064aeadf5643ed#egg=django-countries Django==1.7 IPy==0.81 +Jinja2==2.7.3 Markdown==2.4.1 bencode==1.0 +django-jinja==1.0.4 jsmin==2.0.11 pgpdump==1.5 pytz>=2014.7 diff --git a/requirements_prod.txt b/requirements_prod.txt index c181c3af..020a5ac4 100644 --- a/requirements_prod.txt +++ b/requirements_prod.txt @@ -2,8 +2,10 @@ -e git+git://github.com/SmileyChris/django-countries.git@a2c924074dbe2f0b9b3059bf70064aeadf5643ed#egg=django-countries Django==1.7 IPy==0.81 +Jinja2==2.7.3 Markdown==2.4.1 bencode==1.0 +django-jinja==1.0.4 jsmin==2.0.11 pgpdump==1.5 psycopg2==2.5.4 diff --git a/settings.py b/settings.py index cc1f3a53..5b2195cb 100644 --- a/settings.py +++ b/settings.py @@ -60,10 +60,13 @@ ) TEMPLATE_LOADERS = ( - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader', + 'django_jinja.loaders.FileSystemLoader', + 'django_jinja.loaders.AppLoader', ) +# Send templates matching the following to the Jinja2 engine +DEFAULT_JINJA2_TEMPLATE_EXTENSION = '.jinja' + MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -114,6 +117,7 @@ 'django.contrib.admin', 'django.contrib.staticfiles', 'django_countries', + 'django_jinja', 'main', 'mirrors', -- cgit v1.2.3-54-g00ecf From 2f19529c922172007ff3894ad0e0fca0b3e33f5b Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 18 Oct 2014 13:48:07 -0500 Subject: Convert details sub-tempates to Jinja2 This is a start at improving performance of rendering the package details page, our most-visited and slowest page on the production website. The Django template system is not very efficient due to our heavy use of broken out templates and pulling of various attributes and such on related packages. Signed-off-by: Dan McGee --- packages/templatetags/package_extras.py | 5 ----- templates/packages/details.html | 10 +++++----- templates/packages/details_depend.html | 13 ------------- templates/packages/details_depend.html.jinja | 13 +++++++++++++ templates/packages/details_link.html.jinja | 1 + templates/packages/details_relatedto.html | 2 -- templates/packages/details_relatedto.html.jinja | 3 +++ templates/packages/details_requiredby.html | 8 -------- templates/packages/details_requiredby.html.jinja | 8 ++++++++ 9 files changed, 30 insertions(+), 33 deletions(-) delete mode 100644 templates/packages/details_depend.html create mode 100644 templates/packages/details_depend.html.jinja create mode 100644 templates/packages/details_link.html.jinja delete mode 100644 templates/packages/details_relatedto.html create mode 100644 templates/packages/details_relatedto.html.jinja delete mode 100644 templates/packages/details_requiredby.html create mode 100644 templates/packages/details_requiredby.html.jinja diff --git a/packages/templatetags/package_extras.py b/packages/templatetags/package_extras.py index 3ce64748..2784546d 100644 --- a/packages/templatetags/package_extras.py +++ b/packages/templatetags/package_extras.py @@ -79,11 +79,6 @@ def pkg_details_link(pkg, link_title=None, honor_flagged=False): return link % (pkg.get_absolute_url(), pkg.pkgname, link_content) -@register.simple_tag -def multi_pkg_details(pkgs): - return ', '.join([pkg_details_link(pkg) for pkg in pkgs]) - - @register.simple_tag def maintainer_link(user): if user: diff --git a/templates/packages/details.html b/templates/packages/details.html index bfa2de16..c4c1f6b2 100644 --- a/templates/packages/details.html +++ b/templates/packages/details.html @@ -134,19 +134,19 @@

Versions Elsewhere

{% with pkg.provides.all as all_related %}{% if all_related %} Provides: - {% include "packages/details_relatedto.html" %} + {% include "packages/details_relatedto.html.jinja" %} {% endif %}{% endwith %} {% with pkg.replaces.all as all_related %}{% if all_related %} Replaces: - {% include "packages/details_relatedto.html" %} + {% include "packages/details_relatedto.html.jinja" %} {% endif %}{% endwith %} {% with pkg.conflicts.all as all_related %}{% if all_related %} Conflicts: - {% include "packages/details_relatedto.html" %} + {% include "packages/details_relatedto.html.jinja" %} {% endif %}{% endwith %} {% with pkg.reverse_conflicts as rev_conflicts %}{% if rev_conflicts %} @@ -205,7 +205,7 @@

Versions Elsewhere

Dependencies ({{deps|length}})

{% if deps %}
    - {% for depend in deps %}{% include "packages/details_depend.html" %}{% endfor %} + {% for depend in deps %}{% include "packages/details_depend.html.jinja" %}{% endfor %}
{% endif %} {% endwith %} @@ -214,7 +214,7 @@

Required By ({{rqdby|length}})

{% if rqdby %}
    - {% for req in rqdby %}{% include "packages/details_requiredby.html" %}{% endfor %} + {% for req in rqdby %}{% include "packages/details_requiredby.html.jinja" %}{% endfor %}
{% endif %} {% endwith %} diff --git a/templates/packages/details_depend.html b/templates/packages/details_depend.html deleted file mode 100644 index b89ffbfa..00000000 --- a/templates/packages/details_depend.html +++ /dev/null @@ -1,13 +0,0 @@ -{% load package_extras %}
  • {% ifequal depend.pkg None %} -{% if depend.providers %}{{ depend.dep.name }}{{ depend.dep.comparison|default:"" }}{{ depend.dep.version|default:"" }} ({% multi_pkg_details depend.providers %}) -{% else %}{{ depend.dep.name }}{{ depend.dep.comparison|default:"" }}{{ depend.dep.version|default:"" }} (virtual) -{% endif %}{% else %} -{% pkg_details_link depend.pkg %}{{ depend.dep.comparison|default:"" }}{{ depend.dep.version|default:"" }} -{% if depend.pkg.repo.testing %} (testing) -{% endif %}{% if depend.pkg.repo.staging %} (staging) -{% endif %}{% endifequal %} -{% if depend.dep.deptype == 'O' %} (optional) -{% endif %}{% if depend.dep.deptype == 'M' %} (make) -{% endif %}{% if depend.dep.deptype == 'C' %} (check) -{% endif %}{% if depend.dep.description %} - {{ depend.dep.description }} -{% endif %}
  • diff --git a/templates/packages/details_depend.html.jinja b/templates/packages/details_depend.html.jinja new file mode 100644 index 00000000..404793b6 --- /dev/null +++ b/templates/packages/details_depend.html.jinja @@ -0,0 +1,13 @@ +{% import 'packages/details_link.html.jinja' as details %}
  • {% if depend.pkg == None %} +{% if depend.providers %}{{ depend.dep.name }}{{ depend.dep.comparison|default("") }}{{ depend.dep.version|default("") }} ({% for pkg in depend.providers %}{{ details.details_link(pkg) }}{% if not loop.last %}, {% endif %}{% endfor %}) +{% else %}{{ depend.dep.name }}{{ depend.dep.comparison|default("") }}{{ depend.dep.version|default("") }} (virtual) +{% endif %}{% else %} +{{ details.details_link(depend.pkg) }}{{ depend.dep.comparison|default("") }}{{ depend.dep.version|default("") }} +{% if depend.pkg.repo.testing %} (testing) +{% endif %}{% if depend.pkg.repo.staging %} (staging) +{% endif %}{% endif %} +{% if depend.dep.deptype == 'O' %} (optional) +{% endif %}{% if depend.dep.deptype == 'M' %} (make) +{% endif %}{% if depend.dep.deptype == 'C' %} (check) +{% endif %}{% if depend.dep.description %} - {{ depend.dep.description }} +{% endif %}
  • diff --git a/templates/packages/details_link.html.jinja b/templates/packages/details_link.html.jinja new file mode 100644 index 00000000..b7e75fe5 --- /dev/null +++ b/templates/packages/details_link.html.jinja @@ -0,0 +1 @@ +{% macro details_link(pkg) %}{{ pkg.pkgname }}{% endmacro %} diff --git a/templates/packages/details_relatedto.html b/templates/packages/details_relatedto.html deleted file mode 100644 index e14375d3..00000000 --- a/templates/packages/details_relatedto.html +++ /dev/null @@ -1,2 +0,0 @@ -{% load package_extras %}{% for related in all_related %}{% with related.get_best_satisfier as best_satisfier %}{% ifequal best_satisfier None %}{{ related.name }}{% else %}{% pkg_details_link best_satisfier %}{% endifequal %}{{ related.comparison|default:"" }}{{ related.version|default:"" }}{% if not forloop.last %}, {% endif %} -{% endwith %}{% endfor %} diff --git a/templates/packages/details_relatedto.html.jinja b/templates/packages/details_relatedto.html.jinja new file mode 100644 index 00000000..955fdd37 --- /dev/null +++ b/templates/packages/details_relatedto.html.jinja @@ -0,0 +1,3 @@ +{% import 'packages/details_link.html.jinja' as details %}{% for related in all_related %}{% with best_satisfier = related.get_best_satisfier() %} +{% if best_satisfier == None %}{{ related.name }}{% else %}{{ details.details_link(best_satisfier) }}{% endif %}{{ related.comparison|default("") }}{{ related.version|default("") }}{% if not loop.last %}, {% endif %} +{% endwith %}{% endfor %} diff --git a/templates/packages/details_requiredby.html b/templates/packages/details_requiredby.html deleted file mode 100644 index 504a322f..00000000 --- a/templates/packages/details_requiredby.html +++ /dev/null @@ -1,8 +0,0 @@ -{% load package_extras %}
  • {% pkg_details_link req.pkg %} -{% if req.name != pkg.pkgname %} (requires {{ req.name }}) -{% endif %}{% if req.pkg.repo.testing %} (testing) -{% endif %}{% if req.pkg.repo.staging %} (staging) -{% endif %}{% if req.deptype == 'O' %} (optional) -{% endif %}{% if req.deptype == 'M' %} (make) -{% endif %}{% if req.deptype == 'C' %} (check) -{% endif %}
  • diff --git a/templates/packages/details_requiredby.html.jinja b/templates/packages/details_requiredby.html.jinja new file mode 100644 index 00000000..b083a7fc --- /dev/null +++ b/templates/packages/details_requiredby.html.jinja @@ -0,0 +1,8 @@ +{% import 'packages/details_link.html.jinja' as details %}
  • {{ details.details_link(req.pkg) }} +{% if req.name != pkg.pkgname %} (requires {{ req.name }}) +{% endif %}{% if req.pkg.repo.testing %} (testing) +{% endif %}{% if req.pkg.repo.staging %} (staging) +{% endif %}{% if req.deptype == 'O' %} (optional) +{% endif %}{% if req.deptype == 'M' %} (make) +{% endif %}{% if req.deptype == 'C' %} (check) +{% endif %}
  • -- cgit v1.2.3-54-g00ecf From 2914fc55c4618d97a3ab5a7d519545979f526677 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 18 Oct 2014 14:05:47 -0500 Subject: Enable Jinja2 template bytecode caching Signed-off-by: Dan McGee --- settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/settings.py b/settings.py index 5b2195cb..ba6c68ee 100644 --- a/settings.py +++ b/settings.py @@ -183,6 +183,7 @@ TEMPLATE_LOADERS = ( ('django.template.loaders.cached.Loader', TEMPLATE_LOADERS), ) + JINJA2_BYTECODE_CACHE_ENABLE = True # Enable the debug toolbar if requested if DEBUG_TOOLBAR: -- cgit v1.2.3-54-g00ecf 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 From e5e5632fb3432e153d0677b4bf145bc2eb72ef65 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 18 Oct 2014 15:25:30 -0500 Subject: Break out Jinja2-specific template helpers Signed-off-by: Dan McGee --- packages/templatetags/jinja2.py | 98 +++++++++++++++++++++++++++++++++ packages/templatetags/package_extras.py | 95 +------------------------------- 2 files changed, 99 insertions(+), 94 deletions(-) create mode 100644 packages/templatetags/jinja2.py diff --git a/packages/templatetags/jinja2.py b/packages/templatetags/jinja2.py new file mode 100644 index 00000000..263fc156 --- /dev/null +++ b/packages/templatetags/jinja2.py @@ -0,0 +1,98 @@ +from urllib import urlencode, quote as urlquote, unquote +from django.utils.html import escape +from django_jinja import library +from main.templatetags import pgp + + +@library.filter +def url_unquote(original_url): + try: + url = original_url + if isinstance(url, unicode): + url = url.encode('ascii') + url = unquote(url).decode('utf-8') + return url + except UnicodeError: + return original_url + + +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) + return "%s?%s" % (url, data) + + +@library.global_function +def maintainer_link(user): + if user: + # TODO don't hardcode + title = escape('View packages maintained by ' + user.get_full_name()) + return '%s' % ( + user.username, + title, + user.get_full_name(), + ) + return '' + + +@library.global_function +def packager_link(user): + if user: + # TODO don't hardcode + title = escape('View packages packaged by ' + user.get_full_name()) + return '%s' % ( + user.username, + title, + user.get_full_name(), + ) + return '' + + +@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 = ( + "https://projects.archlinux.org/svntogit/%s.git/%s/trunk?" + "h=packages/%s") + return linkbase % tuple(urlquote(part.encode('utf-8')) for part in parts) + + +@library.global_function +def wiki_link(package): + url = "https://wiki.archlinux.org/index.php/Special:Search" + data = { + 'search': package.pkgname, + } + return link_encode(url, data) + + +@library.global_function +def bugs_list(package): + url = "https://bugs.archlinux.org/" + data = { + 'project': package.repo.bugs_project, + 'cat[]': package.repo.bugs_category, + 'string': package.pkgname, + } + return link_encode(url, data) + + +@library.global_function +def bug_report(package): + url = "https://bugs.archlinux.org/newtask" + data = { + 'project': package.repo.bugs_project, + 'product_category': package.repo.bugs_category, + 'item_summary': '[%s] PLEASE ENTER SUMMARY' % package.pkgname, + } + return link_encode(url, data) + + +# vim: set ts=4 sw=4 et: diff --git a/packages/templatetags/package_extras.py b/packages/templatetags/package_extras.py index f6d6ee73..73a39092 100644 --- a/packages/templatetags/package_extras.py +++ b/packages/templatetags/package_extras.py @@ -1,38 +1,15 @@ -from urllib import urlencode, quote as urlquote, unquote +from urllib import urlencode try: from urlparse import parse_qs except ImportError: from cgi import parse_qs from django import template -from django.utils.html import escape -from django_jinja import library -from main.templatetags import pgp register = template.Library() -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) - return "%s?%s" % (url, data) - - -@library.filter -def url_unquote(original_url): - try: - url = original_url - if isinstance(url, unicode): - url = url.encode('ascii') - url = unquote(url).decode('utf-8') - return url - except UnicodeError: - return original_url - - class BuildQueryStringNode(template.Node): def __init__(self, sortfield): self.sortfield = sortfield @@ -82,74 +59,4 @@ def pkg_details_link(pkg, link_title=None, honor_flagged=False): return link % (pkg.get_absolute_url(), pkg.pkgname, link_content) -@library.global_function -def maintainer_link(user): - if user: - # TODO don't hardcode - title = escape('View packages maintained by ' + user.get_full_name()) - return '%s' % ( - user.username, - title, - user.get_full_name(), - ) - return '' - - -@library.global_function -def packager_link(user): - if user: - # TODO don't hardcode - title = escape('View packages packaged by ' + user.get_full_name()) - return '%s' % ( - user.username, - title, - user.get_full_name(), - ) - return '' - - -@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 = ( - "https://projects.archlinux.org/svntogit/%s.git/%s/trunk?" - "h=packages/%s") - return linkbase % tuple(urlquote(part.encode('utf-8')) for part in parts) - - -@library.global_function -def wiki_link(package): - url = "https://wiki.archlinux.org/index.php/Special:Search" - data = { - 'search': package.pkgname, - } - return link_encode(url, data) - - -@library.global_function -def bugs_list(package): - url = "https://bugs.archlinux.org/" - data = { - 'project': package.repo.bugs_project, - 'cat[]': package.repo.bugs_category, - 'string': package.pkgname, - } - return link_encode(url, data) - - -@library.global_function -def bug_report(package): - url = "https://bugs.archlinux.org/newtask" - data = { - 'project': package.repo.bugs_project, - 'product_category': package.repo.bugs_category, - 'item_summary': '[%s] PLEASE ENTER SUMMARY' % package.pkgname, - } - return link_encode(url, data) - # vim: set ts=4 sw=4 et: -- cgit v1.2.3-54-g00ecf From 122302e9e5fb9752a942abe5691ad3dd6d186196 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 18 Oct 2014 15:36:56 -0500 Subject: Move maintainer/packager link code back into template Signed-off-by: Dan McGee --- packages/templatetags/jinja2.py | 26 -------------------------- templates/packages/details.html.jinja | 14 ++++++++------ 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/packages/templatetags/jinja2.py b/packages/templatetags/jinja2.py index 263fc156..22f9914b 100644 --- a/packages/templatetags/jinja2.py +++ b/packages/templatetags/jinja2.py @@ -24,32 +24,6 @@ def link_encode(url, query): return "%s?%s" % (url, data) -@library.global_function -def maintainer_link(user): - if user: - # TODO don't hardcode - title = escape('View packages maintained by ' + user.get_full_name()) - return '%s' % ( - user.username, - title, - user.get_full_name(), - ) - return '' - - -@library.global_function -def packager_link(user): - if user: - # TODO don't hardcode - title = escape('View packages packaged by ' + user.get_full_name()) - return '%s' % ( - user.username, - title, - user.get_full_name(), - ) - return '' - - @library.global_function def pgp_key_link(key_id, link_text=None): return pgp.pgp_key_link(key_id, link_text) diff --git a/templates/packages/details.html.jinja b/templates/packages/details.html.jinja index 7ca5629c..52d13f14 100644 --- a/templates/packages/details.html.jinja +++ b/templates/packages/details.html.jinja @@ -149,11 +149,10 @@ Maintainers: {% with maints = pkg.maintainers %} - {% if maints %} - {% for m in maints %} - {{ maintainer_link(m)|safe }}
    - {% endfor %} - {% else %}Orphan{% endif %} + {% if maints %}{% for m in maints %} + {{ m.get_full_name() }}
    + {% endfor %}{% else %}Orphan{% endif %} {% endwith %} @@ -164,7 +163,10 @@ {{ pkg.installed_size|filesizeformat }} Last Packager: - {% with pkgr = pkg.packager %}{% if pkgr %}{{ packager_link(pkgr)|safe }}{% else %}{{ pkg.packager_str }}{% endif %}{% endwith %} + {% with pkgr = pkg.packager %}{% if pkgr %} + {{ pkgr.get_full_name() }} + {% else %}{{ pkg.packager_str }}{% endif %}{% endwith %} Build Date: {{ pkg.build_date|date("DATETIME_FORMAT") }} UTC -- cgit v1.2.3-54-g00ecf From 0e90423fc09f53317992bbb024e82ef65728aa11 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 18 Oct 2014 17:25:21 -0500 Subject: Add possible optimization as a TODO for later --- packages/models.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/models.py b/packages/models.py index dd69e7d3..03f03422 100644 --- a/packages/models.py +++ b/packages/models.py @@ -379,6 +379,13 @@ def get_best_satisfier(self): given criteria. It will not search provisions, but will find packages named and matching repo characteristics if possible.''' pkgs = Package.objects.normal().filter(pkgname=self.name) + # TODO: this may in fact be faster- select only the fields we know will + # actually get used, saving us some bandwidth and hopefully query + # construction time. However, reality hasn't quite proved it out yet. + #pkgs = Package.objects.select_related('repo', 'arch').only( + # 'id', 'pkgname', 'epoch', 'pkgver', 'pkgrel', + # 'repo__id', 'repo__name', 'repo__testing', 'repo__staging', + # 'arch__id', 'arch__name').filter(pkgname=self.name) if not self.pkg.arch.agnostic: # make sure we match architectures if possible arches = self.pkg.applicable_arches() -- cgit v1.2.3-54-g00ecf