Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/views/utils/snapshot_context.py
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | def _branch_not_found(branch_type, branch, branches, snapshot_id=None, | ||||
if snapshot_id and not branches: | if snapshot_id and not branches: | ||||
msg = ('Snapshot with id %s has an empty list' | msg = ('Snapshot with id %s has an empty list' | ||||
' of %s!' % (snapshot_id, branch_type_plural)) | ' of %s!' % (snapshot_id, branch_type_plural)) | ||||
elif snapshot_id: | elif snapshot_id: | ||||
msg = ('%s %s for snapshot with id %s' | msg = ('%s %s for snapshot with id %s' | ||||
' not found!' % (branch_type, branch, snapshot_id)) | ' not found!' % (branch_type, branch, snapshot_id)) | ||||
elif visit_id and not branches: | elif visit_id and not branches: | ||||
msg = ('Origin with type %s and url %s' | msg = ('Origin with url %s' | ||||
' for visit with id %s has an empty list' | ' for visit with id %s has an empty list' | ||||
' of %s!' % (origin_info['type'], origin_info['url'], visit_id, | ' of %s!' % (origin_info['url'], visit_id, | ||||
branch_type_plural)) | branch_type_plural)) | ||||
elif visit_id: | elif visit_id: | ||||
msg = ('%s %s associated to visit with' | msg = ('%s %s associated to visit with' | ||||
' id %s for origin with type %s and url %s' | ' id %s for origin with url %s' | ||||
' not found!' % (branch_type, branch, visit_id, | ' not found!' % (branch_type, branch, visit_id, | ||||
origin_info['type'], origin_info['url'])) | origin_info['url'])) | ||||
elif not branches: | elif not branches: | ||||
msg = ('Origin with type %s and url %s' | msg = ('Origin with url %s' | ||||
' for visit with timestamp %s has an empty list' | ' for visit with timestamp %s has an empty list' | ||||
' of %s!' % (origin_info['type'], origin_info['url'], | ' of %s!' % (origin_info['url'], | ||||
timestamp, branch_type_plural)) | timestamp, branch_type_plural)) | ||||
else: | else: | ||||
msg = ('%s %s associated to visit with' | msg = ('%s %s associated to visit with' | ||||
' timestamp %s for origin with type %s' | ' timestamp %s for origin with ' | ||||
' and url %s not found!' % (branch_type, branch, timestamp, | 'url %s not found!' % (branch_type, branch, timestamp, | ||||
origin_info['type'], | |||||
origin_info['url'])) | origin_info['url'])) | ||||
raise NotFoundExc(escape(msg)) | raise NotFoundExc(escape(msg)) | ||||
def _process_snapshot_request(request, snapshot_id=None, origin_type=None, | def _process_snapshot_request(request, snapshot_id=None, | ||||
origin_url=None, timestamp=None, path=None, | origin_url=None, timestamp=None, path=None, | ||||
browse_context='directory'): | browse_context='directory'): | ||||
""" | """ | ||||
Utility function to perform common input request processing | Utility function to perform common input request processing | ||||
for snapshot context views. | for snapshot context views. | ||||
""" | """ | ||||
visit_id = request.GET.get('visit_id', None) | visit_id = request.GET.get('visit_id', None) | ||||
snapshot_context = get_snapshot_context(snapshot_id, origin_type, | snapshot_context = get_snapshot_context(snapshot_id, | ||||
origin_url, timestamp, visit_id) | origin_url, timestamp, visit_id) | ||||
swh_type = snapshot_context['swh_type'] | swh_type = snapshot_context['swh_type'] | ||||
origin_info = snapshot_context['origin_info'] | origin_info = snapshot_context['origin_info'] | ||||
branches = snapshot_context['branches'] | branches = snapshot_context['branches'] | ||||
releases = snapshot_context['releases'] | releases = snapshot_context['releases'] | ||||
url_args = snapshot_context['url_args'] | url_args = snapshot_context['url_args'] | ||||
query_params = snapshot_context['query_params'] | query_params = snapshot_context['query_params'] | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | def _process_snapshot_request(request, snapshot_id=None, | ||||
snapshot_context['revision_id'] = revision_id | snapshot_context['revision_id'] = revision_id | ||||
snapshot_context['branch'] = branch_name | snapshot_context['branch'] = branch_name | ||||
snapshot_context['release'] = release_name | snapshot_context['release'] = release_name | ||||
snapshot_context['release_id'] = release_id | snapshot_context['release_id'] = release_id | ||||
return snapshot_context | return snapshot_context | ||||
def browse_snapshot_directory(request, snapshot_id=None, origin_type=None, | def browse_snapshot_directory(request, snapshot_id=None, | ||||
origin_url=None, timestamp=None, path=None): | origin_url=None, timestamp=None, path=None): | ||||
""" | """ | ||||
Django view implementation for browsing a directory in a snapshot context. | Django view implementation for browsing a directory in a snapshot context. | ||||
""" | """ | ||||
try: | try: | ||||
snapshot_context = _process_snapshot_request( | snapshot_context = _process_snapshot_request( | ||||
request, snapshot_id, origin_type, origin_url, | request, snapshot_id, origin_url, | ||||
timestamp, path, browse_context='directory') | timestamp, path, browse_context='directory') | ||||
root_sha1_git = snapshot_context['root_sha1_git'] | root_sha1_git = snapshot_context['root_sha1_git'] | ||||
sha1_git = root_sha1_git | sha1_git = root_sha1_git | ||||
if root_sha1_git and path: | if root_sha1_git and path: | ||||
dir_info = service.lookup_directory_with_path(root_sha1_git, path) | dir_info = service.lookup_directory_with_path(root_sha1_git, path) | ||||
sha1_git = dir_info['target'] | sha1_git = dir_info['target'] | ||||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | dir_metadata = {'directory': sha1_git, | ||||
'sum of regular file sizes': sum_file_sizes, | 'sum of regular file sizes': sum_file_sizes, | ||||
'path': dir_path, | 'path': dir_path, | ||||
'revision': revision_id, | 'revision': revision_id, | ||||
'context-independent revision': browse_rev_link, | 'context-independent revision': browse_rev_link, | ||||
'snapshot': snapshot_id, | 'snapshot': snapshot_id, | ||||
'context-independent snapshot': browse_snp_link} | 'context-independent snapshot': browse_snp_link} | ||||
if origin_info: | if origin_info: | ||||
dir_metadata['origin type'] = origin_info['type'] | |||||
dir_metadata['origin url'] = origin_info['url'] | dir_metadata['origin url'] = origin_info['url'] | ||||
dir_metadata['origin visit date'] = format_utc_iso_date( | dir_metadata['origin visit date'] = format_utc_iso_date( | ||||
visit_info['date']) | visit_info['date']) | ||||
dir_metadata['origin visit type'] = visit_info['type'] | |||||
vault_cooking = { | vault_cooking = { | ||||
'directory_context': True, | 'directory_context': True, | ||||
'directory_id': sha1_git, | 'directory_id': sha1_git, | ||||
'revision_context': True, | 'revision_context': True, | ||||
'revision_id': revision_id | 'revision_id': revision_id | ||||
} | } | ||||
Show All 34 Lines | return render(request, 'browse/directory.html', | ||||
'readme_url': readme_url, | 'readme_url': readme_url, | ||||
'readme_html': readme_html, | 'readme_html': readme_html, | ||||
'snapshot_context': snapshot_context, | 'snapshot_context': snapshot_context, | ||||
'vault_cooking': vault_cooking, | 'vault_cooking': vault_cooking, | ||||
'show_actions_menu': True, | 'show_actions_menu': True, | ||||
'swh_ids': swh_ids}) | 'swh_ids': swh_ids}) | ||||
def browse_snapshot_content(request, snapshot_id=None, origin_type=None, | def browse_snapshot_content(request, snapshot_id=None, | ||||
origin_url=None, timestamp=None, path=None, | origin_url=None, timestamp=None, path=None, | ||||
selected_language=None): | selected_language=None): | ||||
""" | """ | ||||
Django view implementation for browsing a content in a snapshot context. | Django view implementation for browsing a content in a snapshot context. | ||||
""" | """ | ||||
try: | try: | ||||
snapshot_context = _process_snapshot_request(request, snapshot_id, | snapshot_context = _process_snapshot_request(request, snapshot_id, | ||||
origin_type, origin_url, | origin_url, | ||||
timestamp, path, | timestamp, path, | ||||
browse_context='content') | browse_context='content') | ||||
root_sha1_git = snapshot_context['root_sha1_git'] | root_sha1_git = snapshot_context['root_sha1_git'] | ||||
sha1_git = None | sha1_git = None | ||||
query_string = None | query_string = None | ||||
content_data = None | content_data = None | ||||
split_path = path.split('/') | split_path = path.split('/') | ||||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | if content_data: | ||||
cnt_sha1_git = content_data['checksums']['sha1_git'] | cnt_sha1_git = content_data['checksums']['sha1_git'] | ||||
content_size = content_data['length'] | content_size = content_data['length'] | ||||
error_code = content_data['error_code'] | error_code = content_data['error_code'] | ||||
error_message = content_data['error_message'] | error_message = content_data['error_message'] | ||||
error_description = content_data['error_description'] | error_description = content_data['error_description'] | ||||
if origin_info: | if origin_info: | ||||
content_metadata['origin type'] = origin_info['type'] | |||||
content_metadata['origin url'] = origin_info['url'] | content_metadata['origin url'] = origin_info['url'] | ||||
content_metadata['origin visit date'] = format_utc_iso_date( | content_metadata['origin visit date'] = format_utc_iso_date( | ||||
visit_info['date']) | visit_info['date']) | ||||
content_metadata['origin visit type'] = visit_info['type'] | |||||
browse_snapshot_link = gen_snapshot_link(snapshot_id) | browse_snapshot_link = gen_snapshot_link(snapshot_id) | ||||
content_metadata['context-independent snapshot'] = browse_snapshot_link | content_metadata['context-independent snapshot'] = browse_snapshot_link | ||||
swh_objects = [{'type': 'content', | swh_objects = [{'type': 'content', | ||||
'id': cnt_sha1_git}, | 'id': cnt_sha1_git}, | ||||
{'type': 'revision', | {'type': 'revision', | ||||
'id': revision_id}, | 'id': revision_id}, | ||||
{'type': 'snapshot', | {'type': 'snapshot', | ||||
Show All 37 Lines | return render(request, 'browse/content.html', | ||||
'error_message': error_message, | 'error_message': error_message, | ||||
'error_description': error_description}, | 'error_description': error_description}, | ||||
status=error_code) | status=error_code) | ||||
PER_PAGE = 100 | PER_PAGE = 100 | ||||
def browse_snapshot_log(request, snapshot_id=None, origin_type=None, | def browse_snapshot_log(request, snapshot_id=None, | ||||
origin_url=None, timestamp=None): | origin_url=None, timestamp=None): | ||||
""" | """ | ||||
Django view implementation for browsing a revision history in a | Django view implementation for browsing a revision history in a | ||||
snapshot context. | snapshot context. | ||||
""" | """ | ||||
try: | try: | ||||
snapshot_context = _process_snapshot_request( | snapshot_context = _process_snapshot_request( | ||||
request, snapshot_id, origin_type, origin_url, | request, snapshot_id, origin_url, timestamp, browse_context='log') | ||||
timestamp, browse_context='log') | |||||
revision_id = snapshot_context['revision_id'] | revision_id = snapshot_context['revision_id'] | ||||
per_page = int(request.GET.get('per_page', PER_PAGE)) | per_page = int(request.GET.get('per_page', PER_PAGE)) | ||||
offset = int(request.GET.get('offset', 0)) | offset = int(request.GET.get('offset', 0)) | ||||
revs_ordering = request.GET.get('revs_ordering', 'committer_date') | revs_ordering = request.GET.get('revs_ordering', 'committer_date') | ||||
session_key = 'rev_%s_log_ordering_%s' % (revision_id, revs_ordering) | session_key = 'rev_%s_log_ordering_%s' % (revision_id, revs_ordering) | ||||
rev_log_session = request.session.get(session_key, None) | rev_log_session = request.session.get(session_key, None) | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | def browse_snapshot_log(request, snapshot_id=None, | ||||
revision_metadata = { | revision_metadata = { | ||||
'context-independent revision': browse_rev_link, | 'context-independent revision': browse_rev_link, | ||||
'context-independent revision history': browse_log_link, | 'context-independent revision history': browse_log_link, | ||||
'context-independent snapshot': browse_snp_link, | 'context-independent snapshot': browse_snp_link, | ||||
'snapshot': snapshot_id | 'snapshot': snapshot_id | ||||
} | } | ||||
if origin_info: | if origin_info: | ||||
revision_metadata['origin type'] = origin_info['type'] | |||||
revision_metadata['origin url'] = origin_info['url'] | revision_metadata['origin url'] = origin_info['url'] | ||||
revision_metadata['origin visit date'] = format_utc_iso_date( | revision_metadata['origin visit date'] = format_utc_iso_date( | ||||
visit_info['date']) | visit_info['date']) | ||||
revision_metadata['origin visit type'] = visit_info['type'] | |||||
swh_objects = [{'type': 'revision', | swh_objects = [{'type': 'revision', | ||||
'id': revision_id}, | 'id': revision_id}, | ||||
{'type': 'snapshot', | {'type': 'snapshot', | ||||
'id': snapshot_id}] | 'id': snapshot_id}] | ||||
release_id = snapshot_context['release_id'] | release_id = snapshot_context['release_id'] | ||||
if release_id: | if release_id: | ||||
Show All 19 Lines | return render(request, 'browse/revision-log.html', | ||||
'breadcrumbs': None, | 'breadcrumbs': None, | ||||
'top_right_link': None, | 'top_right_link': None, | ||||
'snapshot_context': snapshot_context, | 'snapshot_context': snapshot_context, | ||||
'vault_cooking': None, | 'vault_cooking': None, | ||||
'show_actions_menu': True, | 'show_actions_menu': True, | ||||
'swh_ids': swh_ids}) | 'swh_ids': swh_ids}) | ||||
def browse_snapshot_branches(request, snapshot_id=None, origin_type=None, | def browse_snapshot_branches(request, snapshot_id=None, | ||||
origin_url=None, timestamp=None): | origin_url=None, timestamp=None): | ||||
""" | """ | ||||
Django view implementation for browsing a list of branches in a snapshot | Django view implementation for browsing a list of branches in a snapshot | ||||
context. | context. | ||||
""" | """ | ||||
try: | try: | ||||
snapshot_context = _process_snapshot_request(request, snapshot_id, | snapshot_context = _process_snapshot_request(request, snapshot_id, | ||||
origin_type, origin_url, | origin_url, timestamp) | ||||
timestamp) | |||||
branches_bc = request.GET.get('branches_breadcrumbs', '') | branches_bc = request.GET.get('branches_breadcrumbs', '') | ||||
branches_bc = branches_bc.split(',') if branches_bc else [] | branches_bc = branches_bc.split(',') if branches_bc else [] | ||||
branches_from = branches_bc[-1] if branches_bc else '' | branches_from = branches_bc[-1] if branches_bc else '' | ||||
swh_type = snapshot_context['swh_type'] | swh_type = snapshot_context['swh_type'] | ||||
origin_info = snapshot_context['origin_info'] | origin_info = snapshot_context['origin_info'] | ||||
url_args = snapshot_context['url_args'] | url_args = snapshot_context['url_args'] | ||||
Show All 13 Lines | def browse_snapshot_branches(request, snapshot_id=None, | ||||
for branch in displayed_branches: | for branch in displayed_branches: | ||||
if snapshot_id: | if snapshot_id: | ||||
revision_url = reverse('browse-revision', | revision_url = reverse('browse-revision', | ||||
url_args={'sha1_git': branch['revision']}, | url_args={'sha1_git': branch['revision']}, | ||||
query_params={'snapshot_id': snapshot_id}) | query_params={'snapshot_id': snapshot_id}) | ||||
else: | else: | ||||
revision_url = reverse('browse-revision', | revision_url = reverse('browse-revision', | ||||
url_args={'sha1_git': branch['revision']}, | url_args={'sha1_git': branch['revision']}, | ||||
query_params={'origin_type': origin_type, | query_params={'origin': origin_info['url']}) | ||||
'origin': origin_info['url']}) | |||||
query_params['branch'] = branch['name'] | query_params['branch'] = branch['name'] | ||||
directory_url = reverse(browse_view_name, | directory_url = reverse(browse_view_name, | ||||
url_args=url_args, | url_args=url_args, | ||||
query_params=query_params) | query_params=query_params) | ||||
del query_params['branch'] | del query_params['branch'] | ||||
branch['revision_url'] = revision_url | branch['revision_url'] = revision_url | ||||
branch['directory_url'] = directory_url | branch['directory_url'] = directory_url | ||||
Show All 33 Lines | return render(request, 'browse/branches.html', | ||||
'swh_object_metadata': {}, | 'swh_object_metadata': {}, | ||||
'top_right_link': None, | 'top_right_link': None, | ||||
'displayed_branches': displayed_branches, | 'displayed_branches': displayed_branches, | ||||
'prev_branches_url': prev_branches_url, | 'prev_branches_url': prev_branches_url, | ||||
'next_branches_url': next_branches_url, | 'next_branches_url': next_branches_url, | ||||
'snapshot_context': snapshot_context}) | 'snapshot_context': snapshot_context}) | ||||
def browse_snapshot_releases(request, snapshot_id=None, origin_type=None, | def browse_snapshot_releases(request, snapshot_id=None, | ||||
origin_url=None, timestamp=None): | origin_url=None, timestamp=None): | ||||
""" | """ | ||||
Django view implementation for browsing a list of releases in a snapshot | Django view implementation for browsing a list of releases in a snapshot | ||||
context. | context. | ||||
""" | """ | ||||
try: | try: | ||||
snapshot_context = _process_snapshot_request(request, snapshot_id, | snapshot_context = _process_snapshot_request(request, snapshot_id, | ||||
origin_type, origin_url, | origin_url, timestamp) | ||||
timestamp) | |||||
rel_bc = request.GET.get('releases_breadcrumbs', '') | rel_bc = request.GET.get('releases_breadcrumbs', '') | ||||
rel_bc = rel_bc.split(',') if rel_bc else [] | rel_bc = rel_bc.split(',') if rel_bc else [] | ||||
rel_from = rel_bc[-1] if rel_bc else '' | rel_from = rel_bc[-1] if rel_bc else '' | ||||
swh_type = snapshot_context['swh_type'] | swh_type = snapshot_context['swh_type'] | ||||
origin_info = snapshot_context['origin_info'] | origin_info = snapshot_context['origin_info'] | ||||
url_args = snapshot_context['url_args'] | url_args = snapshot_context['url_args'] | ||||
▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines |