summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hyperkitty/api.py25
-rw-r--r--hyperkitty/lib/__init__.py20
-rw-r--r--hyperkitty/models.py2
-rw-r--r--hyperkitty/utils.py107
-rw-r--r--hyperkitty/views/accounts.py9
-rw-r--r--hyperkitty/views/api.py20
-rw-r--r--hyperkitty/views/list.py35
-rw-r--r--hyperkitty/views/message.py23
-rw-r--r--hyperkitty/views/pages.py26
-rw-r--r--hyperkitty/views/thread.py21
10 files changed, 147 insertions, 141 deletions
diff --git a/hyperkitty/api.py b/hyperkitty/api.py
index f28a1af..6c80f0d 100644
--- a/hyperkitty/api.py
+++ b/hyperkitty/api.py
@@ -1,14 +1,31 @@
#-*- 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 json
+import re
from djangorestframework.views import View
from django.conf.urls.defaults import url
from django.conf import settings
from django.http import HttpResponseNotModified, HttpResponse
-import json
-import re
from hyperkitty.lib import get_store
-from hyperkitty.utils import log
class EmailResource(View):
@@ -58,7 +75,7 @@ class SearchResource(View):
{'Content': re.compile(regex, re.IGNORECASE)}
]}
else:
- query_string = {field.capitalize():
+ query_string = {field.capitalize():
re.compile(regex, re.IGNORECASE)}
#print query_string, field, keyword
diff --git a/hyperkitty/lib/__init__.py b/hyperkitty/lib/__init__.py
index 710011a..0ae2a7f 100644
--- a/hyperkitty/lib/__init__.py
+++ b/hyperkitty/lib/__init__.py
@@ -1,13 +1,27 @@
#-*- 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 urllib
from hashlib import md5
import datetime
from django.conf import settings
-import kittystore
-
-from hyperkitty.utils import log
def gravatar_url(email):
diff --git a/hyperkitty/models.py b/hyperkitty/models.py
index c84ef51..10334d2 100644
--- a/hyperkitty/models.py
+++ b/hyperkitty/models.py
@@ -25,8 +25,6 @@ from django.conf import settings
from kittystore import get_store
-from hyperkitty.utils import log
-
class Rating(models.Model):
# @TODO: instead of list_address, user list model from kittystore?
diff --git a/hyperkitty/utils.py b/hyperkitty/utils.py
deleted file mode 100644
index 4579cd2..0000000
--- a/hyperkitty/utils.py
+++ /dev/null
@@ -1,107 +0,0 @@
-# -*- 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/>.
-#
-# Author: Aamir Khan <syst3m.w0rm@gmail.com>
-#
-
-import logging
-import traceback
-
-from django.conf import settings
-from django.core import mail
-from django.views.debug import ExceptionReporter, get_exception_reporter_filter
-
-LOG_FILE = 'hk.log'
-
-def log(level, *args, **kwargs):
- """Small wrapper around logger functions."""
- {
- 'debug': logger.debug,
- 'error': logger.error,
- 'exception': logger.exception,
- 'warn': logger.warn
- }[level](*args, **kwargs)
-
-
-class HyperKittyLogHandler(logging.Handler):
- """A custom HyperKitty log handler.
-
- If the request is passed as the first argument to the log record,
- request data will be provided in the email report.
- """
-
- def __init__(self, log_to_file=True, email_admins=True):
- logging.Handler.__init__(self)
- self.log_to_file = log_to_file
- self.email_admins = email_admins
-
- def emit(self, record):
- try:
- request = record.request
- subject = '%s (%s IP): %s' % (
- record.levelname,
- (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS
- and 'internal' or 'EXTERNAL'),
- record.getMessage()
- )
- filter = get_exception_reporter_filter(request)
- request_repr = filter.get_request_repr(request)
- except Exception:
- subject = '%s: %s' % (
- record.levelname,
- record.getMessage()
- )
- request = None
- request_repr = "Request repr() unavailable."
- subject = self.format_subject(subject)
-
- if record.exc_info:
- exc_info = record.exc_info
- stack_trace = '\n'.join(traceback.format_exception(*record.exc_info))
- else:
- exc_info = (None, record.getMessage(), None)
- stack_trace = 'No stack trace available'
-
- message = "%s\n\n%s" % (stack_trace, request_repr)
- reporter = ExceptionReporter(request, is_email=True, *exc_info)
- html_message = reporter.get_traceback_html()
-
- if self.email_admins:
- mail.mail_admins(subject, message, fail_silently=True, html_message=html_message)
-
- if self.log_to_file:
- log_file = open(LOG_FILE, 'a')
- log_file.write(message)
- log_file.close()
-
- def format_subject(self, subject):
- """
- Escape CR and LF characters, and limit length.
- RFC 2822's hard limit is 998 characters per line. So, minus "Subject: "
- the actual subject must be no longer than 989 characters.
- """
- formatted_subject = subject.replace('\n', '\\n').replace('\r', '\\r')
- return formatted_subject[:989]
-
-
-logger = None
-if not logger:
- logger = logging.getLogger('HyperKitty')
-
-if not logger.handlers:
- logger.addHandler(HyperKittyLogHandler(True, True))
diff --git a/hyperkitty/views/accounts.py b/hyperkitty/views/accounts.py
index 49d726f..26568e5 100644
--- a/hyperkitty/views/accounts.py
+++ b/hyperkitty/views/accounts.py
@@ -21,6 +21,7 @@
import re
import sys
+import logging
from django.conf import settings
from django.contrib import messages
@@ -40,10 +41,12 @@ from urllib2 import HTTPError
from urlparse import urlparse
from forms import RegistrationForm
-from hyperkitty.utils import log
from hyperkitty.lib import get_store
+logger = logging.getLogger(__name__)
+
+
def user_logout(request):
logout(request)
return redirect('user_login')
@@ -62,7 +65,7 @@ def user_login(request, template='login.html'):
password=request.POST.get('password'))
if user is not None:
- log('debug', user)
+ logger.debug(user)
if user.is_active:
login(request, user)
return redirect(next_var)
@@ -127,7 +130,7 @@ def user_registration(request):
password=form.cleaned_data['password1'])
if user is not None:
- log('debug', user)
+ logger.debug(user)
if user.is_active:
login(request, user)
return redirect('index')
diff --git a/hyperkitty/views/api.py b/hyperkitty/views/api.py
index d3c2260..c88923d 100644
--- a/hyperkitty/views/api.py
+++ b/hyperkitty/views/api.py
@@ -1,3 +1,22 @@
+#-*- 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 os
import json
@@ -15,7 +34,6 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger, Invali
from django.contrib.auth.decorators import (login_required,
permission_required,
user_passes_test)
-from hyperkitty.utils import log
def api(request):
diff --git a/hyperkitty/views/list.py b/hyperkitty/views/list.py
index a8cae9b..900b7f5 100644
--- a/hyperkitty/views/list.py
+++ b/hyperkitty/views/list.py
@@ -1,14 +1,31 @@
# -*- 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 os
import json
import urllib
-import django.utils.simplejson as simplejson
-
from calendar import timegm
from datetime import datetime, timedelta
-
from urlparse import urljoin
+
+import django.utils.simplejson as simplejson
from django.http import HttpResponse, HttpResponseRedirect
from django.template import RequestContext, loader
from django.conf import settings
@@ -18,10 +35,8 @@ from django.contrib.auth.decorators import (login_required,
user_passes_test)
from hyperkitty.models import Rating, Tag
-#from hyperkitty.lib.mockup import *
from hyperkitty.lib import get_months, get_store
from forms import *
-from hyperkitty.utils import log
# @TODO : Move this into settings.py
@@ -186,7 +201,7 @@ def list(request, mlist_fqdn=None):
month = '0%s' % month
day = msg.date.day
if day < 10:
- day = '0%s' % day
+ day = '0%s' % day
key = '%s%s%s' % (msg.date.year, month, day)
if key in dates:
dates[key] = dates[key] + 1
@@ -334,21 +349,21 @@ def search_keyword(request, mlist_fqdn, target, keyword, page=1):
threads = store.search_content(mlist_fqdn, keyword)
elif target.lower() == 'from':
threads = store.search_sender(mlist_fqdn, keyword)
-
+
return _search_results_page(request, mlist_fqdn, threads, 'Search', page)
def search_tag(request, mlist_fqdn, tag=None, page=1):
'''Returns emails having a particular tag'''
-
+
store = get_store(settings.KITTYSTORE_URL)
list_name = mlist_fqdn.split('@')[0]
-
+
try:
thread_ids = Tag.objects.filter(tag=tag)
except Tag.DoesNotExist:
thread_ids = {}
-
+
threads = []
for thread in thread_ids:
threads_tmp = store.get_messages_in_thread(mlist_fqdn, thread.threadid)
diff --git a/hyperkitty/views/message.py b/hyperkitty/views/message.py
index dd80709..18aab87 100644
--- a/hyperkitty/views/message.py
+++ b/hyperkitty/views/message.py
@@ -1,7 +1,26 @@
+#-*- 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 os
-import django.utils.simplejson as simplejson
+import django.utils.simplejson as simplejson
from django.http import HttpResponse, HttpResponseRedirect
from django.template import RequestContext, loader
from django.conf import settings
@@ -11,10 +30,8 @@ from django.contrib.auth.decorators import (login_required,
user_passes_test)
from hyperkitty.models import Rating
-#from hyperkitty.lib.mockup import *
from hyperkitty.lib import get_store
from forms import *
-from hyperkitty.utils import log
def index (request, mlist_fqdn, hashid):
diff --git a/hyperkitty/views/pages.py b/hyperkitty/views/pages.py
index c9d6e19..a61f17f 100644
--- a/hyperkitty/views/pages.py
+++ b/hyperkitty/views/pages.py
@@ -1,15 +1,31 @@
#-*- 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 os
import json
import urllib
-import django.utils.simplejson as simplejson
-
from calendar import timegm
from datetime import datetime, timedelta
-
from urlparse import urljoin
+
+import django.utils.simplejson as simplejson
from django.http import HttpResponse, HttpResponseRedirect
from django.template import RequestContext, loader
from django.conf import settings
@@ -19,10 +35,9 @@ from django.contrib.auth.decorators import (login_required,
user_passes_test)
from hyperkitty.models import Rating
-#from hyperkitty.lib.mockup import *
from hyperkitty.lib import get_store
from forms import *
-from hyperkitty.utils import log
+
def index(request):
t = loader.get_template('index.html')
@@ -33,7 +48,6 @@ def index(request):
store = get_store(request)
list_data = store.get_list_names()
- log("warn", repr(list_data))
c = RequestContext(request, {
'lists': list_data,
diff --git a/hyperkitty/views/thread.py b/hyperkitty/views/thread.py
index b5bf80a..cef8b58 100644
--- a/hyperkitty/views/thread.py
+++ b/hyperkitty/views/thread.py
@@ -1,3 +1,22 @@
+# -*- 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 datetime
import django.utils.simplejson as simplejson
@@ -13,11 +32,9 @@ from django.contrib.auth.decorators import (login_required,
from hyperkitty.models import Rating, Tag
#from hyperkitty.lib.mockup import *
from forms import *
-from hyperkitty.utils import log
from hyperkitty.lib import get_months, get_store
-
def thread_index (request, mlist_fqdn, threadid):
''' Displays all the email for a given thread identifier '''
list_name = mlist_fqdn.split('@')[0]