def __init__(self, user_obj=None, id=None, slug=None, email=None): #TODO: Can we optimize the init to be able to load a profile without a call to user db? # say in a case where we already have an id and just want some fields from the profile object if slug: # Load profile by slug, if passed profile = db.profiles.find_one({"slug": slug}) if profile: self.__init__(id=profile["id"]) return try: if user_obj and not isinstance(user_obj, AnonymousUser): user = user_obj id = user.id elif email and not id: # Load profile by email, if passed. user = User.objects.get(email__iexact=email) id = user.id else: user = User.objects.get(id=id) self.first_name = user.first_name self.last_name = user.last_name self.email = user.email self.date_joined = user.date_joined self.user = user except: # These default values allow profiles to function even # if the Django User records are missing (for testing) self.first_name = "User" self.last_name = str(id) self.email = "*****@*****.**" self.date_joined = None self.user = None self._id = None # Mongo ID of profile doc self.id = id # user ID self.slug = "" self.position = "" self.organization = "" self.jewish_education = [] self.bio = "" self.website = "" self.location = "" self.public_email = "" self.youtube = "" self.facebook = "" self.twitter = "" self.linkedin = "" self.pinned_sheets = [] self.interrupting_messages = ["newUserWelcome"] self.last_sync_web = 0 # epoch time for last sync of web app self.profile_pic_url = "" self.profile_pic_url_small = "" self.settings = { "email_notifications": "daily", "interface_language": "english", "textual_custom" : "sephardi", "reading_history" : True } # dict that stores the last time an attr has been modified self.attr_time_stamps = { "settings": 0 } # flags that indicate a change needing a cascade after save self._name_updated = False self._process_remove_history = False # Followers self.followers = FollowersSet(self.id) self.followees = FolloweesSet(self.id) # Google API token self.gauth_token = None # Update with saved profile doc in MongoDB profile = db.profiles.find_one({"id": id}) if profile: self.update(profile, ignore_flags_on_init=True) elif self.exists(): # If we encounter a user that has a Django user record but not a profile document # create a profile for them. This allows two enviornments to share a user database, # while maintaining separate profiles (e.g. Sefaria and S4D). self.assign_slug() self.interrupting_messages = [] self.save() # Profile Pic default to Gravatar if len(self.profile_pic_url) == 0: default_image = "https://www.sefaria.org/static/img/profile-default.png" gravatar_base = "https://www.gravatar.com/avatar/" + hashlib.md5(self.email.lower().encode('utf-8')).hexdigest() + "?" gravatar_url = gravatar_base + urllib.parse.urlencode({'d':default_image, 's':str(250)}) gravatar_url_small = gravatar_base + urllib.parse.urlencode({'d':default_image, 's':str(80)}) self.profile_pic_url = gravatar_url self.profile_pic_url_small = gravatar_url_small
def __init__(self, id=None, slug=None, email=None): if slug: # Load profile by slug, if passed profile = db.profiles.find_one({"slug": slug}) if profile: self.__init__(id=profile["id"]) return try: if email and not id: # Load profile by email, if passed. user = User.objects.get(email__iexact=email) id = user.id else: user = User.objects.get(id=id) self.first_name = user.first_name self.last_name = user.last_name self.email = user.email self.date_joined = user.date_joined except: # These default values allow profiles to function even # if the Django User records are missing (for testing) self.first_name = "User" self.last_name = str(id) self.email = "*****@*****.**" self.date_joined = None self._id = None # Mongo ID of profile doc self.id = id # user ID self.slug = "" self.position = "" self.organization = "" self.jewish_education = [] self.bio = "" self.website = "" self.location = "" self.public_email = "" self.youtube = "" self.facebook = "" self.twitter = "" self.linkedin = "" self.pinned_sheets = [] self.interrupting_messages = ["newUserWelcome"] self.partner_group = "" self.partner_role = "" self.last_sync_web = 0 # epoch time for last sync of web app self.settings = { "email_notifications": "daily", "interface_language": "english", "textual_custom" : "sephardi" } # dict that stores the last time an attr has been modified self.attr_time_stamps = { "settings": 0 } self._name_updated = False # Followers self.followers = FollowersSet(self.id) self.followees = FolloweesSet(self.id) # Gravatar default_image = "https://www.sefaria.org/static/img/profile-default.png" gravatar_base = "https://www.gravatar.com/avatar/" + hashlib.md5(self.email.lower()).hexdigest() + "?" self.gravatar_url = gravatar_base + urllib.urlencode({'d':default_image, 's':str(250)}) self.gravatar_url_small = gravatar_base + urllib.urlencode({'d':default_image, 's':str(80)}) # Update with saved profile doc in MongoDB profile = db.profiles.find_one({"id": id}) profile = self.migrateFromOldRecents(profile) if profile: self.update(profile)
def __init__(self, id=None, slug=None): if slug: # Load profile by slug if passed profile = db.profiles.find_one({"slug": slug}) if profile: self.__init__(id=profile["id"]) return try: user = User.objects.get(id=id) self.first_name = user.first_name self.last_name = user.last_name self.email = user.email self.date_joined = user.date_joined except: # These default values allow profiles to function even # if the Django User records are missing (for testing) self.first_name = "User" self.last_name = str(id) self.email = "*****@*****.**" self.date_joined = None self._id = None # Mongo ID of profile doc self.id = id # user ID self.slug = "" self.position = "" self.organization = "" self.jewish_education = [] self.bio = "" self.website = "" self.location = "" self.public_email = "" self.youtube = "" self.facebook = "" self.twitter = "" self.linkedin = "" self.pinned_sheets = [] self.settings = { "email_notifications": "daily", } self._name_updated = False self._slug_updated = False # Update with saved profile doc in MongoDB profile = db.profiles.find_one({"id": id}) if profile: self.update(profile) # Followers self.followers = FollowersSet(self.id) self.followees = FolloweesSet(self.id) # Gravatar default_image = "http://www.sefaria.org/static/img/profile-default.png" gravatar_base = "http://www.gravatar.com/avatar/" + hashlib.md5( self.email.lower()).hexdigest() + "?" self.gravatar_url = gravatar_base + urllib.urlencode({ 'd': default_image, 's': str(250) }) self.gravatar_url_small = gravatar_base + urllib.urlencode({ 'd': default_image, 's': str(80) })