Review Board 1.0.5.1

Dashboard: Make table sections able to display links

Updated 9 months, 1 week ago

Ted Tate Reviewers
Basie-Dev
None Basie SVN
Make the recently closed tickets section on the dashboard show links to tickets. This is a general change to the sections.TableSection class and thus will allow other applications utilizing the class to do similar to what is shown in recently closed tickets.
Works with current tests. Adding another test to test link adding.
Review request changed
Updated 9 months, 2 weeks ago (October 14th, 2009, 12:31 p.m.)
Posted 9 months, 2 weeks ago (October 14th, 2009, 12:34 p.m.)

   

  
I'm unsure about doing this.

Cell should always be a tuple when it is a link where the first item is the link itself, and the second item is link text.

Another option would be to always have cell be a tuple where the second item would be empty if cell was not a link.

Overall, I prefer the first way but would like some input.
Review request changed
Updated 9 months, 2 weeks ago (October 14th, 2009, 3:18 p.m.)
Fixed doctests for dash that this change broke.
Review request changed
Updated 9 months, 2 weeks ago (October 14th, 2009, 3:19 p.m.)
  • Probably breaks tests made for the dashboard. Fixes in progress. Will updated diff when done.

    Works with current tests. Adding another test to test link adding.
Current dash doctests now work.
Posted 9 months, 2 weeks ago (October 15th, 2009, 5:05 p.m.)

   

  
/trunk/apps/dash/sections.py (Diff revision 3)
 
since items already come out of a project

items = get_visible(user, project, self.model)

is it necessary to #get_row for item _and_ project?
  1. Nope. I must have added it in during an earlier iteration of this patch and forgot to remove it.
to weight in, if a cell is not a link, then we shouldn't construct <a> tags.
  1. Agreed. I think I have this one fairly sorted now.
but "project" is instance.project. The new argument doesn't appear to be used.
  1. Agreed.
/trunk/apps/tickets/dash_data.py (Diff revision 3)
 
instead of project.slug, can't we use ticket.project.slug ?
Posted 9 months, 2 weeks ago (October 17th, 2009, 11:23 a.m.)
Some suggestions.
/trunk/apps/dash/sections.py (Diff revision 3)
 
You are not using project in self.get_row. Why did you add that parameter?
  1. Loss of sanity I assume.
    
    Fixed.
{% for link,text in row %}
  {% if link %}
    <a href={{ link }}>{{ text|default:"-" }}</a>
  {% else %}
    {{ text|default:"-" }}
{% endif %}

row will be a generator(something iterable) in which the first element can be a link or None and the second element is the text.
  1. Ahhh, the solution I was looking for. I like this much more than the way I was doing it.
You should include a get_absolute_url (http://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.get_absolute_url) method in our FakeEvent model.

from itertools import izip_longest

row_texts = (instance.title, ...)
link = intance.get_absolute_url()
# Fills with None.
return izip_longest([link], row_texts)
  1. So I just discovered that Python 2.5 does not include izip_longest (just izip). I don't think it should be a big issue if we just use zip here for the time being. The only issue is we are being a bit verbose when only having links in the first columns of our table.
  2. Note the import line (from itertools import izip_longest). itertools is a useful module :)
  3. Sorry for being unclear. izip_longest was added in the Python 2.6 version of itertools.
    
    Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49) 
    ...
    >>> import itertools
    >>> dir(itertools)
    ['__doc__', '__file__', '__name__', 'chain', 'count', 'cycle', 'dropwhile', 'groupby', 'ifilter', 'ifilterfalse', 'imap', 'islice', 'izip', 'repeat', 'starmap', 'takewhile', 'tee']
    
/trunk/apps/tickets/dash_data.py (Diff revision 3)
 
ticket url is: ticket.get_absolute_url()

Take a look at apps/tickets/models.py line 51
  1. Fixed.
/trunk/apps/tickets/dash_data.py (Diff revision 3)
 
from itertools import izip_longest

row_texts = (ticket.number, ...)
link = ticket.get_absolute_url()
# Fills with None.
return izip_longest([link], row_texts)
  1. Same comment as above. Currently replaced with this:
    
    links = ticket.get_absolute_url(), None, None, None
    text = ticket.number, ticket.owner, ticket.subject,  formatted_date
    return zip(links,text)
Review request changed
Updated 9 months, 1 week ago (October 20th, 2009, 2:59 a.m.)
Updated diff based on suggestions from Zuzel and Tony.
Ship it!
Posted 9 months, 1 week ago (October 20th, 2009, 11:28 a.m.)
Looks ok :) I will update my diff after your commit so there are no conflicts. -- Waiting for your review.
  1. Code committed in r1538.
/trunk/apps/tickets/dash_data.py (Diff revision 4)
 
This import line is not necessary (you can remove it before the commit, no need to update the diff on review board)