Skip to content

Commit

Permalink
Add campaign_id to /count for #26
Browse files Browse the repository at this point in the history
  • Loading branch information
beaugunderson committed Feb 9, 2014
1 parent c76d573 commit ae99f11
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ def demo():
@cache.cached(timeout=5)
@app.route('/count')
def count():
return jsonify(count=call_count())
campaign = request.values.get('campaign', 'default')

return jsonify(campaign=campaign, count=call_count(campaign))


@cache.cached(timeout=60, key_prefix=make_cache_key)
Expand Down
5 changes: 3 additions & 2 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ def log_call(params, campaign, request):
logging.error('Failed to log call:', exc_info=True)


def call_count():
def call_count(campaign_id):
try:
return db.session.query(func.Count(Call.zipcode)).all()[0][0]
return (db.session.query(func.Count(Call.zipcode))
.filter(Call.campaign_id == campaign_id).all())[0][0]
except SQLAlchemyError:
logging.error('Failed to get call_count:', exc_info=True)

Expand Down

0 comments on commit ae99f11

Please sign in to comment.