From 0eab479ca0b09bc58c8f77943039edbd651746ad Mon Sep 17 00:00:00 2001 From: cmpilato Date: Fri, 4 Nov 2005 19:20:55 +0000 Subject: [PATCH] Make the various file-related views available from the directory and log views on a per-entry/revision basis. Template authors can choose to ignore the 'viewable'-ness of an item if they choose. In the process, this makes the directory view always link to the markup view for files (instead of sometimes doing markup, sometimes checkout). Consistent, predictable UI, folks ... * viewcvs/lib/viewcvs.py (get_file_view_info): New. (nav_header_data, view_directory, view_log): Use new get_file_view_info to populate file navigation links. * viewcvs/templates/markup.ezt If a file isn't viewable, show a warning instead of the markup. * viewcvs/website/upgrading.html Track changes in the data dictionary. * viewcvs/website/template-authoring-guide.html Track changes in the data dictionary, and fill in a few blanks here and there. git-svn-id: http://viewvc.tigris.org/svn/viewvc/trunk@1150 8cb11bc2-c004-0410-86c3-e597b4017df7 --- lib/viewcvs.py | 179 +++++++++++++------------- templates/markup.ezt | 4 + website/template-authoring-guide.html | 76 ++++++++--- website/upgrading.html | 4 +- 4 files changed, 155 insertions(+), 108 deletions(-) diff --git a/lib/viewcvs.py b/lib/viewcvs.py index 8f03f5fa..94796455 100644 --- a/lib/viewcvs.py +++ b/lib/viewcvs.py @@ -892,6 +892,45 @@ def is_viewable(mime_type): return 1 return 0 +def get_file_view_info(request, where, rev=None, mime_type=None): + """Return common hrefs and a viewability flag used for various views + of FILENAME at revision REV whose MIME type is MIME_TYPE.""" + rev = rev and str(rev) or None + mime_type = mime_type or request.mime_type + + download_text_href = annotate_href = revision_href = None + view_href = request.get_url(view_func=view_markup, + where=where, + pathtype=vclib.FILE, + params={'rev': rev}, + escape=1) + download_href = request.get_url(view_func=view_checkout, + where=where, + pathtype=vclib.FILE, + params={'rev': rev}, + escape=1) + if not is_plain_text(mime_type): + download_text_href = request.get_url(view_func=view_checkout, + where=where, + pathtype=vclib.FILE, + params={'content-type': 'text/plain', + 'rev': rev}, + escape=1) + if cfg.options.allow_annotate: + annotate_href = request.get_url(view_func=view_annotate, + where=where, + pathtype=vclib.FILE, + params={'annotate': rev}, + escape=1) + if request.roottype == 'svn': + revision_href = request.get_url(view_func=view_revision, + params={'rev': rev}, + escape=1) + + return view_href, download_href, download_text_href, \ + annotate_href, revision_href, ezt.boolean(is_viewable(mime_type)) + + # Regular expressions for location text that looks like URLs and email # addresses. Note that the regexps assume the text is already HTML-encoded. _re_rewrite_url = re.compile('((http|https|ftp|file|svn|svn\+ssh)(://[-a-zA-Z0-9%.~:_/]+)((\?|\&)([-a-zA-Z0-9%.~:_]+)=([-a-zA-Z0-9%.~:_])+)*(#([-a-zA-Z0-9%.~:_]+)?)?)') @@ -1031,39 +1070,23 @@ def common_template_data(request): return data def nav_header_data(request, rev, orig_path): + view_href, download_href, download_text_href, annotate_href, \ + revision_href, is_viewable \ + = get_file_view_info(request, request.where, rev, request.mime_type) + data = common_template_data(request) data.update({ 'rev' : rev, - 'annotate_href': None, - 'download_text_href' : None, - 'revision_href': None, - 'orig_path': None, - 'orig_href': None, + 'view_href' : view_href, + 'annotate_href' : annotate_href, + 'download_href' : download_href, + 'download_text_href' : download_text_href, + 'revision_href' : revision_href, + 'viewable' : is_viewable, + 'orig_path' : None, + 'orig_href' : None, }) - data['view_href'] = request.get_url(view_func=view_markup, - params={'rev': rev}, - escape=1) - data['download_href'] = request.get_url(view_func=view_checkout, - params={'rev': rev}, - escape=1) - - if not is_plain_text(request.mime_type): - data['download_text_href'] = \ - request.get_url(view_func=view_checkout, - params={'content-type': 'text/plain', 'rev': rev}, - escape=1) - - if cfg.options.allow_annotate: - data['annotate_href'] = request.get_url(view_func=view_annotate, - params={'annotate': rev}, - escape=1) - - if request.roottype == 'svn': - data['revision_href'] = request.get_url(view_func=view_revision, - params={'rev': rev}, - escape=1) - if orig_path != request.path_parts: path = _path_join(orig_path) data['orig_path'] = path @@ -1540,10 +1563,11 @@ def view_directory(request): where_prefix = where and where + '/' for file in file_data: - row = _item(viewable=None, graph_href=None, author=None, log=None, - log_file=None, log_rev=None, - state=None, size=None, mime_type=None, date=None, - ago=None) + row = _item(graph_href=None, author=None, log=None, log_file=None, + log_rev=None, state=None, size=None, mime_type=None, + date=None, ago=None, view_href=None, log_href=None, + revision_href=None, annotate_href=None, download_href=None, + download_text_href=None, viewable=ezt.boolean(0)) row.rev = file.rev row.author = file.author @@ -1601,22 +1625,14 @@ def view_directory(request): ### for Subversion, we should first try to get this from the properties row.mime_type = guess_mime(file.name) - row.viewable = ezt.boolean(is_viewable(row.mime_type)) - - view = row.viewable and view_markup or view_checkout - + row.view_href, row.download_href, row.download_text_href, \ + row.annotate_href, row.revision_href, row.viewable \ + = get_file_view_info(request, file_where, file.rev, row.mime_type) row.log_href = request.get_url(view_func=view_log, where=file_where, pathtype=vclib.FILE, params={}, escape=1) - - row.view_href = request.get_url(view_func=view, - where=file_where, - pathtype=vclib.FILE, - params={'rev': str(file.rev)}, - escape=1) - if cfg.options.use_cvsgraph and request.roottype == 'cvs': row.graph_href = request.get_url(view_func=view_cvsgraph, where=file_where, @@ -1868,6 +1884,7 @@ def view_log(request): entry.download_href = None entry.download_text_href = None entry.annotate_href = None + entry.revision_href = None entry.sel_for_diff_href = None entry.diff_to_sel_href = None entry.diff_to_prev_href = None @@ -1914,10 +1931,6 @@ def view_log(request): entry.copy_path = rev.copy_path entry.copy_rev = rev.copy_rev - entry.revision_href = request.get_url(view_func=view_revision, - params={'rev': rev.string}, - escape=1) - if entry.orig_path: entry.orig_href = request.get_url(view_func=view_log, where=entry.orig_path, @@ -1935,24 +1948,14 @@ def view_log(request): # view/download links if pathtype is vclib.FILE: - entry.view_href = request.get_url(view_func=view_markup, - params={'rev': rev.string}, - escape=1) - entry.download_href = request.get_url(view_func=view_checkout, + entry.view_href, entry.download_href, entry.download_text_href, \ + entry.annotate_href, entry.revision_href, entry.viewable \ + = get_file_view_info(request, request.where, rev.string, + request.mime_type) + else: + entry.revision_href = request.get_url(view_func=view_revision, params={'rev': rev.string}, escape=1) - if not is_plain_text(request.mime_type): - entry.download_text_href = \ - request.get_url(view_func=view_checkout, - params={'content-type': 'text/plain', - 'rev': rev.string}, - escape=1) - if cfg.options.allow_annotate: - entry.annotate_href = request.get_url(view_func=view_annotate, - params={'annotate': rev.string}, - escape=1) - - else: entry.view_href = request.get_url(view_func=view_directory, where=rev.filename, pathtype=vclib.DIR, @@ -2017,10 +2020,12 @@ def view_log(request): 'human_readable' : ezt.boolean(diff_format in ('h', 'l')), 'log_pagestart' : None, 'entries': entries, + 'viewable' : ezt.boolean(0), 'view_href' : None, 'download_href': None, 'download_text_href': None, 'annotate_href': None, + 'tag_viewable' : ezt.boolean(0), 'tag_view_href' : None, 'tag_download_href': None, 'tag_download_text_href': None, @@ -2043,36 +2048,28 @@ def view_log(request): if pathtype is vclib.FILE: if not request.pathrev: - data['view_href'] = request.get_url(view_func=view_markup, - params={'pathrev': None}, - escape=1) - data['download_href'] = request.get_url(view_func=view_checkout, - params={'pathrev': None}, - escape=1) - if not is_plain_text(request.mime_type): - data['download_text_href'] = \ - request.get_url(view_func=view_checkout, - params={'content-type': 'text/plain', - 'pathrev': None}, - escape=1) - if cfg.options.allow_annotate: - data['annotate_href'] = request.get_url(view_func=view_annotate, - params={'pathrev': None}, - escape=1) + view_href, download_href, download_text_href, \ + annotate_href, revision_href, viewable \ + = get_file_view_info(request, request.where, None, request.mime_type) + data.update({ + 'view_href': view_href, + 'download_href': download_href, + 'download_text_href': download_text_href, + 'annotate_href': annotate_href, + 'viewable': viewable, + }) if request.pathrev and request.roottype == 'cvs': - data['tag_view_href'] = request.get_url(view_func=view_markup, - params={}, escape=1) - data['tag_download_href'] = \ - request.get_url(view_func=view_checkout, params={}, escape=1) - if not is_plain_text(request.mime_type): - data['tag_download_text_href'] = \ - request.get_url(view_func=view_checkout, - params={'content-type': 'text/plain'}, - escape=1) - if cfg.options.allow_annotate: - data['tag_annotate_href'] = \ - request.get_url(view_func=view_annotate, params={}, escape=1) + view_href, download_href, download_text_href, \ + annotate_href, revision_href, viewable \ + = get_file_view_info(request, request.where, None, request.mime_type) + data.update({ + 'tag_view_href': view_href, + 'tag_download_href': download_href, + 'tag_download_text_href': download_text_href, + 'tag_annotate_href': annotate_href, + 'tag_viewable': viewable, + }) else: if not request.pathrev: data['view_href'] = request.get_url(view_func=view_directory, diff --git a/templates/markup.ezt b/templates/markup.ezt index 50934c08..220bb877 100644 --- a/templates/markup.ezt +++ b/templates/markup.ezt @@ -43,6 +43,10 @@ Revision [if-any revision_href][rev]< [end] +[if-any viewable]
[markup]
+[else] +
- Binary file contents not displayed -
+[end] [include "include/footer.ezt"] diff --git a/website/template-authoring-guide.html b/website/template-authoring-guide.html index 6f44bf85..5a992d66 100644 --- a/website/template-authoring-guide.html +++ b/website/template-authoring-guide.html @@ -257,30 +257,36 @@ th { background: rgb(60%,70%,90%); } String ViewCVS file contents as-text download URL for the current resource. + + orig_path + String + When viewing an old file revision through a copy of the file, + this is the old file revision's original path. + + + orig_href + String + URL of a ViewCVS log view for orig_path. + rev String Revision of the current resource. - - view_href - String - URL of the ViewCVS file contents view for the current resource. - revision_href String URL of the Subversion revision view for the current revision. - orig_path - String - When viewing an old file revision through a copy of the file, this is the old file revision's original path. + viewable + Boolean + Whether or not the file's contents are considered human-readable. - orig_href + view_href String - URL of a ViewCVS log view for orig_path. + URL of the ViewCVS file contents view for the current resource. @@ -679,6 +685,11 @@ th { background: rgb(60%,70%,90%); } String Textual description of the time since entries.date. + + entries.annotate_href + + + entries.author String @@ -690,6 +701,16 @@ th { background: rgb(60%,70%,90%); } Date (in UTC if not otherwise configured) of the last modification of the directory entry. + + entries.download_href + + + + + entries.download_text_href + + + entries.errors @@ -740,6 +761,13 @@ th { background: rgb(60%,70%,90%); } Subversion, this is the youngest revision as of the revision of the directory being viewed. + + entries.revision_href + String + URL of the Subversion revision view for the directory entries + current revision. Valid only when roottype is + svn. + entries.size String @@ -754,18 +782,21 @@ th { background: rgb(60%,70%,90%); } entries.pathtype - - + String + Path kind of the directory entry. Valid values: file + (file), dir (directory); may be empty. entries.view_href - + URL of the ViewCVS file contents view for the directory entry. entries.viewable - - + Boolean + Whether or not the directory entry's contents are considered + human-readable. Valid only when entries.pathtype is + file. search_re @@ -1132,6 +1163,11 @@ th { background: rgb(60%,70%,90%); } + + entries.viewable + + + entries.view_href @@ -1237,6 +1273,11 @@ th { background: rgb(60%,70%,90%); } + + tag_viewable + + + tags @@ -1252,6 +1293,11 @@ th { background: rgb(60%,70%,90%); } + + viewable + + + view_href diff --git a/website/upgrading.html b/website/upgrading.html index d68c9acf..66e5599d 100644 --- a/website/upgrading.html +++ b/website/upgrading.html @@ -932,10 +932,10 @@ dir_alternate.ezt, directory.ezt, log.ezt, log_table.ezt renamed to pathrev - + viewable log.ezt, log_table.ezt - removed, used to be a boolean based on the mime type which would determine whether or not the log page would have links to the markup page. + unchanged vsn