Merge branch 'master' of github.com:samuelclay/NewsBlur

* 'master' of github.com:samuelclay/NewsBlur:
  Fixing offsets in river of news.
  Adding ciphering to usernames in log, so I can finally take screenshots of the most colorful logs of all time.
This commit is contained in:
Samuel Clay 2011-12-20 11:50:07 -08:00
commit 66078eb872
3 changed files with 17 additions and 3 deletions

View file

@ -511,7 +511,8 @@ def load_river_stories(request):
# Fetch all stories at and before the page number.
# Not a single page, because reading stories can move them up in the unread order.
# `read_stories_count` is an optimization, works best when all 25 stories before have been read.
limit = limit * page - read_stories_count
offset = (page-1) * limit - read_stories_count
limit = page * limit - read_stories_count
# Read stories to exclude
read_stories = MUserStory.objects(user_id=user.pk, feed_id__in=feed_ids).only('story_id')
@ -573,10 +574,11 @@ def load_river_stories(request):
# if story_feed_counts[story['story_feed_id']] >= 3: continue
# mstories_pruned.append(story)
# story_feed_counts[story['story_feed_id']] += 1
stories = []
for i, story in enumerate(mstories):
if i < offset: continue
if i >= offset + limit: break
if i >= limit: break
stories.append(bunch(story))
stories = Feed.format_stories(stories)
found_feed_ids = list(set([story['story_feed_id'] for story in stories]))

View file

@ -49,6 +49,7 @@ LOGIN_URL = '/reader/login'
ADMIN_MEDIA_PREFIX = '/media/admin/'
SECRET_KEY = 'YOUR_SECRET_KEY'
EMAIL_BACKEND = 'django_ses.SESBackend'
CIPHER_USERNAMES = False
# ===============

View file

@ -1,6 +1,8 @@
import logging
import re
import string
from django.core.handlers.wsgi import WSGIRequest
from django.conf import settings
class NullHandler(logging.Handler): #exists in python 3.1
def emit(self, record):
@ -33,7 +35,16 @@ def user(u, msg):
elif 'Opera' in user_agent:
platform = 'Opera'
premium = '*' if u.is_authenticated() and u.profile.is_premium else ''
info(' ---> [~FB~SN%-6s~SB] [%s%s] %s' % (platform, u, premium, msg))
username = cipher(u.__unicode__()) if settings.CIPHER_USERNAMES else u
info(' ---> [~FB~SN%-6s~SB] [%s%s] %s' % (platform, username, premium, msg))
def cipher(msg):
shift = len(msg)
in_alphabet = unicode(string.ascii_lowercase)
out_alphabet = in_alphabet[shift:] + in_alphabet[:shift]
translation_table = dict((ord(ic), oc) for ic, oc in zip(in_alphabet, out_alphabet))
return msg.translate(translation_table)
def debug(msg):
logger = getlogger()