Permalink
Browse files

Filter by improved

  • Loading branch information...
1 parent 812ed50 commit bd7965682734256fffd277edf30c0225fe983cee @javaguirre committed Apr 1, 2012
Showing with 11 additions and 7 deletions.
  1. +11 −7 application.py
View
@@ -30,19 +30,23 @@ def feed(section_slug, feed_slug):
if request.method == 'POST':
if not re.match("[\s?\w\s?]+", request.form['q']):
abort(404)
+ else:
+ filter_by['q'] = request.form['q']
try:
start = datetime.strptime(request.form['from'], "%m/%d/%Y")
end = datetime.strptime(request.form['to'], "%m/%d/%Y")
+ filter_by['from_date'] = start
+ filter_by['to_date'] = end
except ValueError:
- abort(404)
-
- filter_by = {"q": request.form['q'],
- "from_date": start, "to_date": end}
+ pass
if 'q' in filter_by:
- links = Db().has('link',
- {"title": "/.*" + filter_by['q'] + ".*/i",
- "date": {"$gte": filter_by['from_date'], "$lte": filter_by['to_date']}})
+ query = {"title": re.compile(filter_by['q'], re.IGNORECASE)}
+
+ if "start" and "end" in filter_by:
+ query['date'] = {"$gte": filter_by['start'], "$lte": filter_by['to_date']}
+
+ links = Db().has('link', query)
else:
links = Db().has('link', {"feed_id": feed['_id']})

0 comments on commit bd79656

Please sign in to comment.