Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/views/origin.py
Show First 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | try: | ||||
}) | }) | ||||
results = json.dumps(results) | results = json.dumps(results) | ||||
except Exception as exc: | except Exception as exc: | ||||
return handle_view_exception(request, exc, html_response=False) | return handle_view_exception(request, exc, html_response=False) | ||||
return HttpResponse(results, content_type='application/json') | return HttpResponse(results, content_type='application/json') | ||||
@browse_route(r'origin/(?P<origin_id>[0-9]+)/latest_snapshot/', | |||||
view_name='browse-origin-latest-snapshot') | |||||
def _origin_latest_snapshot(request, origin_id): | |||||
""" | |||||
Internal browse endpoint used to check if an origin has already | |||||
been visited by Software Heritage and has at least one full visit. | |||||
""" | |||||
result = \ | |||||
service.lookup_latest_origin_snapshot(int(origin_id), | |||||
allowed_statuses=['full', | |||||
'partial']) | |||||
result = json.dumps(result, sort_keys=True, indent=4, | |||||
separators=(',', ': ')) | |||||
return HttpResponse(result, content_type='application/json') | |||||
@browse_route(r'origin/(?P<origin_type>[a-z]+)/url/(?P<origin_url>.+)/', | @browse_route(r'origin/(?P<origin_type>[a-z]+)/url/(?P<origin_url>.+)/', | ||||
r'origin/(?P<origin_url>.+)/', | r'origin/(?P<origin_url>.+)/', | ||||
view_name='browse-origin') | view_name='browse-origin') | ||||
def origin_browse(request, origin_url, origin_type=None): | def origin_browse(request, origin_url, origin_type=None): | ||||
"""Django view that redirects to the display of the latest archived | """Django view that redirects to the display of the latest archived | ||||
snapshot for a given software origin. | snapshot for a given software origin. | ||||
""" | """ | ||||
last_snapshot_url = reverse('browse-origin-directory', | last_snapshot_url = reverse('browse-origin-directory', | ||||
url_args={'origin_type': origin_type, | url_args={'origin_type': origin_type, | ||||
'origin_url': origin_url}) | 'origin_url': origin_url}) | ||||
return redirect(last_snapshot_url) | return redirect(last_snapshot_url) |