Created
March 18, 2012 09:31
-
-
Save tiramiseb/2070169 to your computer and use it in GitHub Desktop.
Redmine connection for gtimelog (mod_python/PSP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
REDMINE_URL = 'https://www.some.url.com/redmine' | |
DEFAULT_ENTRIES = [ | |
u'Arrived', | |
u'Break**', | |
u'Lunch**', | |
u'Personal stuff***' | |
] | |
############################################################################### | |
import urllib | |
import xml.etree.ElementTree | |
import urlparse | |
_GET = dict(urlparse.parse_qsl(req.subprocess_env['QUERY_STRING'])) | |
if _GET.has_key('key'): | |
issuesurl = '%s/issues.xml?key=%s&limit=1000' % (REDMINE_URL, _GET['key']) | |
elif _GET.has_key('username') and _GET.has_key('password'): | |
issuesurl = '%s/issues.xml?limit=1000' % REDMINE_URL.replace('https://', 'https://%s:%s@' % (_GET['username'], _GET['password'])) | |
else: | |
issuesurl = None | |
entries = [(u'/', i) for i in DEFAULT_ENTRIES] | |
if issuesurl: | |
try: | |
issuesconn = urllib.urlopen(issuesurl) | |
issueslist = xml.etree.ElementTree.parse(issuesconn) | |
for issue in issueslist.findall('issue'): | |
project = unicode(issue.find('project').get('name')) | |
subject = unicode(issue.find('subject').text) | |
entries.append((project, subject)) | |
issuesconn.close() | |
except: | |
entries.append(('/', 'PROBLEM DOWNLOADING ISSUES')) | |
entries.append(('/', 'CHECK AUTHENTICATION')) | |
else: | |
entries.append(('/', 'NEED AUTHENTICATION')) | |
req.content_type='text/plain;charset=utf-8' | |
for entry in entries: | |
req.write('%s: %s' % (entry[0].encode('utf-8'), entry[1].encode('utf-8'))) | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment