~fabricematrat/charmworld/redirect-charm

« back to all changes in this revision

Viewing changes to charmworld/views/charms.py

  • Committer: Fabrice Matrat
  • Date: 2015-02-09 10:26:43 UTC
  • Revision ID: fabricematrat@gmail.com-20150209102643-8s11n2vxp9zu7nbk
first redirect for charmworld to jujucharms.com including personal, distro, promulgated charms

Show diffs side-by-side

added added

removed removed

Lines of Context:
293
293
    renderer="charmworld:templates/charm.pt")
294
294
def personal_charm(request):
295
295
    _reconcile_revision(request)
296
 
    return _charm_view(request, find_charm(request))
 
296
    redirect_url = request.registry.settings.get('redirect_jujucharms')
 
297
 
 
298
    match = request.matchdict
 
299
    if 'revision' in match:
 
300
        location = ('{url}/u/{owner}/{charm}/{series}/{revision}'.
 
301
                    format(url=redirect_url,
 
302
                           owner=match['owner'],
 
303
                           charm=match['charm'],
 
304
                           series=match['series'],
 
305
                           revision=match['revision']))
 
306
    else:
 
307
        location = ('{url}/u/{owner}/{charm}/{series}'.
 
308
                    format(url=redirect_url,
 
309
                           owner=match['owner'],
 
310
                           charm=match['charm'],
 
311
                           series=match['series']))
 
312
    raise HTTPMovedPermanently(location=location)
297
313
 
298
314
 
299
315
@cached_view_config(
316
332
    route_name="charm",
317
333
    renderer="charmworld:templates/charm.pt")
318
334
def distro_charm(request):
 
335
    _reconcile_revision(request)
319
336
    redirect_url = request.registry.settings.get('redirect_jujucharms')
320
 
    raise HTTPMovedPermanently(
321
 
        location='{url}/{charm}/{series}'.
322
 
                  format(url = redirect_url,
323
 
                         charm=request.matchdict['charm'],
324
 
                         series=request.matchdict['series']))
 
337
    match = request.matchdict
 
338
    if 'revision' in match:
 
339
        location = ('{url}/{charm}/{series}/{revision}'.
 
340
                    format(url=redirect_url,
 
341
                           charm=match['charm'],
 
342
                           series=match['series'],
 
343
                           revision=match['revision']))
 
344
    else:
 
345
        location = ('{url}/{charm}/{series}'.
 
346
                    format(url=redirect_url,
 
347
                           charm=match['charm'],
 
348
                           series=match['series']))
 
349
    raise HTTPMovedPermanently(location=location)
325
350
 
326
351
 
327
352
@cached_view_config(