Skip to content

Commit

Permalink
#58
Browse files Browse the repository at this point in the history
  • Loading branch information
cbertelegni committed Dec 2, 2014
1 parent 6400860 commit 8c7a9d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 11 additions & 3 deletions app/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def donors_per_sex(filters):
query_join = query_join.filter(Aporte.agrupacion.has(nombre = filters['val']))

elif filter['op'] == 'has' and filter['name'] == 'aportante':
field = "Aportante.%s" % filter['val']['name']

if filter['val']['op'] == 'eq':
query_join = query_join.filter(eval(field) == filter['val']['val'])
Expand All @@ -103,7 +102,10 @@ def donors_per_sex(filters):

elif filter['val']['op'] == 'is_not_null':
query_join = query_join.filter(eval(field) != None)


elif filter['val']['op'] == 'in':
fieldfield = "Aportante.%s.in_(%s)" % (filter['val']["name"], filter['val']["val"])
query_join = query_join.filter(eval(fieldfield))

elif filter['name'] == 'ciclo':
query_join = query_join.filter_by(ciclo = filter['val'])
Expand All @@ -113,7 +115,13 @@ def donors_per_sex(filters):

elif filter['name'] == 'distrito':
query_join = query_join.filter_by(distrito = filter['val'])


elif filter['op'] == 'in':
fieldfield = "Aporte.%s.in_(%s)" % (filter["name"], filter["val"])

query_join = query_join.filter(eval(fieldfield))


donors_by_sex_f = query_join.filter(Aportante.sexo=='F').distinct().count()
donors_by_sex_m = query_join.filter(Aportante.sexo=='M').distinct().count()

Expand Down
3 changes: 1 addition & 2 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
cache.init_app(app)

def make_cache_key(*args, **kwargs):
print CACHE_PATH
path = request.path
args = str(hash(frozenset(request.args.items())))
# lang = get_locale()
Expand All @@ -38,7 +37,7 @@ def index():
# Consultas -----------------------

@app.route('/api/aportantes/sexo')
@cache.cached(timeout=60*10, key_prefix=make_cache_key)
# @cache.cached(timeout=60*10, key_prefix=make_cache_key)
def aportantes_por_sexo():

filters = parse_filters(request.args.get('q'))
Expand Down

0 comments on commit 8c7a9d0

Please sign in to comment.