From 469e24df95c7bf86a71e5f0e32715813f522f78b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 12 2017 14:42:36 +0000 Subject: Include the url_path in the JSON representation of a project Fixes https://pagure.io/pagure/issue/2467 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/model.py b/pagure/lib/model.py index 084b381..81f2390 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -477,6 +477,18 @@ class Project(BASE): return str_name @property + def url_path(self): + ''' Return the path at which this project can be accessed in the + web UI. + ''' + path = self.name + if self.namespace: + path = '%s/%s' % (self.namespace, path) + if self.is_fork: + path = "fork/%s/%s" % (self.user.user, path) + return path + + @property def tags_text(self): ''' Return the list of tags in a simple text form. ''' return [tag.tag for tag in self.tags] @@ -826,6 +838,7 @@ class Project(BASE): 'id': self.id, 'name': self.name, 'fullname': self.fullname, + 'url_path': self.url_path, 'description': self.description, 'namespace': self.namespace, 'parent': self.parent.to_json( diff --git a/tests/test_pagure_flask_api_fork.py b/tests/test_pagure_flask_api_fork.py index 1de1c79..5cf42ca 100644 --- a/tests/test_pagure_flask_api_fork.py +++ b/tests/test_pagure_flask_api_fork.py @@ -136,6 +136,7 @@ class PagureFlaskApiForktests(tests.Modeltests): "date_modified": "1431414800", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", @@ -171,6 +172,7 @@ class PagureFlaskApiForktests(tests.Modeltests): "date_modified": "1431414800", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", @@ -309,6 +311,7 @@ class PagureFlaskApiForktests(tests.Modeltests): "date_modified": "1431414800", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", @@ -342,6 +345,7 @@ class PagureFlaskApiForktests(tests.Modeltests): "date_modified": "1431414800", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", diff --git a/tests/test_pagure_flask_api_project.py b/tests/test_pagure_flask_api_project.py index c177136..5477522 100644 --- a/tests/test_pagure_flask_api_project.py +++ b/tests/test_pagure_flask_api_project.py @@ -280,6 +280,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1436527638", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", @@ -401,6 +402,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1436527638", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", @@ -460,6 +462,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1436527638", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", @@ -495,6 +498,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1436527638", "description": "test project #2", "fullname": "test2", + "url_path": "test2", "id": 2, "milestones": {}, "name": "test2", @@ -530,6 +534,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1436527638", "description": "namespaced test project", "fullname": "somenamespace/test3", + "url_path": "somenamespace/test3", "id": 3, "milestones": {}, "name": "test3", @@ -589,6 +594,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1436527638", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", @@ -624,6 +630,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1436527638", "description": "test project #2", "fullname": "test2", + "url_path": "test2", "id": 2, "milestones": {}, "name": "test2", @@ -657,6 +664,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1436527638", "description": "namespaced test project", "fullname": "somenamespace/test3", + "url_path": "somenamespace/test3", "id": 3, "milestones": {}, "name": "test3", @@ -710,6 +718,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1436527638", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", @@ -763,6 +772,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1436527638", "description": "namespaced test project", "fullname": "somenamespace/test3", + "url_path": "somenamespace/test3", "id": 3, "milestones": {}, "name": "test3", @@ -838,6 +848,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1436527638", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", @@ -926,6 +937,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1436527638", "description": "test project #1", "fullname": "test", + "url_path": "test", "group_details": { "some_group": [ "foo" @@ -993,6 +1005,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1436527638", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", @@ -1061,6 +1074,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1436527638", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", @@ -1096,6 +1110,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1436527638", "description": "test project #2", "fullname": "test2", + "url_path": "test2", "id": 2, "milestones": {}, "name": "test2", @@ -1129,6 +1144,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1436527638", "description": "namespaced test project", "fullname": "somenamespace/test3", + "url_path": "somenamespace/test3", "id": 3, "milestones": {}, "name": "test3", @@ -1201,6 +1217,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1436527638", "description": "namespaced test project", "fullname": "somenamespace/test3", + "url_path": "somenamespace/test3", "id": 3, "milestones": {}, "name": "test3", @@ -1315,6 +1332,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1496338274", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", @@ -1379,6 +1397,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1496338274", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", @@ -1452,6 +1471,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1496338274", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", @@ -1514,6 +1534,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1496338274", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", @@ -1577,6 +1598,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "date_modified": "1496338274", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", diff --git a/tests/test_pagure_flask_api_ui_private_repo.py b/tests/test_pagure_flask_api_ui_private_repo.py index f1eaf59..6d32267 100644 --- a/tests/test_pagure_flask_api_ui_private_repo.py +++ b/tests/test_pagure_flask_api_ui_private_repo.py @@ -1060,6 +1060,7 @@ class PagurePrivateRepotest(tests.Modeltests): "milestones": {}, "name": "test4", "fullname": "test4", + "url_path": "test4", "namespace": None, "parent": None, "priorities": {}, @@ -1115,6 +1116,7 @@ class PagurePrivateRepotest(tests.Modeltests): "milestones": {}, "name": "test4", "fullname": "test4", + "url_path": "test4", "namespace": None, "parent": None, "priorities": {}, @@ -1235,6 +1237,7 @@ class PagurePrivateRepotest(tests.Modeltests): "milestones": {}, "name": "test4", "fullname": "test4", + "url_path": "test4", "namespace": None, "parent": None, "priorities": {}, @@ -1267,6 +1270,7 @@ class PagurePrivateRepotest(tests.Modeltests): "id": 1, "milestones": {}, "fullname": "test4", + "url_path": "test4", "name": "test4", "namespace": None, "parent": None, @@ -1357,6 +1361,7 @@ class PagurePrivateRepotest(tests.Modeltests): "milestones": {}, "name": "test4", "fullname": "test4", + "url_path": "test4", "namespace": None, "parent": None, "priorities": {}, @@ -1390,6 +1395,7 @@ class PagurePrivateRepotest(tests.Modeltests): "milestones": {}, "name": "test4", "fullname": "test4", + "url_path": "test4", "namespace": None, "parent": None, "priorities": {}, diff --git a/tests/test_pagure_flask_api_user.py b/tests/test_pagure_flask_api_user.py index f889a9b..a1c8868 100644 --- a/tests/test_pagure_flask_api_user.py +++ b/tests/test_pagure_flask_api_user.py @@ -121,6 +121,7 @@ class PagureFlaskApiUSertests(tests.Modeltests): "date_modified": "1490272832", "description": "test project #1", "fullname": "test", + "url_path": "test", "id": 1, "milestones": {}, "name": "test", @@ -169,6 +170,7 @@ class PagureFlaskApiUSertests(tests.Modeltests): "date_modified": "1490272832", "description": "test project #2", "fullname": "test2", + "url_path": "test2", "id": 2, "milestones": {}, "name": "test2", @@ -216,6 +218,7 @@ class PagureFlaskApiUSertests(tests.Modeltests): "date_modified": "1490272832", "description": "namespaced test project", "fullname": "somenamespace/test3", + "url_path": "somenamespace/test3", "id": 3, "milestones": {}, "name": "test3", diff --git a/tests/test_pagure_lib_git.py b/tests/test_pagure_lib_git.py index d226b43..0726780 100644 --- a/tests/test_pagure_lib_git.py +++ b/tests/test_pagure_lib_git.py @@ -1850,7 +1850,7 @@ new file mode 100644 index 0000000..60f7480 --- /dev/null +++ b/456 -@@ -0,0 +1,128 @@ +@@ -0,0 +1,130 @@ +{ + "assignee": null, + "branch": "master", @@ -1884,6 +1884,7 @@ index 0000000..60f7480 + "date_modified": null, + "description": "test project for ticket", + "fullname": "test_ticket_repo", ++ "url_path": "test_ticket_repo", + "id": 1, + "milestones": {}, + "name": "test_ticket_repo", @@ -1935,6 +1936,7 @@ index 0000000..60f7480 + "date_modified": null, + "description": "test project for ticket", + "fullname": "test_ticket_repo", ++ "url_path": "test_ticket_repo", + "id": 1, + "milestones": {}, + "name": "test_ticket_repo",