def DB_init(db): db.drop_all() db.create_all() u = models.User(username='******', password_hash='deadbeef', id=1, admin=0, secret='Likes Oreos.', name="Jarrett Booz") db.session.add(u) u = models.User(username='******', password_hash='deadbeef', id=2, admin=0, secret='Know it all.', name="Danny Tunitis") db.session.add(u) c = models.Todo(item='Shrink the moon', user_id=1) db.session.add(c) c = models.Todo(item='Grab the moon', user_id=1) db.session.add(c) c = models.Todo(item='Sit on the toilet', user_id=1) db.session.add(c) db.session.commit()
def seed(): '''Add seed data to the database.''' todo_list = models.TodoList() db.session.add(todo_list) todo_list.todos.append(models.Todo(text="Discuss report with John")) todo_list.todos.append( models.Todo(text="Get a haircut", status="completed")) todo_list.todos.append( models.Todo(text="Pay electricity bill", status="completed")) todo_list.todos.append(models.Todo(text="Check gym hours")) db.session.commit()
def create_todo(conn: sqlite3.Connection, contents: str, tag_names: Set[str]) -> models.Todo: _verify_tags(conn, tag_names) id = uuid.uuid4().hex created_at = datetime.now() state = models.TodoState.ongoing conn.execute( f""" insert into todo({_ROWS}) values ({', '.join(['?' for _ in _ROWS.split(',')])}) """, ( id, contents, _get_tag_field(conn, tag_names), state.value, created_at.timestamp(), created_at.timestamp(), created_at.timestamp(), ), ) conn.commit() return models.Todo( id=id, contents=contents, tags=tag_names, state=state, created_at=created_at, updated_at=created_at, state_updated_at=created_at, )
def _row_to_todo(conn: sqlite3.Connection, row: Any) -> Optional[models.Todo]: if row is None: return None return models.Todo( id=row[0], contents=row[1], tags=_get_tag_names(conn, row[2]), state=models.TodoState(row[3]), created_at=datetime.fromtimestamp(row[4]), updated_at=datetime.fromtimestamp(row[5]), state_updated_at=datetime.fromtimestamp(row[6]), )
def DB_init(db): db.drop_all() db.create_all() u = models.User(username='******',password_hash='deadbeef',id=1,admin=0,secret='Likes Oreos.', name="Jarrett Booz") db.session.add(u) u = models.User(username='******',password_hash='deadbeef',id=2,admin=0,secret='Know it all.', name= "Danny Tunitis") db.session.add(u) c = models.Todo(item='Shrink the moon', user_id=1) db.session.add(c) c = models.Todo(item='Grab the moon', user_id=1) db.session.add(c) c = models.Todo(item='Sit on the toilet', user_id=1) db.session.add(c) c = models.Todo(item='Make 2000 more Pico problems', user_id=2) db.session.add(c) c = models.Todo(item='Do dastardly plan: picoCTF{cookies_are_a_sometimes_food_e53b6d53}', user_id=2) db.session.add(c) c = models.Todo(item='Buy milk', user_id=2) db.session.add(c) db.session.commit()
def create_todo(public_id): error = None message = None success = False results = None data = request.get_json() if not data: error = {'title': 'Json data is required'} return jsonify({ 'success': success, 'error': error }), util.http_status_code('BAD_REQUEST') try: clean_data = schema_todo.todo_schema.load(data) user = models.User.query.filter_by(public_id=public_id, active=True).first() if not user: error = {'title': 'User not found'} return jsonify({ 'success': success, 'error': error }), util.http_status_code('BAD_REQUEST') new_todo = models.Todo(title=clean_data['title'], created_by=user.public_id) db.session.add(new_todo) db.session.commit() success = True message = 'Todo created successfully' results = schema_todo.todo_schema.dump(new_todo) return jsonify({ 'success': success, 'data': results, 'message': message }), util.http_status_code('CREATED') except ValidationError as e: error = e.normalized_messages() return jsonify({ 'success': success, 'error': error }), util.http_status_code('BAD_REQUEST')
def add(): content = flask.request.form.get("content") todo = models.Todo(content=content) todo.save() todos = flask.Todo.objects.all() return render_template("index.html", todos=todos)
def save_todo(): todo = models.Todo(content="My first todo") todo.save()