Show More
@@ -56,9 +56,11 b' class FilesController(BaseRepoController' | |||||
56 | super(FilesController, self).__before__() |
|
56 | super(FilesController, self).__before__() | |
57 | c.cut_off_limit = self.cut_off_limit |
|
57 | c.cut_off_limit = self.cut_off_limit | |
58 |
|
58 | |||
59 | def __get_cs(self, rev, repo_name): |
|
59 | def __get_cs_or_redirect(self, rev, repo_name): | |
60 | """ |
|
60 | """ | |
61 |
Safe way to get changeset if error |
|
61 | Safe way to get changeset if error occur it redirects to tip with | |
|
62 | proper message | |||
|
63 | ||||
62 | :param rev: revision to fetch |
|
64 | :param rev: revision to fetch | |
63 | :param repo_name: repo name to redirect after |
|
65 | :param repo_name: repo name to redirect after | |
64 | """ |
|
66 | """ | |
@@ -74,27 +76,25 b' class FilesController(BaseRepoController' | |||||
74 | redirect(h.url('files_home', repo_name=repo_name, revision='tip')) |
|
76 | redirect(h.url('files_home', repo_name=repo_name, revision='tip')) | |
75 |
|
77 | |||
76 | def index(self, repo_name, revision, f_path): |
|
78 | def index(self, repo_name, revision, f_path): | |
77 |
|
79 | #reditect to given revision from form if given | ||
78 | try: |
|
|||
79 | #reditect to given revision from form |
|
|||
80 |
|
|
80 | post_revision = request.POST.get('at_rev', None) | |
81 |
|
|
81 | if post_revision: | |
82 | post_revision = c.rhodecode_repo.get_changeset(post_revision).raw_id |
|
82 | cs = self.__get_cs_or_redirect(revision, repo_name) | |
83 |
|
|
83 | redirect(url('files_home', repo_name=c.repo_name, | |
84 |
|
|
84 | revision=cs.raw_id, f_path=f_path)) | |
|
85 | ||||
85 |
|
86 | |||
|
87 | c.changeset = self.__get_cs_or_redirect(revision, repo_name) | |||
86 |
|
|
88 | c.branch = request.GET.get('branch', None) | |
87 |
|
||||
88 |
|
|
89 | c.f_path = f_path | |
89 |
|
90 | |||
90 | c.changeset = c.rhodecode_repo.get_changeset(revision) |
|
|||
91 |
|
|
91 | cur_rev = c.changeset.revision | |
92 |
|
92 | |||
93 |
|
|
93 | #prev link | |
94 |
|
|
94 | try: | |
95 |
|
|
95 | prev_rev = c.rhodecode_repo.get_changeset(cur_rev).prev(c.branch) | |
96 |
|
|
96 | c.url_prev = url('files_home', repo_name=c.repo_name, | |
97 |
|
|
97 | revision=prev_rev.raw_id, f_path=f_path) | |
98 |
|
|
98 | if c.branch: | |
99 |
|
|
99 | c.url_prev += '?branch=%s' % c.branch | |
100 |
|
|
100 | except (ChangesetDoesNotExistError, VCSError): | |
@@ -102,9 +102,9 b' class FilesController(BaseRepoController' | |||||
102 |
|
102 | |||
103 |
|
|
103 | #next link | |
104 |
|
|
104 | try: | |
105 |
|
|
105 | next_rev = c.rhodecode_repo.get_changeset(cur_rev).next(c.branch) | |
106 |
|
|
106 | c.url_next = url('files_home', repo_name=c.repo_name, | |
107 |
|
|
107 | revision=next_rev.raw_id, f_path=f_path) | |
108 |
|
|
108 | if c.branch: | |
109 |
|
|
109 | c.url_next += '?branch=%s' % c.branch | |
110 |
|
|
110 | except (ChangesetDoesNotExistError, VCSError): | |
@@ -113,30 +113,24 b' class FilesController(BaseRepoController' | |||||
113 |
|
|
113 | #files | |
114 |
|
|
114 | try: | |
115 |
|
|
115 | c.files_list = c.changeset.get_node(f_path) | |
116 |
|
|
116 | c.file_history = self._get_history(c.rhodecode_repo, | |
|
117 | c.files_list, f_path) | |||
117 |
|
|
118 | except RepositoryError, e: | |
118 |
|
|
119 | h.flash(str(e), category='warning') | |
119 |
|
|
120 | redirect(h.url('files_home', repo_name=repo_name, | |
120 |
|
121 | revision=revision)) | ||
121 | except EmptyRepositoryError, e: |
|
|||
122 | h.flash(_('There are no files yet'), category='warning') |
|
|||
123 | redirect(h.url('summary_home', repo_name=repo_name)) |
|
|||
124 |
|
||||
125 | except RepositoryError, e: |
|
|||
126 | h.flash(str(e), category='warning') |
|
|||
127 | redirect(h.url('files_home', repo_name=repo_name, revision='tip')) |
|
|||
128 |
|
||||
129 |
|
122 | |||
130 |
|
123 | |||
131 | return render('files/files.html') |
|
124 | return render('files/files.html') | |
132 |
|
125 | |||
133 | def rawfile(self, repo_name, revision, f_path): |
|
126 | def rawfile(self, repo_name, revision, f_path): | |
134 | cs = self.__get_cs(revision, repo_name) |
|
127 | cs = self.__get_cs_or_redirect(revision, repo_name) | |
135 | try: |
|
128 | try: | |
136 | file_node = cs.get_node(f_path) |
|
129 | file_node = cs.get_node(f_path) | |
137 | except RepositoryError, e: |
|
130 | except RepositoryError, e: | |
138 | h.flash(str(e), category='warning') |
|
131 | h.flash(str(e), category='warning') | |
139 |
redirect(h.url('files_home', repo_name=repo_name, |
|
132 | redirect(h.url('files_home', repo_name=repo_name, | |
|
133 | revision=cs.raw_id)) | |||
140 |
|
134 | |||
141 | fname = f_path.split('/')[-1].encode('utf8', 'replace') |
|
135 | fname = f_path.split('/')[-1].encode('utf8', 'replace') | |
142 | response.content_type = file_node.mimetype |
|
136 | response.content_type = file_node.mimetype | |
@@ -144,26 +138,29 b' class FilesController(BaseRepoController' | |||||
144 | return file_node.content |
|
138 | return file_node.content | |
145 |
|
139 | |||
146 | def raw(self, repo_name, revision, f_path): |
|
140 | def raw(self, repo_name, revision, f_path): | |
147 | cs = self.__get_cs(revision, repo_name) |
|
141 | cs = self.__get_cs_or_redirect(revision, repo_name) | |
148 | try: |
|
142 | try: | |
149 | file_node = cs.get_node(f_path) |
|
143 | file_node = cs.get_node(f_path) | |
150 | except RepositoryError, e: |
|
144 | except RepositoryError, e: | |
151 | h.flash(str(e), category='warning') |
|
145 | h.flash(str(e), category='warning') | |
152 |
redirect(h.url('files_home', repo_name=repo_name, |
|
146 | redirect(h.url('files_home', repo_name=repo_name, | |
|
147 | revision=cs.raw_id)) | |||
153 |
|
148 | |||
154 | response.content_type = 'text/plain' |
|
149 | response.content_type = 'text/plain' | |
155 |
|
150 | |||
156 | return file_node.content |
|
151 | return file_node.content | |
157 |
|
152 | |||
158 | def annotate(self, repo_name, revision, f_path): |
|
153 | def annotate(self, repo_name, revision, f_path): | |
159 | cs = self.__get_cs(revision, repo_name) |
|
154 | cs = self.__get_cs_or_redirect(revision, repo_name) | |
160 | try: |
|
155 | try: | |
161 | c.file = cs.get_node(f_path) |
|
156 | c.file = cs.get_node(f_path) | |
162 | except RepositoryError, e: |
|
157 | except RepositoryError, e: | |
163 | h.flash(str(e), category='warning') |
|
158 | h.flash(str(e), category='warning') | |
164 |
redirect(h.url('files_home', repo_name=repo_name, |
|
159 | redirect(h.url('files_home', repo_name=repo_name, | |
|
160 | revision=cs.raw_id)) | |||
165 |
|
161 | |||
166 |
c.file_history = self._get_history(c.rhodecode_repo, |
|
162 | c.file_history = self._get_history(c.rhodecode_repo, | |
|
163 | c.file, f_path) | |||
167 | c.cs = cs |
|
164 | c.cs = cs | |
168 | c.f_path = f_path |
|
165 | c.f_path = f_path | |
169 |
|
166 |
General Comments 0
You need to be logged in to leave comments.
Login now