Skip to content

Commit 1b7c0c8

Browse files
author
Richard Jones
committed
finally, tables autosize columns [SF#609070]
1 parent 8134bd1 commit 1b7c0c8

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Fixed:
7272
- added example HTML tempating for vacation flag (sf bug 701722)
7373
- only look for CSV files when importing (thanks Dan Grassi)
7474
- can now unset values in CSV editing (sf bug 704788)
75+
- finally, tables autosize columns (sf bug 609070)
7576

7677

7778
2003-??-?? 0.5.7

roundup/admin.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: admin.py,v 1.45 2003-03-21 04:02:12 richard Exp $
19+
# $Id: admin.py,v 1.46 2003-03-23 06:07:05 richard Exp $
2020

2121
'''Administration commands for maintaining Roundup trackers.
2222
'''
@@ -95,11 +95,11 @@ def props_from_args(self, args):
9595
if arg.find('=') == -1:
9696
raise UsageError, _('argument "%(arg)s" not propname=value'
9797
)%locals()
98-
try:
99-
key, value = arg.split('=')
100-
except ValueError:
98+
l = arg.split('=')
99+
if len(l) < 2:
101100
raise UsageError, _('argument "%(arg)s" not propname=value'
102101
)%locals()
102+
key, value = l[0], '='.join(l[1:])
103103
if value:
104104
props[key] = value
105105
else:
@@ -751,14 +751,25 @@ def do_table(self, args):
751751
752752
Lists all instances of the given class. If the properties are not
753753
specified, all properties are displayed. By default, the column widths
754-
are the width of the property names. The width may be explicitly defined
754+
are the width of the largest value. The width may be explicitly defined
755755
by defining the property as "name:width". For example::
756756
roundup> table priority id,name:10
757757
Id Name
758758
1 fatal-bug
759759
2 bug
760760
3 usability
761761
4 feature
762+
763+
Also to make the width of the column the width of the label,
764+
leave a trailing : without a width on the property. E.G.
765+
roundup> table priority id,name:
766+
Id Name
767+
1 fata
768+
2 bug
769+
3 usab
770+
4 feat
771+
772+
will result in a the 4 character wide "Name" column.
762773
'''
763774
if len(args) < 1:
764775
raise UsageError, _('Not enough arguments supplied')
@@ -790,10 +801,19 @@ def do_table(self, args):
790801
for spec in prop_names:
791802
if ':' in spec:
792803
name, width = spec.split(':')
793-
props.append((name, int(width)))
804+
if width == '':
805+
props.append((name, len(spec)))
806+
else:
807+
props.append((name, int(width)))
794808
else:
795-
props.append((spec, len(spec)))
796-
809+
# this is going to be slow
810+
maxlen = len(spec)
811+
for nodeid in cl.list():
812+
curlen = len(str(cl.get(nodeid, spec)))
813+
if curlen > maxlen:
814+
maxlen = curlen
815+
props.append((spec, maxlen))
816+
797817
# now display the heading
798818
print ' '.join([name.capitalize().ljust(width) for name,width in props])
799819

0 commit comments

Comments
 (0)