Skip to content
This repository has been archived by the owner on Apr 18, 2018. It is now read-only.

Commit

Permalink
Merge branch 'master' into pushes_user_filter
Browse files Browse the repository at this point in the history
Conflicts:
	pushmanager/servlets/api.py
	pushmanager/servlets/pushes.py
	pushmanager/templates/pushes.html
	pushmanager/tests/test_servlet_api.py
	pushmanager/tests/test_template_pushes.py
  • Loading branch information
sjaensch committed Mar 4, 2015
2 parents 05e3938 + eb269f3 commit 23bb098
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
18 changes: 9 additions & 9 deletions pushmanager/servlets/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@ def _on_PUSHDATA_db_response(self, success, db_results):

def _api_PUSHES(self):
"""Returns a JSON representation of pushes."""
rpp = int(self.request.arguments.get('rpp', [50])[0])
offset = int(self.request.arguments.get('offset', [0])[0])
user = util.get_str_arg(self.request, 'user', '')
rpp = util.get_int_arg(self.request, 'rpp', 50)
offset = util.get_int_arg(self.request, 'offset', 0)
state = util.get_str_arg(self.request, 'state', '')
user = util.get_str_arg(self.request, 'user', '')

filters = []
if user != '':
filters.append(db.push_pushes.c.user == user)
if state != '':
filters.append(db.push_pushes.c.state == state)
if user != '':
filters.append(db.push_pushes.c.user == user)

push_query = db.push_pushes.select(
whereclause=SA.and_(*filters),
Expand Down Expand Up @@ -160,9 +160,9 @@ def _api_PUSHCONTENTS(self):
return self.send_error(404)

query = db.push_requests.select(SA.and_(
db.push_requests.c.id == db.push_pushcontents.c.request,
db.push_pushcontents.c.push == push_id,
))
db.push_requests.c.id == db.push_pushcontents.c.request,
db.push_pushcontents.c.push == push_id,
))
db.execute_cb(query, self._on_PUSHCONTENTS_db_response)

def _on_PUSHCONTENTS_db_response(self, success, db_results):
Expand Down Expand Up @@ -201,7 +201,7 @@ def _api_PUSHITEMS(self):
db.push_requests.c.id == db.push_pushcontents.c.request,
db.push_requests.c.state != 'pickme',
db.push_pushcontents.c.push == push_id,
),
),
order_by=(db.push_requests.c.user, db.push_requests.c.title),
)
db.execute_cb(query, self._on_PUSHITEMS_db_response)
Expand Down
22 changes: 11 additions & 11 deletions pushmanager/servlets/pushes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ class PushesServlet(RequestHandler):
def get(self):
pushes_per_page = pushmanager.core.util.get_int_arg(self.request, 'rpp', 50)
offset = pushmanager.core.util.get_int_arg(self.request, 'offset', 0)
push_user = pushmanager.core.util.get_str_arg(self.request, 'user', '')
state = pushmanager.core.util.get_str_arg(self.request, 'state', '')
push_user = pushmanager.core.util.get_str_arg(self.request, 'user', '')
response = yield tornado.gen.Task(
self.async_api_call,
'pushes',
{
'rpp': pushes_per_page,
'offset': offset,
'user': push_user,
'state': state,
}
)
self.async_api_call,
'pushes',
{
'rpp': pushes_per_page,
'offset': offset,
'state': state,
'user': push_user,
}
)

results = self.get_api_results(response)
if not results:
Expand All @@ -36,7 +36,7 @@ def get(self):
pushes=pushes,
offset=offset,
rpp=pushes_per_page,
push_user=push_user,
state=state,
push_user=push_user,
pushes_count=pushes_count,
)
14 changes: 12 additions & 2 deletions pushmanager/templates/pushes.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
</select>
</li>
&mdash;
<li>
Show states:
<select id="state-filter">
<option value="">All states</option>
<option value="accepting" {% if state == 'accepting' %}selected="selected"{% end %}>Accepting</option>
<option value="live" {% if state == 'live' %}selected="selected"{% end %}>Live</option>
<option value="discarded" {% if state == 'discarded' %}selected="selected"{% end %}>Discarded</option>
</select>
</li>
&mdash;
<li><button id="new-push">New Push</button></li>
&mdash;
<li>{{ modules.NewRequestDialog() }}</li>
Expand Down Expand Up @@ -77,10 +87,10 @@ <h2>New Push</h2>

<div id="paginator">
{% if pushes and offset > 0 %}
<a href="/pushes?rpp={{ rpp }}&amp;offset={{ max(offset - rpp, 0) }}&amp;user={{ url_escape(push_user) }}&amp;state={{ url_escape(state) }}"> Newer</a>
<a href="/pushes?rpp={{ rpp }}&amp;offset={{ max(offset - rpp, 0) }}&amp;state={{ url_escape(state) }}"&amp;user={{ url_escape(push_user) }}> Newer</a>
{% end if %}
{% if pushes and offset + rpp < pushes_count %}
<a href="/pushes?rpp={{ rpp }}&amp;offset={{ offset + rpp }}&amp;user={{ url_escape(push_user) }}&amp;state={{ url_escape(state) }}">Older</a>
<a href="/pushes?rpp={{ rpp }}&amp;offset={{ offset + rpp }}&amp;state={{ url_escape(state) }}"&amp;user={{ url_escape(push_user) }}>Older</a>
{% end if %}
</div>

Expand Down
4 changes: 2 additions & 2 deletions pushmanager/tests/test_servlet_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def test_pushes(self):
pushes, last_push = self.api_call("pushes?rpp=1")
T.assert_length(pushes, 1)

pushes, last_push = self.api_call("pushes?before=%d" % time.time())
T.assert_length(pushes, 2)
pushes, last_push = self.api_call("pushes?offset=1")
T.assert_length(pushes, 1)

def test_pushes_order(self):
self.insert_pushes()
Expand Down
2 changes: 1 addition & 1 deletion pushmanager/tests/test_template_pushes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def render_pushes_page(self, page_title='Pushes', pushes=[], pushes_per_page=50,
pushes=pushes,
rpp=pushes_per_page,
offset=offset,
push_user='',
state='',
push_user='',
)

def test_include_new_push(self):
Expand Down

0 comments on commit 23bb098

Please sign in to comment.