[PATCH 1/2] [frontend] add yum_repos to coprs/user API call

Michael Simacek msimacek at redhat.com
Wed Nov 20 14:03:00 UTC 2013


---
 coprs_frontend/coprs/logic/coprs_logic.py        |  6 ++++++
 coprs_frontend/coprs/views/api_ns/api_general.py | 15 ++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/coprs_frontend/coprs/logic/coprs_logic.py b/coprs_frontend/coprs/logic/coprs_logic.py
index 77599c5..5129a82 100644
--- a/coprs_frontend/coprs/logic/coprs_logic.py
+++ b/coprs_frontend/coprs/logic/coprs_logic.py
@@ -41,6 +41,7 @@ class CoprsLogic(object):
         user_relation = kwargs.get('user_relation', None)
         username = kwargs.get('username', None)
         with_mock_chroots = kwargs.get('with_mock_chroots', None)
+        with_builds = kwargs.get('with_builds', None)
         incl_deleted = kwargs.get('incl_deleted', None)
         ids = kwargs.get('ids', None)
 
@@ -70,6 +71,11 @@ class CoprsLogic(object):
                           order_by(models.MockChroot.os_version.asc()).\
                           order_by(models.MockChroot.arch.asc())
 
+        if with_builds:
+            query = query.outerjoin(models.Copr.builds).\
+                          options(db.contains_eager(models.Copr.builds)).\
+                          order_by(models.Build.submitted_on.desc())
+
         return query
 
     @classmethod
diff --git a/coprs_frontend/coprs/views/api_ns/api_general.py b/coprs_frontend/coprs/views/api_ns/api_general.py
index 8d42745..97e4c03 100644
--- a/coprs_frontend/coprs/views/api_ns/api_general.py
+++ b/coprs_frontend/coprs/views/api_ns/api_general.py
@@ -3,6 +3,7 @@ import time
 
 import base64
 import flask
+import urlparse
 
 from coprs import db
 from coprs import exceptions
@@ -116,12 +117,21 @@ def api_coprs_by_owner(username=None):
     httpcode = 200
     if username:
         query = coprs_logic.CoprsLogic.get_multiple(flask.g.user,
-            user_relation='owned', username=username)
+            user_relation='owned', username=username, with_builds=True)
         repos = query.all()
         output = {'output': 'ok', 'repos': []}
         for repo in repos:
+            yum_repos = {}
+            for build in repo.builds:
+                if build.results:
+                    for chroot in repo.active_mock_chroots:
+                        release = '{chroot.os_release}-{chroot.os_version}-{chroot.arch}'.format(chroot=chroot)
+                        yum_repos[release] = urlparse.urljoin(build.results, release + '/')
+                    break
+
             output['repos'].append({'name': repo.name,
-                                    'repos': repo.repos,
+                                    'additional_repos': repo.repos,
+                                    'yum_repos': yum_repos,
                                     'description': repo.description,
                                     'instructions': repo.instructions})
     else:
@@ -132,7 +142,6 @@ def api_coprs_by_owner(username=None):
     jsonout.status_code = httpcode
     return jsonout
 
-
 @api_ns.route('/coprs/<username>/<coprname>/new_build/', methods=["POST"])
 @api_login_required
 def copr_new_build(username, coprname):
-- 
1.8.3.1



More information about the copr-devel mailing list