def list_authors(self) -> Iterator[models.Author]: result = self._conn.execute(sqlalchemy.text(LIST_AUTHORS)) for row in result: yield models.Author( id=row[0], name=row[1], bio=row[2], )
async def list_authors(self) -> AsyncIterator[models.Author]: result = await self._conn.stream(sqlalchemy.text(LIST_AUTHORS)) async for row in result: yield models.Author( id=row[0], name=row[1], bio=row[2], )
async def create_author(self, *, name: str, bio: Optional[str]) -> Optional[models.Author]: row = (await self._conn.execute(sqlalchemy.text(CREATE_AUTHOR), {"p1": name, "p2": bio})).first() if row is None: return None return models.Author( id=row[0], name=row[1], bio=row[2], )
async def get_author(self, *, id: int) -> Optional[models.Author]: row = (await self._conn.execute(sqlalchemy.text(GET_AUTHOR), {"p1": id})).first() if row is None: return None return models.Author( id=row[0], name=row[1], bio=row[2], )
def add_author(request): """ Creates new domains and should be restricted to high level site admins only""" if request.method == 'POST': author_name = request.POST['author_name'] dob = request.POST['dob'] date_added = datetime.datetime.utcnow() author_id = str(uuid.uuid4()) new_author = models.Author(AuthorID=author_id, Name=author_name, DOB=datetime.datetime.strptime( dob, '%Y%m%d'), Date_Added=date_added, Books_Stored=0) new_author.save() # todo add proper redirect here return redirect('/authors/authors') else: return redirect('/authors/authors')