Exemple #1
0
 def get(self, entry_id):
     """Return single entry or a list."""
     if entry_id is None:
         d = request.args.get('month')
         if not d:
             d = date.today()
         else:
             d = datetime.strptime(d, '%Y-%m')
         resp = {'entries': [e.to_json() for e in Entry.query_month(d)]}
         if request.args.get('total') == '1':
             resp['totalAmount'] = '%.2f' % (Entry.month_total(d) or 0)
         return jsonify(**resp)
     else:
         entry = Entry.query.filter_by(id=entry_id).one()
         return jsonify(**entry.to_json())
Exemple #2
0
def index(year=None, month=None):
    if year is None and month is None:
        d = date.today().replace(day=1)
    else:
        try:
            d = date(year, month, 1)
        except ValueError:
            abort(400)
    entries = [e.to_json() for e in Entry.query_month(d)]
    total = '%.2f' % (Entry.month_total(d) or 0)
    tags = [t.to_json() for t in Tag.query.order_by(Tag.name)]
    return render_template('main.jinja',
                           date=str(d),
                           entries=entries,
                           totalAmount=total,
                           tags=tags)