omarestrella / repolab

Python and Django based Git and Mercurial repository viewer
MIT License
0 stars 0 forks source link

Breadcrumbs link to master #2

Closed mbrown1413 closed 12 years ago

mbrown1413 commented 12 years ago

Right now the directory breadcrumbs always link to the master branch. This is because I couldn't pass the changeset into the path_breadcrumbs filter (filters have a max of 2 arguments). I'm considering turning the template filter into a template tag, which would fix the argument passing problem.

omarestrella commented 12 years ago

If you want to use the filter, can you pass in the repo itself and get its latest changeset instead of passing in repo.slug? Maybe: repo.get_repo().get_changeset()

mbrown1413 commented 12 years ago

But it's not necessarily the latest changeset that we're viewing.

The other option is to do this inside the view, then pass it in as context. Here's an idea for the context format:

context['breadcrumbs'] = [
    {'name': 'RepoLab', 'url': 'http://127.0.0.1:8001/repo/repolab/tree/master/'},
    {'name': 'repolab', 'url': 'http://127.0.0.1:8001/repo/repolab/tree/master/repolab/'},
    {'name': 'templates', 'url': None},  # Current node, no href
]
omarestrella commented 12 years ago

That is a possibility. Should we handle this in a mixin? My only problem with that is that there is yet another mixin to inherit from. Id rather stay away from another mixin.

Theres got to be a way to do get_current_changeset() or something similar for a node. Or writing a context processor that makes the currently browsed changeset available to the template and pass that to a filter or tag? So we can do something like: {% breadcrumbs repo current_changeset %}

mbrown1413 commented 12 years ago

The template already has access to everything it needs. The problem is that django template filters can only accept two arguments, but we need repo slug, current changeset, and path. From the django documentation on Writing custom template filters:

Custom filters are just Python functions that take one or two arguments:

  • The value of the variable (input) -- not necessarily a string.
  • The value of the argument -- this can have a default value, or be left out altogether.

We could write a template tag though.

About writing a mixin: we can just write it into the view and factor it out into a mixin later if we need it somewhere else. I'm definitely leaning towards writing this in the view.