Beispiel #1
0
 def test_get_account_components(self):
     entries = loader.load_string(TEST_INPUT)[0]
     components = getters.get_account_components(entries)
     expected_components = {
         'US', 'Assets', 'Restaurant', 'Grocery', 'Cash', 'Coffee',
         'Expenses', 'Credit-Card'
     }
     self.assertEqual(sorted(expected_components), components)
Beispiel #2
0
def toc():
    entries_no_open_close = [
        entry for entry in app.entries
        if not isinstance(entry, (data.Open, data.Close))
    ]
    if entries_no_open_close:
        mindate, maxdate = None, None
    else:
        mindate, maxdate = getters.get_min_max_dates(entries_no_open_close)

    def view_url(name, **kw):
        return app.router.build(name, path=DEFAULT_VIEW_REDIRECT, **kw)

    viewboxes = []
    if app.args.view:
        # Render a single link to a view, the view selected from --view.
        viewboxes.append(('selected', None, [('/', 'Selected View')]))
    else:
        # Render a menu of various views.

        # Global views.
        viewboxes.append(
            ('global', None, [(view_url('all'), 'All Transactions')]))

        # By year views.
        viewboxes.append(
            ('year', 'By Year', [(view_url('year',
                                           year=year), 'Year {}'.format(year))
                                 for year in reversed(app.active_years)]))

        # By tag views.
        viewboxes.append(
            ('tag', 'Tags', [(view_url('tag', tag=tag), '#{}'.format(tag))
                             for tag in getters.get_all_tags(app.entries)]))

        # By component.
        components = getters.get_account_components(app.entries)
        viewboxes.append(
            ('component', 'Component', [(view_url('component',
                                                  component=component),
                                         '{}'.format(component))
                                        for component in components]))

        # Note: With the filtering language, payees will be added and much many more
        # options. Don't worry.

    oss = io.StringIO()
    oss.write('<div id="viewboxes">\n')
    for cssid, title, viewbox in viewboxes:
        view_items = [
            '<li><a href="{}">{}</a></li>'.format(url, title)
            for url, title in viewbox
        ]
        oss.write("""
          <div id="{cssid}" class="viewbox">
            {title}
            <ul>
              {view_items}
            </ul>
          </div>
          <hr/>
        """.format(cssid=cssid,
                   title='<h2>{}</h2>'.format(title) if title else '',
                   view_items='\n'.join(view_items)))
    oss.write('</div> <!-- viewboxes -->\n')

    return render_global(pagetitle="Table of Contents",
                         contents=oss.getvalue())