Source

wdmmg / wdmmg / controllers / entry.py

Full commit
import logging

from pylons import request, response, session, tmpl_context as c, url
from pylons.controllers.util import abort, redirect

from wdmmg.lib.base import BaseController, render
from wdmmg.lib.helpers import Page
from wdmmg.lib.helpers import dept_name_to_wdtk_identifier
from wdmmg import model

log = logging.getLogger(__name__)

class EntryController(BaseController):
    def index(self):
        query = model.Entry.find()
        c.page = Page(
            collection=query,
            page=int(request.params.get('page', 1)),
            items_per_page=c.items_per_page,
            item_count=query.count(),
        )
        return render('entry/index.html')

    def view(self, id=None):
        c.row = model.Entry.by_id(id)
        if not c.row:
            abort(404, 'Sorry, there is no entry with code %r'% id)
    
        c.desc = c.row.explain()
        c.id = c.row.get('_id')
        del c.row['_id']
        c.from_ = c.row.get('from')
        del c.row['from']
        c.to = c.row.get('to')
        del c.row['to']
        c.dataset = c.row.get('dataset')
        del c.row['dataset']
        c.currency = c.row.get('currency', c.dataset.get('currency')).upper()
        if c.row.get('currency'):
            del c.row['currency']
        c.amount = c.row.get('amount')
        del c.row['amount']
        c.time = c.row.get('time')
        del c.row['time']
        
        if 'departments' in c.dataset.get('name'):
            c.show_foi = True
        else:
            c.show_foi = False
        return render('entry/view.html')