Fix Bug 1359037 - Provide some syndication feature to Nightly release notes

This commit is contained in:
Kohei Yoshino 2017-05-09 02:08:47 -04:00
Родитель 024ee2ac12
Коммит 0ee0317de3
5 изменённых файлов: 110 добавлений и 2 удалений

Просмотреть файл

@ -0,0 +1,32 @@
{# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. -#}
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>{{ _('Firefox Nightly Notes') }}</title>
<subtitle>{{ _('Firefox Nightly gets a new version every day and as a consequence, the release notes for the Nightly channel are updated continuously to reflect features that have reached sufficient maturity to benefit from community feedback and bug reports.') }}</subtitle>
<author>
<name>{{ _('Mozilla') }}</name>
</author>
<id>{{ url('firefox.nightly.notes.feed')|absolute_url }}</id>
<link rel="self" type="application/atom+xml" href="{{ url('firefox.nightly.notes.feed')|absolute_url }}"/>
<link rel="alternate" type="text/html" href="{{ url('firefox.notes', channel='nightly')|absolute_url }}"/>
<icon>{{ static('img/firefox/nightly/favicon.png')|absolute_url }}</icon>
<updated>{{ notes[0].modified.isoformat() }}</updated>
{% for note in notes %}
<entry>
<title>{{ note.note|markdown|striptags|truncate(100) }}</title>
<id>{{ note.link|absolute_url }}</id>
<link rel="alternate" type="text/html" href="{{ note.link|absolute_url }}"/>
<updated>{{ note.modified.isoformat() }}</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
{{ note.version }} / {{ note.tag }}
{%- if note.bug %} / <a href="https://bugzilla.mozilla.org/show_bug.cgi?id={{ note.bug }}">{{ _('Bug %d')|format(note.bug) }}</a>{% endif %}
{{ note.note|markdown|safe }}
</div>
</content>
</entry>
{% endfor %}
</feed>

Просмотреть файл

@ -3,3 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. #}
{% extends "firefox/releases/release-notes.html" %}
{% block extrahead %}
<link rel="alternate" type="application/atom+xml" title="{{ _('Firefox Nightly Notes Feed') }}" href="{{ url('firefox.nightly.notes.feed') }}">
{% endblock %}

Просмотреть файл

@ -106,6 +106,8 @@ urlpatterns = (
# Release notes
url('^firefox/(?:%s/)?(?:%s/)?notes/$' % (platform_re, channel_re),
bedrock.releasenotes.views.latest_notes, name='firefox.notes'),
url('^firefox/nightly/notes/feed/$',
bedrock.releasenotes.views.nightly_feed, name='firefox.nightly.notes.feed'),
url('firefox/(?:latest/)?releasenotes/$', bedrock.releasenotes.views.latest_notes,
{'product': 'firefox'}),
url('^firefox/(?:%s/)?system-requirements/$' % channel_re,

Просмотреть файл

@ -1,6 +1,8 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from dateutil.parser import parse as date_parse
from django.core.cache import caches
from django.http import Http404
from django.test.client import RequestFactory
@ -11,7 +13,7 @@ from mock import patch, Mock
from nose.tools import eq_, ok_
from pathlib2 import Path
from pyquery import PyQuery as pq
from rna.models import Release
from rna.models import Release, Note
from bedrock.firefox.firefox_details import FirefoxDesktop
from bedrock.mozorg.tests import TestCase
@ -252,6 +254,48 @@ class TestRNAViews(TestCase):
eq_(views.check_url('Firefox', '42.0'),
'/en-US/firefox/42.0/system-requirements/')
@patch('bedrock.releasenotes.views.get_list_or_404')
def test_nightly_feed(self, get_list_or_404):
"""Nightly Notes feed should be served with public changes"""
release_1 = Mock()
release_1.version = '55.0a1'
release_1.is_public = True
release_1.release_date = date_parse('2017-03-06T00:00:00')
release_1.notes.return_value = ([
Note(id=1, tag='New', note='New 1', is_public=True,
modified=date_parse('2017-04-20T13:27:28')),
Note(id=2, tag='New', note='New 2', is_public=True,
modified=date_parse('2017-04-20T13:28:32')),
Note(id=11, tag='Changed', note='Change 1', is_public=True,
modified=date_parse('2017-04-20T13:27:50')),
Note(id=12, tag='Changed', note='Change 2', is_public=True,
modified=date_parse('2017-04-20T13:28:03')),
Note(id=13, tag='Changed', note='Change 3', is_public=False,
modified=date_parse('2017-04-20T13:28:16')),
], [
Note(id=21, tag='', note='Known issue 1', is_public=True,
modified=date_parse('2017-04-20T13:30:12')),
])
release_2 = Mock()
release_2.version = '56.0a1'
release_2.is_public = True
release_2.release_date = date_parse('2017-05-08T00:00:00')
release_2.notes.return_value = ([
Note(id=31, tag='New', note='New 1', is_public=True,
modified=date_parse('2017-05-08T13:27:28')),
], [])
get_list_or_404.return_value = [release_1, release_2]
views.nightly_feed(self.request)
eq_(len(self.last_ctx['notes']), 5)
eq_(self.last_ctx['notes'][0].id, 31)
eq_(self.last_ctx['notes'][1].id, 2)
eq_(self.last_ctx['notes'][2].id, 12)
eq_(self.last_ctx['notes'][3].id, 11)
eq_(self.last_ctx['notes'][4].id, 1)
class TestReleaseNotesIndex(TestCase):
pd_cache = caches['product-details']

Просмотреть файл

@ -6,7 +6,7 @@ import re
from django.conf import settings
from django.db.models import Q
from django.http import Http404, HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.shortcuts import get_object_or_404, get_list_or_404
from bedrock.base.urlresolvers import reverse
from lib import l10n_utils
@ -234,3 +234,29 @@ def releases_index(request, product):
request, '{product}/releases/index.html'.format(product=product.lower()),
{'releases': sorted(releases.items(), reverse=True)}
)
def nightly_feed(request):
"""Serve an Atom feed with the latest changes in Firefox Nightly"""
notes = []
query = Q(product='Firefox', channel='Nightly')
releases = sorted(get_list_or_404(Release, query),
key=lambda x: x.release_date, reverse=True)[0:5]
for release in releases:
if release.is_public:
link = reverse('firefox.desktop.releasenotes',
args=(release.version, 'release'))
for note in release.notes()[0]:
if note.is_public and note.tag:
note.link = link + '#note-' + str(note.id)
note.version = release.version
notes.append(note)
# Sort by date in descending order
notes = sorted(notes, key=lambda x: x.modified, reverse=True)
return l10n_utils.render(request, 'firefox/releases/nightly-feed.xml',
{'notes': notes},
content_type='application/atom+xml')