def activate_hw(): id = click.prompt('ID of the homework to activate', type=str) realid = hwserializer.loads(id) hw = Homework.query.get(realid) if hw: hw.activate() db.session.commit() click.echo('Activated homework: ' + hwserializer.dumps(hw.id)) else: click.echo('No such homework: ' + id)
def edit_hw(): id = click.prompt('ID of homework to edit: ', type=str) hw = Homework.query.get(hwserializer.loads(id)) click.echo("Homework name: " + hw.name) click.echo("Homework description: " + hw.description) if click.confirm('Change name?', default=True): name = click.prompt('New name: ', type=str) hw.name = name if click.confirm('Change description?', default=True): click.echo('New description: (Ctrl-D to finish):') description = sys.stdin.read() hw.description = description db.session.add(hw) db.session.commit()
def delete_hw(): id = click.prompt('ID of the homework to delete', type=str) realid = hwserializer.loads(id) hw = Homework.query.get(realid) if hw: if not click.confirm('Please confirm!', default=False): return for item in hw.items: for test in item.tests: subs = RequestLog.query.filter( RequestLog.test_id == test.id).all() for sub in subs: db.session.delete(sub) db.session.delete(test) db.session.delete(item) db.session.delete(hw) db.session.commit() click.echo('Deleted homework: ' + hwserializer.dumps(hw.id)) else: click.echo('No such homework: ' + id)
def delete_hw(): id = click.prompt('ID of the homework to delete', type=str) realid = hwserializer.loads(id) hw = Homework.query.get(realid) if hw: if not click.confirm('Please confirm!', default=False): return for item in hw.items: for test in item.tests: subs = RequestLog.query.filter(RequestLog.test_id == test.id).all() for sub in subs: db.session.delete(sub) db.session.delete(test) db.session.delete(item) db.session.delete(hw) db.session.commit() click.echo('Deleted homework: ' + hwserializer.dumps(hw.id)) else: click.echo('No such homework: ' + id)
def get(self, hwid): hw = Homework.query.get(hwserializer.loads(hwid)) if not hw: abort(404) return serialize_homework(hw)
for i in range(length): result.append(randint(min_val, max_val)) return result def is_negative(l): for item in l: if int(item) >= 0: return False return True if __name__ == '__main__': hwid = click.prompt('HW to fix:', type=str) hwid = hwserializer.loads(hwid) items = Item.query.filter(Item.homework_id == hwid).all() for item in items: tests = Test.query.filter(Test.item_id == item.id).all() for test in tests: lstdin = test.stdin.strip().split('\n') for i in range(len(lstdin)): line = lstdin[i] linel = line.strip().split(' ') while is_negative(linel): A = generate_array(len(linel), randint(-500, 0), randint(0, 500)) line = str(A)[1:len(A) - 1].replace(',', '') linel = line.split(' ') lstdin[i] = line