~mhall119/ubuntu-api-website/content-editing

« back to all changes in this revision

Viewing changes to developer_network/web/views.py

  • Committer: Michael Hall
  • Date: 2014-02-07 18:39:18 UTC
  • Revision ID: mhall119@ubuntu.com-20140207183918-z8niczhvqmb42uwa
Make the 2-column namespace listing balance more evenly

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
    sections = version.section_set.all()
60
60
    first_column = []
61
61
    second_column = []
62
 
    total_items = 0
 
62
    total_size = 0
63
63
    sorted_sections = []
64
64
    for section in sections:
65
65
        section_count = section.namespace_set.count()
66
66
        section_count += section.free_element_set().count()
67
67
        if section_count == 0 and not request.user.has_perm('common.change_version'):
68
68
            continue
69
 
        total_items += section_count
 
69
        total_size += section_count + 2 # Extra 2 for the section header
70
70
        i = 0
71
71
        for s in sorted_sections:
72
72
            if (s.namespace_set.count() + s.free_element_set().count()) > section_count:
75
75
                break
76
76
        sorted_sections.insert(i, section)
77
77
        
78
 
    first_column_items = 0
 
78
    first_column_size = 0
79
79
    for section in sorted_sections:
80
 
        if first_column_items <= (total_items / 2):
 
80
        section_size = section.namespace_set.count() + section.free_element_set().count() + 2  # Extra 2 for the section header
 
81
        if (first_column_size + section_size) <= (total_size / 2):
81
82
            first_column.append(section)
82
 
            first_column_items += (section.namespace_set.count() + section.free_element_set().count())
 
83
            first_column_size += (section_size)
83
84
        else:
84
85
            second_column.append(section)
85
86