def landing(request): """Customer Care Landing page.""" # Get a redis client redis = None try: redis = redis_client(name='default') except RedisError as e: statsd.incr('redis.errror') log.error('Redis error: %s' % e) contributor_stats = redis and redis.get(settings.CC_TOP_CONTRIB_CACHE_KEY) if contributor_stats: contributor_stats = json.loads(contributor_stats) statsd.incr('customercare.stats.contributors.hit') else: statsd.incr('customercare.stats.contributors.miss') twitter_user = None if request.twitter.authed: try: credentials = request.twitter.api.verify_credentials() except (TwythonError, TwythonAuthError): # Bad oauth token. Create a new session so user re-auths. request.twitter = twitter.Session() else: twitter_user = credentials['screen_name'] yesterday = datetime.now() - timedelta(days=1) recent_replied_count = _count_answered_tweets(since=yesterday) return render( request, 'customercare/landing.html', { 'contributor_stats': contributor_stats, 'canned_responses': get_common_replies(request.LANGUAGE_CODE), 'tweets': _get_tweets(locale=request.LANGUAGE_CODE, filter='unanswered', https=request.is_secure()), 'authed': request.user.is_authenticated() and request.twitter.authed, 'twitter_user': twitter_user, 'filters': FILTERS, 'filter': 'unanswered', 'time': datetime.now(), 'goal': settings.CC_REPLIES_GOAL, 'recent_replied_count': recent_replied_count })
def landing(request): """Customer Care Landing page.""" # Get a redis client redis = None try: redis = redis_client(name="default") except RedisError as e: log.error("Redis error: %s" % e) contributor_stats = redis and redis.get(settings.CC_TOP_CONTRIB_CACHE_KEY) if contributor_stats: contributor_stats = json.loads(contributor_stats) twitter_user = None if request.twitter.authed: try: credentials = request.twitter.api.verify_credentials() except (TwythonError, TwythonAuthError): # Bad oauth token. Create a new session so user re-auths. request.twitter = twitter.Session() else: twitter_user = credentials["screen_name"] yesterday = datetime.now() - timedelta(days=1) recent_replied_count = _count_answered_tweets(since=yesterday) return render( request, "customercare/landing.html", { "contributor_stats": contributor_stats, "canned_responses": get_common_replies(request.LANGUAGE_CODE), "tweets": _get_tweets(locale=request.LANGUAGE_CODE, filter="unanswered", https=request.is_secure()), "authed": request.user.is_authenticated and request.twitter.authed, "twitter_user": twitter_user, "filters": FILTERS, "filter": "unanswered", "time": datetime.now(), "goal": settings.CC_REPLIES_GOAL, "recent_replied_count": recent_replied_count, }, )
def landing(request): """Customer Care Landing page.""" # Get a redis client redis = None try: redis = redis_client(name="default") except RedisError as e: statsd.incr("redis.errror") log.error("Redis error: %s" % e) contributor_stats = redis and redis.get(settings.CC_TOP_CONTRIB_CACHE_KEY) if contributor_stats: contributor_stats = json.loads(contributor_stats) statsd.incr("customercare.stats.contributors.hit") else: statsd.incr("customercare.stats.contributors.miss") twitter_user = None if request.twitter.authed: try: credentials = request.twitter.api.verify_credentials() except (TwythonError, TwythonAuthError): # Bad oauth token. Create a new session so user re-auths. request.twitter = twitter.Session() else: twitter_user = credentials["screen_name"] yesterday = datetime.now() - timedelta(days=1) recent_replied_count = _count_answered_tweets(since=yesterday) return render( request, "customercare/landing.html", { "contributor_stats": contributor_stats, "canned_responses": get_common_replies(request.LANGUAGE_CODE), "tweets": _get_tweets(locale=request.LANGUAGE_CODE, filter="unanswered", https=request.is_secure()), "authed": request.user.is_authenticated() and request.twitter.authed, "twitter_user": twitter_user, "filters": FILTERS, "filter": "unanswered", "goal": settings.CC_REPLIES_GOAL, "recent_replied_count": recent_replied_count, }, )
def landing(request): """Customer Care Landing page.""" # Get a redis client redis = None try: redis = redis_client(name='default') except RedisError as e: statsd.incr('redis.errror') log.error('Redis error: %s' % e) contributor_stats = redis and redis.get(settings.CC_TOP_CONTRIB_CACHE_KEY) if contributor_stats: contributor_stats = json.loads(contributor_stats) statsd.incr('customercare.stats.contributors.hit') else: statsd.incr('customercare.stats.contributors.miss') twitter_user = None if request.twitter.authed: try: credentials = request.twitter.api.verify_credentials() except (TwythonError, TwythonAuthError): # Bad oauth token. Create a new session so user re-auths. request.twitter = twitter.Session() else: twitter_user = credentials['screen_name'] yesterday = datetime.now() - timedelta(days=1) recent_replied_count = _count_answered_tweets(since=yesterday) return render(request, 'customercare/landing.html', { 'contributor_stats': contributor_stats, 'canned_responses': get_common_replies(request.LANGUAGE_CODE), 'tweets': _get_tweets(locale=request.LANGUAGE_CODE, filter='unanswered', https=request.is_secure()), 'authed': request.user.is_authenticated() and request.twitter.authed, 'twitter_user': twitter_user, 'filters': FILTERS, 'filter': 'unanswered', 'time': datetime.now(), 'goal': settings.CC_REPLIES_GOAL, 'recent_replied_count': recent_replied_count})