Beispiel #1
0
def api_create_item(request, *, content, answer, answer_type, paper_id, **kwargs):
    check_admin(request)
    if not content or not content.strip():
        raise APIValueError('content', 'content cannot be empty.')
    if not answer or not answer.strip():
        raise APIValueError('answer', 'answer cannot be empty.')
    if not answer_type or not answer_type.strip():
        raise APIValueError('answer_type', 'answer_type cannot be empty.')
    if not paper_id or not paper_id.strip():
        raise APIValueError('paper_id', 'paper_id cannot be empty.')
    paper = yield from Paper.find(paper_id)
    item = Item(index=paper.munber, paper=paper.id, content=content.strip(), answer=answer.strip(), answer_type=answer_type.strip())
    if (answer_type.strip()=='选择题'):
        answer_A = kwargs.get('answer_A', None)
        answer_B = kwargs.get('answer_B', None)
        answer_C = kwargs.get('answer_C', None)
        answer_D = kwargs.get('answer_D', None)
        item.answer_A = answer_A.strip()
        item.answer_B = answer_B.strip()
        item.answer_C = answer_C.strip()
        item.answer_D = answer_D.strip()
    yield from item.save()
    paper.munber +=1
    yield from paper.update()
    return item
Beispiel #2
0
def api_update_paper(id, request, *, name, brief, tag):
    check_admin(request)
    paper = yield from Paper.find(id)
    if not name or not name.strip():
        raise APIValueError('name', 'name cannot be empty.')
    if not tag or not tag.strip():
        raise APIValueError('tag', 'tag cannot be empty.')
    paper.name = name.strip()
    paper.brief = brief.strip()
    paper.tag = tag.strip()
    yield from paper.update()
    return paper
Beispiel #3
0
def api_delete_paper(request, *, id):
    check_admin(request)
    paper = yield from Paper.find(id)
    yield from paper.remove()
    return dict(id=id)
Beispiel #4
0
def api_get_paper(*, id):
    paper = yield from Paper.find(id)
    return paper