Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : search
---------------------------------------------------------------
commit e888efc8a4284ec1b43d406158adb14ce348bfa9
Author: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
Date: Sat Mar 1 14:50:44 2014 +0400
api: find for fulltext in search
Signed-off-by: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
---------------------------------------------------------------
coprs_frontend/coprs/logic/coprs_logic.py | 4 ----
coprs_frontend/coprs/templates/api.html | 22 ++++++++++++++++------
coprs_frontend/coprs/views/api_ns/api_general.py | 12 +++++++-----
3 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/coprs_frontend/coprs/logic/coprs_logic.py
b/coprs_frontend/coprs/logic/coprs_logic.py
index 19cb5b9..7cab264 100644
--- a/coprs_frontend/coprs/logic/coprs_logic.py
+++ b/coprs_frontend/coprs/logic/coprs_logic.py
@@ -47,7 +47,6 @@ class CoprsLogic(object):
def get_multiple(cls, user, **kwargs):
user_relation = kwargs.get("user_relation", None)
username = kwargs.get("username", None)
- coprname = kwargs.get("coprname", None)
with_mock_chroots = kwargs.get("with_mock_chroots", None)
with_builds = kwargs.get("with_builds", None)
incl_deleted = kwargs.get("incl_deleted", None)
@@ -64,9 +63,6 @@ class CoprsLogic(object):
if isinstance(ids, list): # can be an empty list
query = query.filter(models.Copr.id.in_(ids))
- if coprname:
- query = query.filter(models.Copr.name == coprname)
-
if user_relation == "owned":
query = query.filter(
models.User.openid_name == models.User.openidize_name(username))
diff --git a/coprs_frontend/coprs/templates/api.html
b/coprs_frontend/coprs/templates/api.html
index 1e9ee9a..1df4fb3 100644
--- a/coprs_frontend/coprs/templates/api.html
+++ b/coprs_frontend/coprs/templates/api.html
@@ -342,15 +342,17 @@ copr_url =
http://copr.fedoraproject.org
<h4>URL parameters:</h4>
<ul>
- <li><b>project</b> – The name of the project whose
you'd like
+ <li><b>project</b> – The text of the project whose
you'd like
to find</li>
</ul>
<h4>Result:</h4>
<ul>
- <li><b>"users"</b> – List of users in given
format:
+ <li><b>"repos"</b> – List of repos in given
format:
<ul>
- <li><b>"name"</b> – Name of the
user</li>
+ <li><b>"username"</b> – Name of the
user</li>
+ <li><b>"coprname"</b> – Name of the
copr</li>
+ <li><b>"description"</b> – Description
of the copr</li>
</ul>
</ul>
@@ -361,12 +363,20 @@ copr_url =
http://copr.fedoraproject.org
<pre>
{
"output": "ok",
- "users": [
+ "repos": [
{
- "name": "ignatenkobrain"
+ "username": "ignatenkobrain",
+ "coprname": "test",
+ "description": "Tests"
+ },
+ "username": "ignatenkobrain",
+ "coprname": "tests",
+ "description": ""
},
{
- "name": "msuchy"
+ "username": "msuchy",
+ "coprname": "tests",
+ "description": "Copr testing repository, just for test various
builds."
}
]
}
diff --git a/coprs_frontend/coprs/views/api_ns/api_general.py
b/coprs_frontend/coprs/views/api_ns/api_general.py
index 527f49b..cc41fdd 100644
--- a/coprs_frontend/coprs/views/api_ns/api_general.py
+++ b/coprs_frontend/coprs/views/api_ns/api_general.py
@@ -344,23 +344,25 @@ def copr_chroot_details(username, coprname, chrootname):
@api_ns.route("/coprs/search/")
@api_ns.route("/coprs/search/<project>/")
def api_coprs_search_by_project(project=None):
- """ Return the list of coprs found in search by the given project.
+ """ Return the list of coprs found in search by the given text.
project is taken either from GET params or from the URL itself
(in this order).
- :arg project: the project one would like find for coprs.
+ :arg project: the text one would like find for coprs.
"""
project = flask.request.args.get("project", None) or project
httpcode = 200
if project:
- query = coprs_logic.CoprsLogic.get_multiple(
- flask.g.user, coprname=project)
+ query = coprs_logic.CoprsLogic.get_multiple_fulltext(
+ flask.g.user, project)
repos = query.all()
output = {"output": "ok", "users": []}
for repo in repos:
- output["users"].append({"name": repo.owner})
+ output["repos"].append({"username": repo.owner,
+ "coprname"; repo.name,
+ "description": repo.description})
else:
output = {"output": "notok", "error": "Invalid
request"}
httpcode = 500