<s> from __future__ import absolute_import <EOL> import hashlib <EOL> from google . appengine . ext import ndb <EOL> from webargs . flaskparser import parser <EOL> from webargs import fields as wf <EOL> from api import fields <EOL> import model <EOL> import util <EOL> import config <EOL> class User ( model . Base ) : <EOL> name = ndb . StringProperty ( required = True ) <EOL> username = ndb . StringProperty ( required = True ) <EOL> email = ndb . StringProperty ( default = '<STR_LIT>' ) <EOL> auth_ids = ndb . StringProperty ( repeated = True ) <EOL> active = ndb . BooleanProperty ( default = True ) <EOL> admin = ndb . BooleanProperty ( default = False ) <EOL> permissions = ndb . StringProperty ( repeated = True ) <EOL> verified = ndb . BooleanProperty ( default = False ) <EOL> token = ndb . StringProperty ( default = '<STR_LIT>' ) <EOL> password_hash = ndb . StringProperty ( default = '<STR_LIT>' ) <EOL> github = ndb . StringProperty ( default = '<STR_LIT>' ) <EOL> def has_permission ( self , perm ) : <EOL> return self . admin or perm in self . permissions <EOL> def avatar_url_size ( self , size = None ) : <EOL> return '<STR_LIT>' % { <EOL> '<STR_LIT>' : hashlib . md5 ( <EOL> ( self . email or self . username ) . encode ( '<STR_LIT:utf-8>' ) ) . hexdigest ( ) , <EOL> '<STR_LIT:size>' : '<STR_LIT>' % size if size > <NUM_LIT:0> else '<STR_LIT>' , <EOL> } <EOL> avatar_url = property ( avatar_url_size ) <EOL> @ classmethod <EOL> def get_dbs ( <EOL> cls , admin = None , active = None , verified = None , permissions = None , ** kwargs <EOL> ) : <EOL> args = parser . parse ( { <EOL> '<STR_LIT>' : wf . Bool ( missing = None ) , <EOL> '<STR_LIT>' : wf . Bool ( missing = None ) , <EOL> '<STR_LIT>' : wf . Bool ( missing = None ) , <EOL> '<STR_LIT>' : wf . DelimitedList ( wf . Str ( ) , delimiter = '<STR_LIT:U+002C>' , missing = [ ] ) , <EOL> } ) <EOL> return super ( User , cls ) . get_dbs ( <EOL> admin = admin or args [ '<STR_LIT>' ] , <EOL> active = active or args [ '<STR_LIT>' ] , <EOL> verified = verified or args [ '<STR_LIT>' ] , <EOL> permissions = permissions or args [ '<STR_LIT>' ] , <EOL> ** kwargs <EOL> ) <EOL> @ classmethod <EOL> def is_username_available ( cls , username , self_key = None ) : <EOL> if self_key is None : <EOL> return cls . get_by ( '<STR_LIT:username>' , username ) is None <EOL> user_keys , _ = util . get_keys ( cls . query ( ) , username = username , limit = <NUM_LIT:2> ) <EOL> return not user_keys or self_key in user_keys and not user_keys [ <NUM_LIT:1> : ] <EOL> @ classmethod <EOL> def is_email_available ( cls , email , self_key = None ) : <EOL> if not config . CONFIG_DB . check_unique_email : <EOL> return True <EOL> user_keys , _ = util . get_keys ( <EOL> cls . query ( ) , email = email , verified = True , limit = <NUM_LIT:2> , <EOL> ) <EOL> return not user_keys or self_key in user_keys and not user_keys [ <NUM_LIT:1> : ] <EOL> FIELDS = { <EOL> '<STR_LIT>' : fields . Boolean , <EOL> '<STR_LIT>' : fields . Boolean , <EOL> '<STR_LIT>' : fields . List ( fields . String ) , <EOL> '<STR_LIT>' : fields . String , <EOL> '<STR_LIT:email>' : fields . String , <EOL> '<STR_LIT:name>' : fields . String , <EOL> '<STR_LIT>' : fields . List ( fields . String ) , <EOL> '<STR_LIT:username>' : fields . String , <EOL> '<STR_LIT>' : fields . Boolean , <EOL> } <EOL> FIELDS . update ( model . Base . FIELDS ) </s>
