Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/origin.py
Show All 14 Lines | |||||
from swh.web.api.utils import enrich_origin, enrich_origin_visit | from swh.web.api.utils import enrich_origin, enrich_origin_visit | ||||
from swh.web.api.views.utils import api_lookup | from swh.web.api.views.utils import api_lookup | ||||
DOC_RETURN_ORIGIN = ''' | DOC_RETURN_ORIGIN = ''' | ||||
:>json string origin_visits_url: link to in order to get information | :>json string origin_visits_url: link to in order to get information | ||||
about the visits for that origin | about the visits for that origin | ||||
:>json string url: the origin canonical url | :>json string url: the origin canonical url | ||||
:>json string type: the type of software origin (deprecated value; | |||||
types are now associated to visits instead of origins) | |||||
:>json number id: the origin unique identifier (deprecated value; | |||||
you should only refer to origins based on their URL) | |||||
''' | ''' | ||||
DOC_RETURN_ORIGIN_ARRAY = \ | DOC_RETURN_ORIGIN_ARRAY = \ | ||||
DOC_RETURN_ORIGIN.replace(':>json', ':>jsonarr') | DOC_RETURN_ORIGIN.replace(':>json', ':>jsonarr') | ||||
DOC_RETURN_ORIGIN_VISIT = ''' | DOC_RETURN_ORIGIN_VISIT = ''' | ||||
:>json string date: ISO representation of the visit date (in UTC) | :>json string date: ISO representation of the visit date (in UTC) | ||||
:>json str origin: the origin canonical url | :>json str origin: the origin canonical url | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | def api_origins(request): | ||||
response = {'results': results, 'headers': {}} | response = {'results': results, 'headers': {}} | ||||
if len(results) > origin_count: | if len(results) > origin_count: | ||||
origin_from = results.pop()['id'] | origin_from = results.pop()['id'] | ||||
response['headers']['link-next'] = reverse( | response['headers']['link-next'] = reverse( | ||||
'api-1-origins', | 'api-1-origins', | ||||
query_params={'origin_from': origin_from, | query_params={'origin_from': origin_from, | ||||
'origin_count': origin_count}, | 'origin_count': origin_count}, | ||||
request=request) | request=request) | ||||
for result in results: | |||||
if 'id' in result: | |||||
del result['id'] | |||||
return response | return response | ||||
@api_route(r'/origin/(?P<origin_url>.+)/get/', 'api-1-origin') | @api_route(r'/origin/(?P<origin_url>.+)/get/', 'api-1-origin') | ||||
@api_doc('/origin/') | @api_doc('/origin/') | ||||
@format_docstring(return_origin=DOC_RETURN_ORIGIN) | @format_docstring(return_origin=DOC_RETURN_ORIGIN) | ||||
def api_origin(request, origin_url): | def api_origin(request, origin_url): | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 369 Lines • Show Last 20 Lines |