aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSlava Bacherikov <slava@bacher09.org>2012-08-14 02:48:53 +0300
committerSlava Bacherikov <slava@bacher09.org>2012-08-14 02:48:53 +0300
commite507bbbb1816188d6eed66cbb9fe742f1d888e67 (patch)
tree5f07d335c8a9ef6976eff3915c760bda5362d717
parentAdd spaceless to package_object template (diff)
downloadgentoo-packages-e507bbbb1816188d6eed66cbb9fe742f1d888e67.tar.gz
gentoo-packages-e507bbbb1816188d6eed66cbb9fe742f1d888e67.tar.bz2
gentoo-packages-e507bbbb1816188d6eed66cbb9fe742f1d888e67.zip
Add link to maintainers packages in changelog
-rw-r--r--gpackages/apps/packages/changelog_highlight.py43
-rw-r--r--gpackages/apps/packages/models.py2
-rw-r--r--gpackages/apps/packages/templatetags/packages.py2
3 files changed, 45 insertions, 2 deletions
diff --git a/gpackages/apps/packages/changelog_highlight.py b/gpackages/apps/packages/changelog_highlight.py
new file mode 100644
index 0000000..69cce15
--- /dev/null
+++ b/gpackages/apps/packages/changelog_highlight.py
@@ -0,0 +1,43 @@
+from package_info.generic_metadata.changelog_highlight import Email, \
+ ChangelogHtmlFormater, ChangelogLexer, ChangelogStyle, highlight
+
+from django.core.urlresolvers import reverse
+from django.core.urlresolvers import NoReverseMatch
+
+def maintainer_link_by_email(email):
+ from . import models
+ try:
+ obj = models.MaintainerModel.objects.get(email = email)
+ url = reverse('packages', kwargs = {'maintainer' : obj.pk})
+ except (models.MaintainerModel.DoesNotExist, NoReverseMatch):
+ return None
+ else:
+ return url
+
+
+class ChangelogHtmlFormaterWithLinks(ChangelogHtmlFormater):
+
+ def __init__(self, *args, **kwargs):
+ super(ChangelogHtmlFormaterWithLinks, self).__init__(*args, **kwargs)
+ self._maintainer_url = {}
+
+ def token_decorate(self, token, value):
+ if token == Email:
+ if value in self._maintainer_url:
+ return self._maintainer_url[value]
+ url = maintainer_link_by_email(value)
+ if url is not None:
+ name, domain = value.split('@')
+ nvalue = '<a href="{1}" class="defcolor">{0}</a>'. \
+ format(name, url)
+ self._maintainer_url[value] = nvalue
+ return nvalue
+
+ value = super(ChangelogHtmlFormaterWithLinks, self). \
+ token_decorate(token, value)
+ return value
+
+def changelog_highlight(text):
+ "Shortcut for generating highlighted changelog html output"
+ return highlight(text, ChangelogLexer(),
+ ChangelogHtmlFormaterWithLinks(style = ChangelogStyle))
diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
index f1a56d0..1e2cac5 100644
--- a/gpackages/apps/packages/models.py
+++ b/gpackages/apps/packages/models.py
@@ -16,7 +16,7 @@ from package_info.validators import validate_url, validate_email, \
from package_info.parse_cp import VersionParse
from django.utils.html import urlize, linebreaks
-from package_info.generic_metadata.changelog_highlight import changelog_highlight
+from .changelog_highlight import changelog_highlight
from django.utils.safestring import mark_safe
from django.core.cache import cache
diff --git a/gpackages/apps/packages/templatetags/packages.py b/gpackages/apps/packages/templatetags/packages.py
index 212cc52..2efbb69 100644
--- a/gpackages/apps/packages/templatetags/packages.py
+++ b/gpackages/apps/packages/templatetags/packages.py
@@ -1,7 +1,6 @@
from django.utils.safestring import mark_safe
from django import template
from django.core.cache import cache
-from package_info.generic_metadata.changelog_highlight import changelog_highlight
register = template.Library()
@@ -9,6 +8,7 @@ from ..models import RepositoryModel, EbuildModel, UseFlagDescriptionModel
from ..views import arches
from ..forms import ArchChoiceForm, FilteringForm
from ..utils import license_urlize
+from ..changelog_highlight import changelog_highlight
from generic.utils import inclusion_cached_tag
def last_updated_key():