<s> """<STR_LIT>""" <EOL> from core . platform import models <EOL> import feconf <EOL> from google . appengine . ext import ndb <EOL> ( base_models , ) = models . Registry . import_models ( [ models . NAMES . base_model ] ) <EOL> class UserSettingsModel ( base_models . BaseModel ) : <EOL> """<STR_LIT>""" <EOL> email = ndb . StringProperty ( required = True , indexed = True ) <EOL> username = ndb . StringProperty ( indexed = True ) <EOL> normalized_username = ndb . StringProperty ( indexed = True ) <EOL> last_agreed_to_terms = ndb . DateTimeProperty ( default = None ) <EOL> last_started_state_editor_tutorial = ndb . DateTimeProperty ( default = None ) <EOL> profile_picture_data_url = ndb . TextProperty ( default = None , indexed = False ) <EOL> user_bio = ndb . TextProperty ( indexed = False ) <EOL> subject_interests = ndb . StringProperty ( repeated = True , indexed = True ) <EOL> first_contribution_msec = ndb . FloatProperty ( default = None ) <EOL> preferred_language_codes = ndb . StringProperty ( <EOL> repeated = True , <EOL> indexed = True , <EOL> choices = [ lc [ '<STR_LIT:code>' ] for lc in feconf . ALL_LANGUAGE_CODES ] ) <EOL> @ classmethod <EOL> def is_normalized_username_taken ( cls , normalized_username ) : <EOL> """<STR_LIT>""" <EOL> return bool ( cls . get_all ( ) . filter ( <EOL> cls . normalized_username == normalized_username ) . get ( ) ) <EOL> @ classmethod <EOL> def get_by_normalized_username ( cls , normalized_username ) : <EOL> """<STR_LIT>""" <EOL> return cls . get_all ( ) . filter ( <EOL> cls . normalized_username == normalized_username ) . get ( ) <EOL> class UserContributionsModel ( base_models . BaseModel ) : <EOL> """<STR_LIT>""" <EOL> created_exploration_ids = ndb . StringProperty ( <EOL> repeated = True , indexed = True , default = None ) <EOL> edited_exploration_ids = ndb . StringProperty ( <EOL> repeated = True , indexed = True , default = None ) <EOL> class UserEmailPreferencesModel ( base_models . BaseModel ) : <EOL> """<STR_LIT>""" <EOL> site_updates = ndb . BooleanProperty ( indexed = True ) <EOL> editor_role_notifications = ndb . BooleanProperty ( <EOL> indexed = True , default = feconf . DEFAULT_EDITOR_ROLE_EMAIL_PREFERENCE ) <EOL> class UserSubscriptionsModel ( base_models . BaseModel ) : <EOL> """<STR_LIT>""" <EOL> activity_ids = ndb . StringProperty ( repeated = True , indexed = True ) <EOL> collection_ids = ndb . StringProperty ( repeated = True , indexed = True ) <EOL> feedback_thread_ids = ndb . StringProperty ( repeated = True , indexed = True ) <EOL> last_checked = ndb . DateTimeProperty ( default = None ) <EOL> class UserRecentChangesBatchModel ( base_models . BaseMapReduceBatchResultsModel ) : <EOL> """<STR_LIT>""" <EOL> output = ndb . JsonProperty ( indexed = False ) <EOL> job_queued_msec = ndb . FloatProperty ( indexed = False ) <EOL> class UserStatsModel ( base_models . BaseMapReduceBatchResultsModel ) : <EOL> """<STR_LIT>""" <EOL> impact_score = ndb . FloatProperty ( indexed = True ) <EOL> class ExplorationUserDataModel ( base_models . BaseModel ) : <EOL> """<STR_LIT>""" <EOL> user_id = ndb . StringProperty ( required = True , indexed = True ) <EOL> exploration_id = ndb . StringProperty ( required = True , indexed = True ) <EOL> rating = ndb . IntegerProperty ( default = None , indexed = True ) <EOL> rated_on = ndb . DateTimeProperty ( default = None , indexed = False ) <EOL> draft_change_list = ndb . JsonProperty ( default = None ) <EOL> draft_change_list_last_updated = ndb . DateTimeProperty ( default = None ) <EOL> draft_change_list_exp_version = ndb . IntegerProperty ( default = None ) <EOL> @ classmethod <EOL> def _generate_id ( cls , user_id , exploration_id ) : <EOL> return '<STR_LIT>' % ( user_id , exploration_id ) <EOL> @ classmethod <EOL> def create ( cls , user_id , exploration_id ) : <EOL> """<STR_LIT>""" <EOL> instance_id = cls . _generate_id ( user_id , exploration_id ) <EOL> return cls ( <EOL> id = instance_id , user_id = user_id , exploration_id = exploration_id ) <EOL> @ classmethod <EOL> def get ( cls , user_id , exploration_id ) : <EOL> """<STR_LIT>""" <EOL> instance_id = cls . _generate_id ( user_id , exploration_id ) <EOL> return super ( ExplorationUserDataModel , cls ) . get ( <EOL> instance_id , strict = False ) <EOL> class CollectionProgressModel ( base_models . BaseModel ) : <EOL> """<STR_LIT>""" <EOL> user_id = ndb . StringProperty ( required = True , indexed = True ) <EOL> collection_id = ndb . StringProperty ( required = True , indexed = True ) <EOL> completed_explorations = ndb . StringProperty ( repeated = True ) <EOL> @ classmethod <EOL> def _generate_id ( cls , user_id , collection_id ) : <EOL> return '<STR_LIT>' % ( user_id , collection_id ) <EOL> @ classmethod <EOL> def create ( cls , user_id , collection_id ) : <EOL> """<STR_LIT>""" <EOL> instance_id = cls . _generate_id ( user_id , collection_id ) <EOL> return cls ( <EOL> id = instance_id , user_id = user_id , collection_id = collection_id ) <EOL> @ classmethod <EOL> def get ( cls , user_id , collection_id ) : <EOL> """<STR_LIT>""" <EOL> instance_id = cls . _generate_id ( user_id , collection_id ) <EOL> return super ( CollectionProgressModel , cls ) . get ( <EOL> instance_id , strict = False ) <EOL> @ classmethod <EOL> def get_or_create ( cls , user_id , collection_id ) : <EOL> """<STR_LIT>""" <EOL> instance_model = cls . get ( user_id , collection_id ) <EOL> if instance_model : <EOL> return instance_model <EOL> else : <EOL> return cls . create ( user_id , collection_id ) </s>
