Permalink
Browse files

Merge pull request #953 from groovecoder/remove-webtrends

Remove webtrends
  • Loading branch information...
2 parents ee23bb8 + 091bfb4 commit 70e6d8974730f47ddd6a3fd32710c5a03e106667 @darkwing darkwing committed Mar 25, 2013
View
@@ -1,24 +0,0 @@
-from django.db import transaction
-
-import cronjobs
-
-from dashboards.models import PERIODS, WikiDocumentVisits
-
-
-@cronjobs.register
-def reload_wiki_traffic_stats():
- transaction.enter_transaction_management()
- transaction.managed(True)
-
- for period, _ in PERIODS:
- try:
- WikiDocumentVisits.reload_period_from_json(
- period, WikiDocumentVisits.json_for(period))
- except:
- transaction.rollback()
- raise
- else:
- transaction.commit()
-
- # Nice but not necessary when the process is about to exit:
- transaction.leave_transaction_management()
View
@@ -30,22 +30,6 @@ class StatsIOError(IOError):
"""An error communicating with WebTrends"""
-def period_dates():
- """Return when each period begins and ends, relative to now.
-
- Return values are in the format WebTrends likes: "2010m01d30" or
- "current_day-7".
-
- """
- # WebTrends' server apparently runs in UTC, FWIW.
- yesterday = 'current_day-1' # Start at yesterday so we get a full week of
- # data.
- return {THIS_WEEK: ('current_day-7',
- yesterday),
- ALL_TIME: (settings.WEBTRENDS_EPOCH.strftime('%Ym%md%d'),
- yesterday)}
-
-
class WikiDocumentVisits(ModelBase):
"""Web stats for Knowledge Base Documents"""
@@ -116,27 +100,3 @@ def _visit_counts(cls, json_data):
'document: %s' % url)
counts[doc.pk] = visits
return counts
-
- @classmethod
- def json_for(cls, period):
- """Return the JSON-formatted WebTrends stats for the given period.
-
- Make one attempt to fetch and reload the data. If something fails, it's
- the caller's responsibility to retry.
-
- """
- auth_handler = HTTPBasicAuthHandler()
- auth_handler.add_password(realm=settings.WEBTRENDS_REALM,
- uri=settings.WEBTRENDS_WIKI_REPORT_URL,
- user=settings.WEBTRENDS_USER,
- passwd=settings.WEBTRENDS_PASSWORD)
- opener = build_opener(auth_handler)
- start, end = period_dates()[period]
- url = (settings.WEBTRENDS_WIKI_REPORT_URL +
- '&start_period=%s&end_period=%s' % (start, end))
- try:
- # TODO: A wrong username or password results in a recursion depth
- # error.
- return opener.open(url).read()
- except IOError, e:
- raise StatsIOError(*e.args)
@@ -107,16 +107,3 @@ def test_good_visit_count(self):
'"measures":{"Visits":213817.0,"Views":595329.0,"Average Time '
'Viewed":25.0},"SubRows":null}}}}}'
% ((settings.LANGUAGE_CODE,) * 2)))
-
- @patch_object(settings._wrapped, 'WEBTRENDS_WIKI_REPORT_URL',
- 'https://localhost:123654/nonexistent')
- def test_networking_failure(self):
- """Assert a StatsIOError is thrown when networking fails."""
- self.assertRaises(StatsIOError, WikiDocumentVisits.json_for, THIS_WEEK)
-
- # This takes 14 seconds and hits the WebTrends server, for which you might
- # not have credentials. If you have credentials and want to test the
- # networking, uncomment this.
- # def test_networking(self):
- # WikiDocumentVisits.reload_period_from_json(
- # THIS_WEEK, WikiDocumentVisits.json_for(THIS_WEEK))
Oops, something went wrong.

0 comments on commit 70e6d89

Please sign in to comment.