##// END OF EJS Templates
fixes for rawfile, annotation, download. It will check now if it's a filenode....
marcink -
r1189:a4e1b955 beta
parent child Browse files
Show More
@@ -74,6 +74,29 class FilesController(BaseRepoController
74 74 h.flash(str(e), category='warning')
75 75 redirect(h.url('files_home', repo_name=repo_name, revision='tip'))
76 76
77
78 def __get_filenode_or_redirect(self, repo_name, cs, path):
79 """
80 Returns file_node, if error occurs or given path is directory,
81 it'll redirect to top level path
82
83 :param repo_name: repo_name
84 :param cs: given changeset
85 :param path: path to lookup
86 """
87
88
89 try:
90 file_node = cs.get_node(path)
91 if file_node.is_dir():
92 raise RepositoryError('given path is a directory')
93 except RepositoryError, e:
94 h.flash(str(e), category='warning')
95 redirect(h.url('files_home', repo_name=repo_name,
96 revision=cs.raw_id))
97
98 return file_node
99
77 100 def index(self, repo_name, revision, f_path):
78 101 #reditect to given revision from form if given
79 102 post_revision = request.POST.get('at_rev', None)
@@ -109,7 +132,7 class FilesController(BaseRepoController
109 132 except (ChangesetDoesNotExistError, VCSError):
110 133 c.url_next = '#'
111 134
112 #files
135 #files or dirs
113 136 try:
114 137 c.files_list = c.changeset.get_node(f_path)
115 138 c.file_history = self._get_history(c.rhodecode_repo,
@@ -124,39 +147,24 class FilesController(BaseRepoController
124 147
125 148 def rawfile(self, repo_name, revision, f_path):
126 149 cs = self.__get_cs_or_redirect(revision, repo_name)
127 try:
128 file_node = cs.get_node(f_path)
129 except RepositoryError, e:
130 h.flash(str(e), category='warning')
131 redirect(h.url('files_home', repo_name=repo_name,
132 revision=cs.raw_id))
150 file_node = self.__get_filenode_or_redirect(repo_name, cs, f_path)
133 151
134 fname = f_path.split('/')[-1].encode('utf8', 'replace')
152 response.content_disposition = 'attachment; filename=%s' % \
153 f_path.split('/')[-1].encode('utf8', 'replace')
154
135 155 response.content_type = file_node.mimetype
136 response.content_disposition = 'attachment; filename=%s' % fname
137 156 return file_node.content
138 157
139 158 def raw(self, repo_name, revision, f_path):
140 159 cs = self.__get_cs_or_redirect(revision, repo_name)
141 try:
142 file_node = cs.get_node(f_path)
143 except RepositoryError, e:
144 h.flash(str(e), category='warning')
145 redirect(h.url('files_home', repo_name=repo_name,
146 revision=cs.raw_id))
160 file_node = self.__get_filenode_or_redirect(repo_name, cs, f_path)
147 161
148 162 response.content_type = 'text/plain'
149
150 163 return file_node.content
151 164
152 165 def annotate(self, repo_name, revision, f_path):
153 166 cs = self.__get_cs_or_redirect(revision, repo_name)
154 try:
155 c.file = cs.get_node(f_path)
156 except RepositoryError, e:
157 h.flash(str(e), category='warning')
158 redirect(h.url('files_home', repo_name=repo_name,
159 revision=cs.raw_id))
167 c.file = self.__get_filenode_or_redirect(repo_name, cs, f_path)
160 168
161 169 c.file_history = self._get_history(c.rhodecode_repo,
162 170 c.file, f_path)
@@ -268,7 +276,7 class FilesController(BaseRepoController
268 276 return render('files/file_diff.html')
269 277
270 278 def _get_history(self, repo, node, f_path):
271 if not node.kind is NodeKind.FILE:
279 if not node.is_file():
272 280 return []
273 281 changesets = node.history
274 282 hist_l = []
General Comments 0
You need to be logged in to leave comments. Login now