-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.py
executable file
·73 lines (59 loc) · 2.02 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pony.orm import db_session, commit, select, delete
from ej import models
import argparse
def main():
# DB
models.init()
parser = argparse.ArgumentParser(description='EJ Admin CRUD')
def create_problem(args):
print('create')
print(args)
with db_session:
p = models.Problem(title='Dia da Vovó', time_limit=5, check_code="")
models.TestCase(input_='2\n42\n69\n', output='24\n96\n', problem=p)
models.TestCase(input_='1\n55\n', output='55\n', problem=p)
p2 = models.Problem(title='Divide by 2', time_limit=1,
check_code='''
def check(input, output, user_output):
import io
inbuf = io.StringIO(input)
a = float(inbuf.read())
outbuf = io.StringIO(user_output)
b = float(outbuf.read())
if(abs(a/2.0 - b) < 1e-6):
return True
return False
''')
models.TestCase(input_='10\n', output='5\n', problem=p2)
models.TestCase(input_='11\n', output='5.5\n', problem=p2)
commit()
def read_problem(args):
print('read')
print(args)
with db_session:
print(select(p for p in models.Problem)[:].show())
print(select(p for p in models.TestCase)[:].show())
def update_problem(args):
print('update')
print(args)
def delete_problem(args):
print('delete')
print(args)
with db_session:
delete(p for p in models.Problem)
delete(p for p in models.TestCase)
sp = parser.add_subparsers()
sp_create = sp.add_parser('create')
sp_create.set_defaults(func=create_problem)
sp_read = sp.add_parser('read')
sp_read.set_defaults(func=read_problem)
sp_update = sp.add_parser('update')
sp_update.set_defaults(func=update_problem)
sp_delete = sp.add_parser('delete')
sp_delete.set_defaults(func=delete_problem)
args = parser.parse_args()
args.func(args)
if __name__ == '__main__':
main()