##// 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 b' class FilesController(BaseRepoController'
74 h.flash(str(e), category='warning')
74 h.flash(str(e), category='warning')
75 redirect(h.url('files_home', repo_name=repo_name, revision='tip'))
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 def index(self, repo_name, revision, f_path):
100 def index(self, repo_name, revision, f_path):
78 #reditect to given revision from form if given
101 #reditect to given revision from form if given
79 post_revision = request.POST.get('at_rev', None)
102 post_revision = request.POST.get('at_rev', None)
@@ -109,7 +132,7 b' class FilesController(BaseRepoController'
109 except (ChangesetDoesNotExistError, VCSError):
132 except (ChangesetDoesNotExistError, VCSError):
110 c.url_next = '#'
133 c.url_next = '#'
111
134
112 #files
135 #files or dirs
113 try:
136 try:
114 c.files_list = c.changeset.get_node(f_path)
137 c.files_list = c.changeset.get_node(f_path)
115 c.file_history = self._get_history(c.rhodecode_repo,
138 c.file_history = self._get_history(c.rhodecode_repo,
@@ -124,39 +147,24 b' class FilesController(BaseRepoController'
124
147
125 def rawfile(self, repo_name, revision, f_path):
148 def rawfile(self, repo_name, revision, f_path):
126 cs = self.__get_cs_or_redirect(revision, repo_name)
149 cs = self.__get_cs_or_redirect(revision, repo_name)
127 try:
150 file_node = self.__get_filenode_or_redirect(repo_name, cs, f_path)
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))
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 response.content_type = file_node.mimetype
155 response.content_type = file_node.mimetype
136 response.content_disposition = 'attachment; filename=%s' % fname
137 return file_node.content
156 return file_node.content
138
157
139 def raw(self, repo_name, revision, f_path):
158 def raw(self, repo_name, revision, f_path):
140 cs = self.__get_cs_or_redirect(revision, repo_name)
159 cs = self.__get_cs_or_redirect(revision, repo_name)
141 try:
160 file_node = self.__get_filenode_or_redirect(repo_name, cs, f_path)
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))
147
161
148 response.content_type = 'text/plain'
162 response.content_type = 'text/plain'
149
150 return file_node.content
163 return file_node.content
151
164
152 def annotate(self, repo_name, revision, f_path):
165 def annotate(self, repo_name, revision, f_path):
153 cs = self.__get_cs_or_redirect(revision, repo_name)
166 cs = self.__get_cs_or_redirect(revision, repo_name)
154 try:
167 c.file = self.__get_filenode_or_redirect(repo_name, cs, f_path)
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))
160
168
161 c.file_history = self._get_history(c.rhodecode_repo,
169 c.file_history = self._get_history(c.rhodecode_repo,
162 c.file, f_path)
170 c.file, f_path)
@@ -268,7 +276,7 b' class FilesController(BaseRepoController'
268 return render('files/file_diff.html')
276 return render('files/file_diff.html')
269
277
270 def _get_history(self, repo, node, f_path):
278 def _get_history(self, repo, node, f_path):
271 if not node.kind is NodeKind.FILE:
279 if not node.is_file():
272 return []
280 return []
273 changesets = node.history
281 changesets = node.history
274 hist_l = []
282 hist_l = []
General Comments 0
You need to be logged in to leave comments. Login now