def api_finance(*, page='1'): page_index = get_page_index(page) num = yield from Finance.findNumber('count(id)') p = Page(num, page_index) if num == 0: return dict(page=p, finances=()) finances = yield from Finance.findAll(orderBy='created_at desc', limit=(p.offset, p.limit)) return dict(page=p, finances=finances)
def dashboard(*, page='1'): num = yield from Finance.findNumber('count(id)') page = Page(num) if num == 0: finances = [] else: finances = yield from Finance.findAll(orderBy='created_at desc') rev = [] for fin in finances: rev.append(int(fin.revenue)) return { '__template__': 'dashboard.html', 'page': page, 'finances': finances, 'rev': rev }
def api_create_finance(request, *, month, year, revenue, invoiced_or_not, content): check_admin(request) if not month or not month.strip(): raise APIValueError('month', 'month cannot be empty.') if not year or not year.strip(): raise APIValueError('year', 'year cannot be empty.') if not revenue or not revenue.strip(): raise APIValueError('revenue', 'revenue cannot be empty.') if not invoiced_or_not or not invoiced_or_not.strip(): raise APIValueError('introduce', 'introduce cannot be empty.') if not content or not content.strip(): raise APIValueError('content', 'content cannot be empty.') finance = Finance(month=month.strip(), year=year.strip(), revenue=revenue.strip(), invoiced_or_not=invoiced_or_not.strip(), content=content.strip()) yield from finance.save() return finance
def get_blog(id): blog = yield from Blog.find(id) comments = yield from Comment.findAll('blog_id=?', [id], orderBy='created_at desc') for c in comments: c.html_content = text2html(c.content) blog.html_content = markdown2.markdown(blog.content) num = yield from Finance.findNumber('count(id)') page = Page(num) if num == 0: finances = [] else: finances = yield from Finance.findAll(orderBy='created_at desc') rev = [] for fin in finances: rev.append(int(fin.revenue)) return { '__template__': 'blog.html', 'blog': blog, 'comments': comments, 'page': page, 'finances': finances, 'rev': rev }
def api_delete_finance(request, *, id): check_admin(request) finance = yield from Finance.find(id) yield from finance.remove() return dict(id=id)
def api_get_resource(*, id): finance = yield from Finance.find(id) return finance