diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-04-15 01:40:48 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-04-15 01:40:48 -0400 |
commit | cdff1a234be0d625c5c824707dbae32ffa6a76dd (patch) | |
tree | a9e029f2a98ad72e64d9e09a922ec39ab502a75b /packages | |
parent | f18a6c809f45e71175ced6050d7e57bf4e7e89ba (diff) | |
parent | 90873ef7de4bf842fbf6971836a373c555cfcbaa (diff) |
Merge branch 'master-nomake'
Diffstat (limited to 'packages')
-rw-r--r-- | packages/models.py | 7 | ||||
-rw-r--r-- | packages/templatetags/jinja2.py | 92 | ||||
-rw-r--r-- | packages/templatetags/package_extras.py | 114 | ||||
-rw-r--r-- | packages/views/__init__.py | 4 | ||||
-rw-r--r-- | packages/views/search.py | 6 |
5 files changed, 109 insertions, 114 deletions
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 @@ class RelatedToBase(models.Model): 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() diff --git a/packages/templatetags/jinja2.py b/packages/templatetags/jinja2.py new file mode 100644 index 00000000..a07f87bd --- /dev/null +++ b/packages/templatetags/jinja2.py @@ -0,0 +1,92 @@ +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 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 = ("abslibre", operation, package.repo.name.lower(), package.pkgbase) + linkbase = ( + "https://projects.parabola.nu/%s.git/%s/%s/%s") + return linkbase % tuple(urlquote(part.encode('utf-8')) for part in parts) + + +@library.global_function +def wiki_link(package): + url = "https://wiki.parabola.nu/index.php" + data = { + 'title': "Special:Search", + 'search': package.pkgname, + } + return link_encode(url, data) + +@library.global_function +def bugs_list(package): + if package.arch.name == 'mips64el': + project = "mips64el" + else: + project = "issue-tracker" + url = "https://labs.parabola.nu/projects/%s/search" % project + data = { + 'titles_only': '1', + 'issues': '1', + 'q': package.pkgname, + } + return link_encode(url, data) + + +@library.global_function +def bug_report(package): + url = "https://labs.parabola.nu/projects/" + if package.arch.name == 'mips64el': + url = url + "mips64el/issues/new" + else: + url = url + "issue-tracker/issues/new" + data = { + 'issue[subject]': '[%s] PLEASE ENTER SUMMARY' % package.pkgname, + } + return link_encode(url, data) + +@library.global_function +def flag_unfree(package): + url = "https://labs.parabola.nu/projects/" + if package.arch.name == 'mips64el': + url = url + "mips64el/issues/new" + else: + url = url + "issue-tracker/issues/new" + data = { + 'issue[tracker_id]': '4', # "freedom issue" + 'issue[priority_id]': '1', # "freedom issue" + 'issue[watcher_user_ids][]': '62', # "dev-list" + 'issue[subject]': '[%s] Please put your reasons here (register first if you haven\'t)' % 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 e022116a..73a39092 100644 --- a/packages/templatetags/package_extras.py +++ b/packages/templatetags/package_extras.py @@ -1,33 +1,13 @@ -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 - -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).replace('&', '&') - return "%s?%s" % (url, data) -@register.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 +register = template.Library() class BuildQueryStringNode(template.Node): @@ -79,94 +59,4 @@ 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: - # TODO don't hardcode - title = escape('View packages maintained by ' + user.get_full_name()) - return '<a href="/packages/?maintainer=%s" title="%s">%s</a>' % ( - user.username, - title, - user.get_full_name(), - ) - return '' - - -@register.simple_tag -def packager_link(user): - if user: - # TODO don't hardcode - title = escape('View packages packaged by ' + user.get_full_name()) - return '<a href="/packages/?packager=%s" title="%s">%s</a>' % ( - user.username, - title, - user.get_full_name(), - ) - return '' - - -@register.simple_tag -def scm_link(package, operation): - parts = ("abslibre", operation, package.repo.name.lower(), package.pkgbase) - linkbase = ( - "https://projects.parabola.nu/%s.git/%s/%s/%s") - return linkbase % tuple(urlquote(part.encode('utf-8')) for part in parts) - - -@register.simple_tag -def get_wiki_link(package): - url = "https://wiki.parabola.nu/index.php" - data = { - 'title': "Special:Search", - 'search': package.pkgname, - } - return link_encode(url, data) - -@register.simple_tag -def bugs_list(package): - if package.arch.name == 'mips64el': - project = "mips64el" - else: - project = "issue-tracker" - url = "https://labs.parabola.nu/projects/%s/search" % project - data = { - 'titles_only': '1', - 'issues': '1', - 'q': package.pkgname, - } - return link_encode(url, data) - - -@register.simple_tag -def bug_report(package): - url = "https://labs.parabola.nu/projects/" - if package.arch.name == 'mips64el': - url = url + "mips64el/issues/new" - else: - url = url + "issue-tracker/issues/new" - data = { - 'issue[subject]': '[%s] PLEASE ENTER SUMMARY' % package.pkgname, - } - return link_encode(url, data) - -@register.simple_tag -def flag_unfree(package): - url = "https://labs.parabola.nu/projects/" - if package.arch.name == 'mips64el': - url = url + "mips64el/issues/new" - else: - url = url + "issue-tracker/issues/new" - data = { - 'issue[tracker_id]': '4', # "freedom issue" - 'issue[priority_id]': '1', # "freedom issue" - 'issue[watcher_user_ids][]': '62', # "dev-list" - 'issue[subject]': '[%s] Please put your reasons here (register first if you haven\'t)' % package.pkgname, - } - return link_encode(url, data) - # vim: set ts=4 sw=4 et: diff --git a/packages/views/__init__.py b/packages/views/__init__.py index 1f8a0169..f3d64548 100644 --- a/packages/views/__init__.py +++ b/packages/views/__init__.py @@ -35,7 +35,7 @@ def opensearch(request): @require_safe -@cache_control(public=True, max_age=300) +@cache_control(public=True, max_age=613) def opensearch_suggest(request): search_term = request.GET.get('q', '') if search_term == '': @@ -55,7 +55,7 @@ def opensearch_suggest(request): 'pkgname', flat=True).order_by('pkgname').distinct()[:10] results = [search_term, list(names)] to_json = json.dumps(results, ensure_ascii=False) - cache.set(cache_key, to_json, 300) + cache.set(cache_key, to_json, 613) return HttpResponse(to_json, content_type='application/x-suggestions+json') diff --git a/packages/views/search.py b/packages/views/search.py index b3778172..0b776d79 100644 --- a/packages/views/search.py +++ b/packages/views/search.py @@ -45,6 +45,12 @@ class PackageSearchForm(forms.Form): [('', 'All'), ('unknown', 'Unknown')] + \ [(m.username, m.get_full_name()) for m in maints] + def exact_matches(self): + # only do exact match search if 'q' is sole parameter + if self.changed_data != ['q']: + return [] + return Package.objects.normal().filter(pkgname=self.cleaned_data['q']) + def parse_form(form, packages): if form.cleaned_data['repo']: |