diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2012-10-22 15:50:22 +0200 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2012-10-22 15:50:22 +0200 |
commit | ec83ca078f90a2f5ede73ffa2666d7653b5c1d56 (patch) | |
tree | 0236c55618b4d8f6f077866e5b7f91b40c41840f /hyperkitty/lib | |
parent | dfa93dee5d6765ca85d7b333cc995108dd2c17d6 (diff) | |
download | hyperkitty-ec83ca078f90a2f5ede73ffa2666d7653b5c1d56.tar.gz hyperkitty-ec83ca078f90a2f5ede73ffa2666d7653b5c1d56.tar.xz hyperkitty-ec83ca078f90a2f5ede73ffa2666d7653b5c1d56.zip |
Add compatibility URLs for Pipermail
Diffstat (limited to 'hyperkitty/lib')
-rw-r--r-- | hyperkitty/lib/compat.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/hyperkitty/lib/compat.py b/hyperkitty/lib/compat.py new file mode 100644 index 0000000..cb0a864 --- /dev/null +++ b/hyperkitty/lib/compat.py @@ -0,0 +1,53 @@ +#-*- coding: utf-8 -*- +# Copyright (C) 1998-2012 by the Free Software Foundation, Inc. +# +# This file is part of HyperKitty. +# +# HyperKitty is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# HyperKitty 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 General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# HyperKitty. If not, see <http://www.gnu.org/licenses/>. +# + +import re +import datetime + +PORT_IN_URL = re.compile(':\d+$') + + +def get_list_by_name(list_name, store, request): + arch_list_names = store.get_list_names() + matching = [] + for name in arch_list_names: + if name[:name.index("@")] == list_name: + matching.append(name) + + if len(matching) == 0: # no candidate found + return None + if len(matching) == 1: # only one candidate + return store.get_list(matching[0]) + + # more than one result, try using the hostname + domain = request.get_host() + domain = PORT_IN_URL.sub('', domain) + list_fqdn = "%s@%s" % (list_name, domain) + if list_fqdn in matching: + return store.get_list(list_fqdn) + + # return the first match, arbitrarily + return store.get_list(matching[0]) + +def month_name_to_num(month_name): + """map month names to months numbers""" + today = datetime.date.today() + months = dict( (today.replace(month=num).strftime('%B'), num) + for num in range(1, 12) ) + return months[month_name] |