From: Magnus Hagander Date: Tue, 20 Jan 2015 21:49:30 +0000 (+0100) Subject: Add activity log and RSS feeds X-Git-Url: http://git.postgresql.org/gitweb/static/connections.php?a=commitdiff_plain;h=c80b7e1d58f3bac19a6df99ddf3d4bfc50e6a2ee;p=pgcommitfest2.git Add activity log and RSS feeds This somehow got dropped from the old site in a feature branch that was never merged... --- diff --git a/pgcommitfest/commitfest/feeds.py b/pgcommitfest/commitfest/feeds.py new file mode 100644 index 0000000..dc37924 --- /dev/null +++ b/pgcommitfest/commitfest/feeds.py @@ -0,0 +1,38 @@ +from django.contrib.syndication.views import Feed + +class ActivityFeed(Feed): + title = description = 'Commitfest Activity Log' + link = 'https://commitfest.postgresql.org/' + + def __init__(self, activity, cf, *args, **kwargs): + super(ActivityFeed, self).__init__(*args, **kwargs) + self.activity = activity + if cf: + self.cfid = cf.id + self.title = self.description = 'PostgreSQL Commitfest {0} Activity Log'.format(cf.name) + else: + self.cfid = None + + def items(self): + return self.activity + + def item_title(self, item): + if self.cfid: + return item['name'] + else: + return '{cfname}: {name}'.format(**item) + + def item_description(self, item): + if self.cfid: + return "
Patch: {name}
User: {by}
\n
{what}
".format(**item) + else: + return "
Commitfest: {cfname}
Patch: {name}
User: {by}
{what}
".format(**item) + + def item_link(self, item): + if self.cfid: + return 'https://commitfest.postgresql.org/{cfid}/{patchid}/'.format(cfid=self.cfid,**item) + else: + return 'https://commitfest.postgresql.org/{cfid}/{patchid}/'.format(**item) + + def item_pubdate(self, item): + return item['date'] diff --git a/pgcommitfest/commitfest/templates/activity.html b/pgcommitfest/commitfest/templates/activity.html new file mode 100644 index 0000000..a864eee --- /dev/null +++ b/pgcommitfest/commitfest/templates/activity.html @@ -0,0 +1,28 @@ +{%extends "base.html"%} +{%load commitfest %} +{%block contents%} + + + + + + +{%if not commitfest%}{%endif%} + + + + + +{%for a in activity %} + + + +{%if not commitfest%}{%endif%} + + + +{%endfor%} + +
TimeUserCommitFestPatchActivity
{{a.date}}{{a.by}}{{a.cfname}}{{a.name}}{{a.what}}
+ +{%endblock%} diff --git a/pgcommitfest/commitfest/templates/base.html b/pgcommitfest/commitfest/templates/base.html index 14be28b..e60f3a9 100644 --- a/pgcommitfest/commitfest/templates/base.html +++ b/pgcommitfest/commitfest/templates/base.html @@ -8,6 +8,7 @@ +{%if rss_alternate%} {%endif%}
@@ -24,6 +25,7 @@ Log in {%endif%} +{%if header_activity%}
  • {{header_activity}}
  • {%endif%}

    {{title}}

    diff --git a/pgcommitfest/commitfest/views.py b/pgcommitfest/commitfest/views.py index b04030b..f9ec991 100644 --- a/pgcommitfest/commitfest/views.py +++ b/pgcommitfest/commitfest/views.py @@ -1,7 +1,7 @@ from django.shortcuts import render_to_response, get_object_or_404 from django.http import HttpResponseRedirect, Http404, HttpResponseForbidden from django.template import RequestContext -from django.db import transaction +from django.db import transaction, connection from django.db.models import Q from django.contrib import messages from django.contrib.auth.decorators import login_required @@ -19,6 +19,7 @@ from models import CommitFest, Patch, PatchOnCommitFest, PatchHistory, Committer from forms import PatchForm, NewPatchForm, CommentForm, CommitFestFilterForm from forms import BulkEmailForm from ajax import doAttachThread +from feeds import ActivityFeed def home(request): commitfests = list(CommitFest.objects.all()) @@ -30,6 +31,50 @@ def home(request): 'opencf': opencf, 'inprogresscf': inprogresscf, 'title': 'Commitfests', + 'header_activity': 'Activity log', + 'header_activity_link': '/activity/', + }, context_instance=RequestContext(request)) + + +def activity(request, cfid=None, rss=None): + # Number of notes to fetch + if rss: + num = 50 + else: + num = 100 + + if cfid: + cf = get_object_or_404(CommitFest, pk=cfid) + + # Yes, we do string concatenation of the were clause. Because + # we're evil. And also because the number has been verified + # when looking up the cf itself, so nothing can be injected + # there. + extrafields = '' + where = 'WHERE poc.commitfest_id={0}'.format(cf.id) + else: + cf = None + extrafields = ',poc.commitfest_id AS cfid,cf.name AS cfname' + where = ' INNER JOIN commitfest_commitfest cf ON cf.id=poc.commitfest_id' + + sql = "SELECT ph.date, auth_user.username AS by, ph.what, p.id AS patchid, p.name{0} FROM commitfest_patchhistory ph INNER JOIN commitfest_patch p ON ph.patch_id=p.id INNER JOIN auth_user on auth_user.id=ph.by_id INNER JOIN commitfest_patchoncommitfest poc ON poc.patch_id=p.id {1} ORDER BY ph.date DESC LIMIT {2}".format(extrafields,where, num) + + curs = connection.cursor() + curs.execute(sql) + activity = [dict(zip([c[0] for c in curs.description],r)) for r in curs.fetchall()] + + if rss: + # Return RSS feed with these objects + return ActivityFeed(activity, cf)(request) + else: + # Return regular webpage + return render_to_response('activity.html', { + 'commitfest': cf, + 'activity': activity, + 'title': cf and 'Commitfest activity' or 'Global Commitfest activity', + 'rss_alternate': cf and '/{0}/activity.rss/'.format(cf.id) or '/activity.rss/', + 'rss_alternate_title': 'PostgreSQL Commitfest Activity Log', + 'breadcrumbs': cf and [{'title': cf.title, 'href': '/%s/' % cf.pk},] or None, }, context_instance=RequestContext(request)) def redir(request, what): @@ -114,6 +159,8 @@ def commitfest(request, cfid): 'grouping': sortkey==0, 'sortkey': sortkey, 'openpatchids': [p.id for p in patches if p.is_open], + 'header_activity': 'Activity log', + 'header_activity_link': 'activity/', }, context_instance=RequestContext(request)) def global_search(request): diff --git a/pgcommitfest/urls.py b/pgcommitfest/urls.py index ef1d38c..a715c71 100644 --- a/pgcommitfest/urls.py +++ b/pgcommitfest/urls.py @@ -7,8 +7,10 @@ admin.autodiscover() urlpatterns = patterns('', url(r'^$', 'commitfest.views.home'), + url(r'^activity(?P\.rss)?/', 'commitfest.views.activity'), url(r'^(\d+)/$', 'commitfest.views.commitfest'), url(r'^(open|inprogress)/$', 'commitfest.views.redir'), + url(r'^(?P\d+)/activity(?P\.rss)?/$', 'commitfest.views.activity'), url(r'^(\d+)/(\d+)/$', 'commitfest.views.patch'), url(r'^(\d+)/(\d+)/edit/$', 'commitfest.views.patchform'), url(r'^(\d+)/new/$', 'commitfest.views.newpatch'),