<s> from uuid import UUID , uuid4 <EOL> from datetime import datetime <EOL> from sqlalchemy import Column , String , DateTime <EOL> from sqlalchemy import or_ <EOL> from changes . config import db <EOL> from changes . db . types . guid import GUID <EOL> class Author ( db . Model ) : <EOL> """<STR_LIT>""" <EOL> __tablename__ = '<STR_LIT>' <EOL> id = Column ( GUID , primary_key = True , default = uuid4 ) <EOL> name = Column ( String ( <NUM_LIT> ) , nullable = False ) <EOL> email = Column ( String ( <NUM_LIT> ) , unique = True ) <EOL> date_created = Column ( DateTime , default = datetime . utcnow ) <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( Author , self ) . __init__ ( ** kwargs ) <EOL> if not self . id : <EOL> self . id = uuid4 ( ) <EOL> @ classmethod <EOL> def find ( cls , author_id , current_user = None ) : <EOL> if author_id == '<STR_LIT>' : <EOL> if current_user is None : <EOL> return [ ] <EOL> email = current_user . email <EOL> elif '<STR_LIT:@>' in author_id : <EOL> email = author_id <EOL> else : <EOL> email = None <EOL> if email : <EOL> username , domain = email . split ( '<STR_LIT:@>' , <NUM_LIT:1> ) <EOL> email_query = '<STR_LIT>' . format ( username , domain ) <EOL> return list ( cls . query . filter ( <EOL> or_ ( <EOL> cls . email . like ( email_query ) , <EOL> cls . email == email , <EOL> ) <EOL> ) ) <EOL> try : <EOL> author_id = UUID ( author_id ) <EOL> except ValueError : <EOL> return [ ] <EOL> author = cls . query . get ( author_id ) <EOL> if author is None : <EOL> return [ ] <EOL> return [ author ] </s>
