Commit 38917c69 authored by Michal Čihař's avatar Michal Čihař

CSV dump of history

Only basic information is present so far, more might be added in future.

Fixes #763
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 966168dc
......@@ -9,6 +9,7 @@ Released on ? 2015.
* Improved support for PHP files.
* Ability to add ACL to anonymous user.
* Improved configurability of import_project command.
* Added CSV dump of history.
weblate 2.3
-----------
......
......@@ -4,7 +4,10 @@
<div class="panel panel-primary">
<div class="panel-heading">
<h4 class="panel-title">{% trans "History" %}</h4>
<h4 class="panel-title">
<a class="pull-right flip" href="{% url 'changes-csv' %}?{{ request.GET.urlencode }}" title="{% trans "Download all changes as CSV" %}"><i class="fa fa-download"></i></a>
{% trans "History" %}
</h4>
</div>
<div class="panel-body">
......
......@@ -31,6 +31,10 @@ class ChangesTest(ViewTestCase):
response = self.client.get(reverse('changes'))
self.assertContains(response, 'Resource update')
def test_basic_csv(self):
response = self.client.get(reverse('changes-csv'))
self.assertContains(response, 'timestamp,')
def test_filter(self):
response = self.client.get(
reverse('changes'),
......
......@@ -19,15 +19,16 @@
#
from django.views.generic.list import ListView
from django.http import Http404
from django.http import Http404, HttpResponse
from django.contrib import messages
from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext as _, activate
from django.db.models import Q
from weblate.trans.models.changes import Change
from weblate.trans.views.helper import get_project_translation
from weblate.lang.models import Language
from urllib import urlencode
import csv
class ChangesView(ListView):
......@@ -174,3 +175,32 @@ class ChangesView(ListView):
)
return result
class ChangesCSVView(ChangesView):
"""CSV renderer for changes view"""
paginate_by = None
def get(self, request, *args, **kwargs):
self.object_list = self.get_queryset()
# Always output in english
activate('en')
response = HttpResponse(content_type='text/csv; charset=utf-8')
response['Content-Disposition'] = 'attachment; filename=changes.csv'
writer = csv.writer(response)
# Add header
writer.writerow(('timestamp', 'action', 'user', 'url'))
for change in self.object_list.iterator():
writer.writerow((
change.timestamp.isoformat(),
change.get_action_display().encode('utf8'),
change.user.username if change.user else '',
change.get_absolute_url(),
))
return response
......@@ -27,7 +27,7 @@ from weblate.trans.feeds import (
TranslationChangesFeed, SubProjectChangesFeed,
ProjectChangesFeed, ChangesFeed, LanguageChangesFeed
)
from weblate.trans.views.changes import ChangesView
from weblate.trans.views.changes import ChangesView, ChangesCSVView
from weblate.sitemaps import SITEMAPS
import weblate.accounts.urls
......@@ -418,6 +418,11 @@ urlpatterns = patterns(
ChangesView.as_view(),
name='changes',
),
url(
r'^changes/csv/$',
ChangesCSVView.as_view(),
name='changes-csv',
),
# Notification hooks
url(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment