Permalink
Browse files

Make the data synchronising happen async

  • Loading branch information...
1 parent 79c3cb5 commit 55bc84abbf4b4866b390e63d65682df92e057168 @meldra committed Aug 6, 2012
Showing with 28 additions and 12 deletions.
  1. +9 −0 README.md
  2. +19 −12 brain/views.py
View
9 README.md
@@ -23,11 +23,20 @@ Brief, and possibly incomplete at this point:
(eg, for ubuntu/debian: `sudo apt-get install python-django`)
* Get the Libravatar python module
(eg, `sudo pip install pyLibravatar` or `sudo apt-get instal python-libravatar`)
+* Get the djutils module
+ (`sudo pip install djutils`)
* Clone this repository into a directory somewhere
* Setup Mailman to output weekly archives with the file format like:
`<yourmailmanlisturl>Week-of-Mon-20120716.txt`
* Set up your settings.py as per any other django site
* Add `'brain',` to the apps in the settings.py
+* Add to the bottom of your settings.py:
+`# Mailman baseurl
+# Remember the trailing slash!
+MAILMAN_BASEURL = 'https://<your whereis mbox>
+
+# Url to get a json response with directory info for alias mapping
+DIRECTORY_JSON = '<url to some json with names, email, phone, etc details).js'`
* To the bottom of your settings.py, add the <yourmailmanlisturl> portion
of the above url format. Remember the trailing slash!
* If you don't want this in debug mode, make that change to settings.py
View
31 brain/views.py
@@ -11,7 +11,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with WasWhereWhen. If not, see <http://www.gnu.org/licenses/>.
#
-import calendar, mailbox, email.utils, urllib2, simplejson, re
+import calendar, mailbox, email.utils, urllib2, simplejson, re, djutils.decorators
from django.conf import settings
from django.shortcuts import render_to_response
from django.template import Template
@@ -32,6 +32,17 @@
withyear = False
aliascachetimer = date.today()
+@djutils.decorators.async
+def load_data_async(year, month, day):
+ global aliascachetimer
+ try:
+ aliascount = Alias.objects.count()
+ except:
+ raise Exception("The db models have not been sync'd yet. Please sync them first.")
+ if settings.DIRECTORY_JSON and aliascachetimer < date.today() or settings.DIRECTORY_JSON and aliascount == 0:
+ aliascachetimer = resyncaliases()
+ syncmbox(year, month, day)
+
def monday(date_obj, weekday):
day = datetime.combine(date_obj, time())
@@ -410,31 +421,27 @@ def syncmbox(year, month, day):
dayname = d.weekday()
while True:
+ syncmbox = mbox(d, dayname, False)
d = d - timedelta(7)
- mbox = mbox(d, dayname, False)
- if mbox == False:
+ if syncmbox == False:
break
return True
def index(request, year=0, month=0, day=0):
now = datetime.now()
- global aliascachetimer
-
- try:
- aliascount = Alias.objects.count()
- except:
- raise Exception("The db models have not been sync'd yet. Please sync them first.")
-
- if settings.DIRECTORY_JSON and aliascachetimer < date.today() or settings.DIRECTORY_JSON and aliascount == 0:
- aliascachetimer = resyncaliases()
cal = WhereisCalendar(calendar.SUNDAY)
day = int(day)
month = int(month)
year = int(year)
days = False
+ try:
+ load_data_async(year, month, day)
+ except:
+ raise
+
if month > 0 and month <= 12 and year > 0:
days = calendar.monthrange(year, month)

0 comments on commit 55bc84a

Please sign in to comment.