Commit 94365a58 authored by eric's avatar eric

Display 10 latest commits from the 4 relearn projects

Includes 4 api calls, I hope it doesn’t make the site too slow.
parent a90cda52
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This file is part of gitcal and is © the contributors, listed in README.txt
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
Expects a visual culture style git api,
returns Ical Calendars of the commits
Dependency: vobject
"""
import json
from urllib2 import urlopen
from relearn.settings import API_PATH
def get_api(*args):
url = API_PATH + '/'.join(args)
res = urlopen(url)
dict = json.loads(res.read())
res.close
return dict
def commits(repo_slug):
repo = get_api(repo_slug)
return repo['commits']
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This file is part of gitcal and is © the contributors, listed in README.txt
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
"""
from django.conf.urls.defaults import patterns, url
urlpatterns = patterns('gitcal.views',
url(r'(?P<repo_slug>[\w\.\-_]+)\.ics$', 'render'),
)
from datetime import datetime
from etherpadlite.models import Pad, PadAuthor, PadServer
from django.contrib.auth.models import AnonymousUser
from gitcommits.models import commits
def pads(request):
hash = {}
......@@ -19,3 +22,22 @@ def pads(request):
hash['author'] = author
hash['pads'] = Pad.objects.all()
return hash
def filter_commits(commits):
filtered_commits = []
i = 0
for commit in commits:
if "Merge branch '" in commit['message']:
continue
commit['commit_time'] = datetime.fromtimestamp(commit['commit_time'])
commit['repo_name'] = commit['repo_name'].replace('osp.', '')
filtered_commits.append(commit)
i += 1
if i == 10:
break
return filtered_commits
def compose_commits(request):
commit_stream = commits("osp.relearn.off-grid") + commits("osp.relearn.gesturing-paths") + commits("osp.relearn.be") + commits("osp.relearn.can-it-scale-to-the-universe")
commit_stream.sort(reverse=True, key=lambda c: c['commit_time'])
return { 'commits' : filter_commits(commit_stream) }
API_PATH = 'http://osp.constantvzw.org/api/'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.', # Add one of postgresql_psycopg2, mysql, sqlite3, oracle
......@@ -9,3 +12,8 @@ DATABASES = {
}
}
EMAIL_HOST = ''
EMAIL_PORT = 587
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = True
\ No newline at end of file
......@@ -4,6 +4,8 @@ import django.conf.global_settings as DEFAULT_SETTINGS
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
API_PATH = 'http://osp.constantvzw.org/api/'
DEBUG = True
TEMPLATE_DEBUG = DEBUG
......@@ -109,6 +111,7 @@ TEMPLATE_DIRS = (
TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + (
"relearn.context_processors.pads",
"relearn.context_processors.compose_commits",
)
INSTALLED_APPS = (
......
......@@ -68,6 +68,14 @@
</form>
{% endcomment %}
{% endif %}
<h2>What we say</h2>
<p>The latest 10 commits, excluding the merges. There is a delay of an hour…</p>
{% for commit in commits %}
<h3>{{ commit.repo_name }}</h3>
<p class='commit-message'>{{ commit.message|urlize|linebreaksbr }}</p>
<p>By <span class='commit-author'>{{ commit.author }}</span> on <span class='commit-date'>{{ commit.commit_time }}</span></p>
{% endfor %}
</div>
</div>
</body>
......
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