Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/views/utils/snapshot_context.py
Show All 17 Lines | from swh.web.browse.utils import ( | ||||
get_snapshot_context, get_directory_entries, gen_directory_link, | get_snapshot_context, get_directory_entries, gen_directory_link, | ||||
gen_revision_link, request_content, gen_content_link, | gen_revision_link, request_content, gen_content_link, | ||||
prepare_content_for_display, content_display_max_size, | prepare_content_for_display, content_display_max_size, | ||||
format_log_entries, gen_revision_log_link, | format_log_entries, gen_revision_log_link, | ||||
get_readme_to_display, get_swh_persistent_ids, | get_readme_to_display, get_swh_persistent_ids, | ||||
gen_snapshot_link, process_snapshot_branches | gen_snapshot_link, process_snapshot_branches | ||||
) | ) | ||||
from swh.web.common import service | from swh.web.common import service, highlightjs | ||||
from swh.web.common.exc import ( | from swh.web.common.exc import ( | ||||
handle_view_exception, NotFoundExc | handle_view_exception, NotFoundExc | ||||
) | ) | ||||
from swh.web.common.utils import ( | from swh.web.common.utils import ( | ||||
reverse, gen_path_info, format_utc_iso_date, swh_object_icons | reverse, gen_path_info, format_utc_iso_date, swh_object_icons | ||||
) | ) | ||||
_empty_snapshot_id = snapshot_identifier({'branches': {}}) | _empty_snapshot_id = snapshot_identifier({'branches': {}}) | ||||
▲ Show 20 Lines • Show All 359 Lines • ▼ Show 20 Lines | return render(request, 'browse/directory.html', | ||||
'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_type=None, | ||||
origin_url=None, timestamp=None, path=None): | origin_url=None, timestamp=None, path=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_type, origin_url, | ||||
timestamp, path, | timestamp, path, | ||||
Show All 36 Lines | def browse_snapshot_content(request, snapshot_id=None, origin_type=None, | ||||
language = None | language = None | ||||
mimetype = None | mimetype = None | ||||
if content_data and content_data['raw_data'] is not None: | if content_data and content_data['raw_data'] is not None: | ||||
content_display_data = prepare_content_for_display( | content_display_data = prepare_content_for_display( | ||||
content_data['raw_data'], content_data['mimetype'], path) | content_data['raw_data'], content_data['mimetype'], path) | ||||
content = content_display_data['content_data'] | content = content_display_data['content_data'] | ||||
language = content_display_data['language'] | language = content_display_data['language'] | ||||
mimetype = content_display_data['mimetype'] | mimetype = content_display_data['mimetype'] | ||||
vlorentz: "Override language with **user-**selected language" | |||||
Done Inline Actionsok kalpitk: ok | |||||
# Override language with user-selected language | |||||
if selected_language is not None: | |||||
language = selected_language | |||||
available_languages = None | |||||
if mimetype and 'text/' in mimetype: | |||||
available_languages = highlightjs._hljs_languages | |||||
browse_view_name = 'browse-' + swh_type + '-directory' | browse_view_name = 'browse-' + swh_type + '-directory' | ||||
breadcrumbs = [] | breadcrumbs = [] | ||||
path_info = gen_path_info(filepath) | path_info = gen_path_info(filepath) | ||||
if root_sha1_git: | if root_sha1_git: | ||||
breadcrumbs.append({'name': root_sha1_git[:7], | breadcrumbs.append({'name': root_sha1_git[:7], | ||||
'url': reverse(browse_view_name, | 'url': reverse(browse_view_name, | ||||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | return render(request, 'browse/content.html', | ||||
{'heading': heading, | {'heading': heading, | ||||
'swh_object_name': 'Content', | 'swh_object_name': 'Content', | ||||
'swh_object_metadata': content_metadata, | 'swh_object_metadata': content_metadata, | ||||
'content': content, | 'content': content, | ||||
'content_size': content_size, | 'content_size': content_size, | ||||
'max_content_size': content_display_max_size, | 'max_content_size': content_display_max_size, | ||||
'mimetype': mimetype, | 'mimetype': mimetype, | ||||
'language': language, | 'language': language, | ||||
'available_languages': available_languages, | |||||
'breadcrumbs': breadcrumbs if root_sha1_git else [], | 'breadcrumbs': breadcrumbs if root_sha1_git else [], | ||||
'top_right_link': { | 'top_right_link': { | ||||
'url': content_raw_url, | 'url': content_raw_url, | ||||
'icon': swh_object_icons['content'], | 'icon': swh_object_icons['content'], | ||||
'text': 'Raw File' | 'text': 'Raw File' | ||||
}, | }, | ||||
'snapshot_context': snapshot_context, | 'snapshot_context': snapshot_context, | ||||
'vault_cooking': None, | 'vault_cooking': None, | ||||
▲ Show 20 Lines • Show All 338 Lines • Show Last 20 Lines |
"Override language with user-selected language"