def create_event(): if not request.form: return abort(400) extra_info = request.form.get('extra_info') ncodes = int(request.form.get('ncodes', 0)) start_time = request.form.get('start_time') expire_time = request.form.get('expire_time') if not all([extra_info, ncodes, start_time, expire_time]): return jsonify(message='missing arguments'), 400 try: json.loads(extra_info) except Exception: return jsonify(message='invalid extra_info'), 400 rand_len = int(request.form.get('rand_len', '6')) prefix = request.form.get('prefix', '') event = CodeGenEvent.create_event(ncodes, extra_info, start_time, expire_time, prefix, rand_len) return jsonify(event_id=event.id)
def get_all_events(): events = CodeGenEvent.select() return jsonify([e.to_dict(get_codes=False) for e in events])
def get_event(event_id): try: event = CodeGenEvent.get(id=event_id) except CodeGenEvent.DoesNotExist: return jsonify(message="event doesn't exists"), 404 return jsonify(event.to_dict(get_codes=True))