##// END OF EJS Templates
clean and fixes in files controller
marcink -
r1137:82344ce0 beta
parent child Browse files
Show More
@@ -56,9 +56,11 b' class FilesController(BaseRepoController'
56 56 super(FilesController, self).__before__()
57 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 ucure it redirects to given
61 Safe way to get changeset if error occur it redirects to tip with
62 proper message
63
62 64 :param rev: revision to fetch
63 65 :param repo_name: repo name to redirect after
64 66 """
@@ -74,27 +76,25 b' class FilesController(BaseRepoController'
74 76 redirect(h.url('files_home', repo_name=repo_name, revision='tip'))
75 77
76 78 def index(self, repo_name, revision, f_path):
77
78 try:
79 #reditect to given revision from form
79 #reditect to given revision from form if given
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 revision=post_revision, f_path=f_path))
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 prev_rev = c.rhodecode_repo.get_changeset(cur_rev).prev(c.branch).raw_id
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 revision=prev_rev, f_path=f_path)
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 next_rev = c.rhodecode_repo.get_changeset(cur_rev).next(c.branch).raw_id
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 revision=next_rev, f_path=f_path)
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 c.file_history = self._get_history(c.rhodecode_repo, c.files_list, f_path)
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 redirect(h.url('files_home', repo_name=repo_name, revision=revision))
120
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
120 redirect(h.url('files_home', repo_name=repo_name,
121 revision=revision))
129 122
130 123
131 124 return render('files/files.html')
132 125
133 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 128 try:
136 129 file_node = cs.get_node(f_path)
137 130 except RepositoryError, e:
138 131 h.flash(str(e), category='warning')
139 redirect(h.url('files_home', repo_name=repo_name, revision=cs.raw_id))
132 redirect(h.url('files_home', repo_name=repo_name,
133 revision=cs.raw_id))
140 134
141 135 fname = f_path.split('/')[-1].encode('utf8', 'replace')
142 136 response.content_type = file_node.mimetype
@@ -144,26 +138,29 b' class FilesController(BaseRepoController'
144 138 return file_node.content
145 139
146 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 142 try:
149 143 file_node = cs.get_node(f_path)
150 144 except RepositoryError, e:
151 145 h.flash(str(e), category='warning')
152 redirect(h.url('files_home', repo_name=repo_name, revision=cs.raw_id))
146 redirect(h.url('files_home', repo_name=repo_name,
147 revision=cs.raw_id))
153 148
154 149 response.content_type = 'text/plain'
155 150
156 151 return file_node.content
157 152
158 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 155 try:
161 156 c.file = cs.get_node(f_path)
162 157 except RepositoryError, e:
163 158 h.flash(str(e), category='warning')
164 redirect(h.url('files_home', repo_name=repo_name, revision=cs.raw_id))
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, c.file, f_path)
162 c.file_history = self._get_history(c.rhodecode_repo,
163 c.file, f_path)
167 164 c.cs = cs
168 165 c.f_path = f_path
169 166
General Comments 0
You need to be logged in to leave comments. Login now