comparison mercurial/hgweb/hgwebdir_mod.py @ 4246:a80502f47552

hgwebdir: break templater -> templater circular reference This is essentially another instance of the same problem fixed by the parent changeset. See its commit message for the details.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Mon, 19 Mar 2007 19:07:37 -0300
parents ef14fdb675da
children ca639faa38a2
comparison
equal deleted inserted replaced
4245:3f2e334937ce 4246:a80502f47552
170 for key, row in rows: 170 for key, row in rows:
171 row['parity'] = parity 171 row['parity'] = parity
172 parity = 1 - parity 172 parity = 1 - parity
173 yield row 173 yield row
174 174
175 virtual = req.env.get("PATH_INFO", "").strip('/') 175 try:
176 if virtual.startswith('static/'): 176 virtual = req.env.get("PATH_INFO", "").strip('/')
177 static = os.path.join(templater.templatepath(), 'static') 177 if virtual.startswith('static/'):
178 fname = virtual[7:] 178 static = os.path.join(templater.templatepath(), 'static')
179 req.write(staticfile(static, fname, req) or 179 fname = virtual[7:]
180 tmpl('error', error='%r not found' % fname)) 180 req.write(staticfile(static, fname, req) or
181 elif virtual: 181 tmpl('error', error='%r not found' % fname))
182 while virtual: 182 elif virtual:
183 real = dict(self.repos).get(virtual) 183 while virtual:
184 real = dict(self.repos).get(virtual)
185 if real:
186 break
187 up = virtual.rfind('/')
188 if up < 0:
189 break
190 virtual = virtual[:up]
184 if real: 191 if real:
185 break 192 req.env['REPO_NAME'] = virtual
186 up = virtual.rfind('/') 193 try:
187 if up < 0: 194 repo = hg.repository(parentui, real)
188 break 195 hgweb(repo).run_wsgi(req)
189 virtual = virtual[:up] 196 except IOError, inst:
190 if real: 197 req.write(tmpl("error", error=inst.strerror))
191 req.env['REPO_NAME'] = virtual 198 except hg.RepoError, inst:
192 try: 199 req.write(tmpl("error", error=str(inst)))
193 repo = hg.repository(parentui, real) 200 else:
194 hgweb(repo).run_wsgi(req) 201 req.write(tmpl("notfound", repo=virtual))
195 except IOError, inst:
196 req.write(tmpl("error", error=inst.strerror))
197 except hg.RepoError, inst:
198 req.write(tmpl("error", error=str(inst)))
199 else: 202 else:
200 req.write(tmpl("notfound", repo=virtual)) 203 if req.form.has_key('static'):
201 else: 204 static = os.path.join(templater.templatepath(), "static")
202 if req.form.has_key('static'): 205 fname = req.form['static'][0]
203 static = os.path.join(templater.templatepath(), "static") 206 req.write(staticfile(static, fname, req)
204 fname = req.form['static'][0] 207 or tmpl("error", error="%r not found" % fname))
205 req.write(staticfile(static, fname, req) 208 else:
206 or tmpl("error", error="%r not found" % fname)) 209 sortable = ["name", "description", "contact", "lastchange"]
207 else: 210 sortcolumn, descending = self.repos_sorted
208 sortable = ["name", "description", "contact", "lastchange"] 211 if req.form.has_key('sort'):
209 sortcolumn, descending = self.repos_sorted 212 sortcolumn = req.form['sort'][0]
210 if req.form.has_key('sort'): 213 descending = sortcolumn.startswith('-')
211 sortcolumn = req.form['sort'][0] 214 if descending:
212 descending = sortcolumn.startswith('-') 215 sortcolumn = sortcolumn[1:]
213 if descending: 216 if sortcolumn not in sortable:
214 sortcolumn = sortcolumn[1:] 217 sortcolumn = ""
215 if sortcolumn not in sortable: 218
216 sortcolumn = "" 219 sort = [("sort_%s" % column,
217 220 "%s%s" % ((not descending and column == sortcolumn)
218 sort = [("sort_%s" % column, 221 and "-" or "", column))
219 "%s%s" % ((not descending and column == sortcolumn) 222 for column in sortable]
220 and "-" or "", column)) 223 req.write(tmpl("index", entries=entries,
221 for column in sortable] 224 sortcolumn=sortcolumn, descending=descending,
222 req.write(tmpl("index", entries=entries, 225 **dict(sort)))
223 sortcolumn=sortcolumn, descending=descending, 226 finally:
224 **dict(sort))) 227 tmpl = None