def api_shoppings(*, page='1'): page_index = get_page_index(page) num = yield from Shopping.findNumber('count(id)') p = Page(num, page_index) if num == 0: return dict(page=p, shoppings=()) shoppings = yield from Shopping.findAll(orderBy='created_at desc', limit=(p.offset, p.limit)) return dict(page=p, shoppings=shoppings)
def index(*, page='1'): page_index = get_page_index(page) num = yield from Shopping.findNumber('count(id)') page = Page(num) if num == 0: shoppings = [] else: shoppings = yield from Shopping.findAll(orderBy='created_at desc', limit=(page.offset, page.limit)) return { '__template__': 'shoppings.html', 'page': page, 'shoppings': shoppings }
def api_create_shopping(request, *, name, summary, content, price): check_admin(request) if not name or not name.strip(): raise APIValueError('name', 'name cannot be empty.') if not summary or not summary.strip(): raise APIValueError('summary', 'summary cannot be empty.') if not content or not content.strip(): raise APIValueError('content', 'content cannot be empty.') if not price or not price.strip(): raise APIValueError('price', 'price cannot be empty.') shopping = Shopping(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, name=name.strip(), summary=summary.strip(), content=content.strip(), price=price.strip()) yield from shopping.save() return shopping
def api_update_shopping(id, request, *, name, summary, content, price): check_admin(request) shopping = yield from Shopping.find(id) if not name or not name.strip(): raise APIValueError('name', 'name cannot be empty.') if not summary or not summary.strip(): raise APIValueError('summary', 'summary cannot be empty.') if not content or not content.strip(): raise APIValueError('content', 'content cannot be empty.') if not price or not price.strip(): raise APIValueError('price', 'price cannot be empty.') shopping.name = name.strip() shopping.summary = summary.strip() shopping.content = content.strip() shopping.price = price.strip() yield from shopping.update() return shopping
def get_shopping(id): shopping = yield from Shopping.find(id) shopping.html_content = markdown2.markdown(shopping.content) return {'__template__': 'shopping.html', 'shopping': shopping}
def api_delete_shopping(request, *, id): check_admin(request) shopping = yield from Shopping.find(id) yield from shopping.remove() return dict(id=id)
def api_get_shopping(*, id): shopping = yield from Shopping.find(id) return shopping
def _create_shopping(cls, name='Shopping teste', slug='shopping-teste'): mall = Shopping() mall.nome = name mall.slug = slug mall.save() return mall