Ejemplo n.º 1
0
def populateProfiles():
	with open('F2014-applications.csv', 'rb') as csvfile:
		reader = csv.reader(csvfile)
		count = 1
		for row in reader:
			#if count == 0:
			#	break
			if len(row[3].split('@')) != 2 :
				print >> sys.stderr, "Skipping %s" % row
				continue
			lname = row[1]
			fname = row[2]
			email = row[3].split('@')[0] + '@thegovlab.org'
			credentials = row[7] # credentials
			experience = row[8] # experience
			skills = row[9] # skills
			interests = row[10] # interests
			bio = row[6] # bio
			location = row[14] # location
			country = row[16] # country
			if row[19] != "yes":
				print >> sys.stderr, "Skipping %s because of missing letter." % email
			user_profile = UserProfile.get_by_id(email)
			profile_data = { 'fname': fname, 'lname': lname,
				'offer': skills, 'demand': interests,
				'experience': experience, 'expertise': credentials,
				'city_state': location, 'country': country  }
			if user_profile == None:
				user_profile = UserProfile(id=email, profile=json.dumps(profile_data))
				user_profile.put()
			else:
				print >> sys.stderr, "Skipping %s because data is already there." % email
				continue
			print >> sys.stderr, "Profile for user %s added." % email	
			count = count - 1
Ejemplo n.º 2
0
def createNewUser(fname, lname, email, affiliation):
	if UserProfile.get_by_id(email):
		logging.error("User %s already exists." % email)
		return
	user_profile = UserProfile(id=email, fname=fname, lname=lname, affiliation=affiliation)
	user_profile.put()
	return user_profile
	logging.info("New user %s created." % email)
Ejemplo n.º 3
0
def createNewUser(fname, lname, email):
	newUser = UserProfile.getFromEmail(email)
	if newUser == None:
		newUser = UserProfile(id=email, fname=fname, lname=lname, email=email)
		newUser.put()
		logging.info('User %s created.' % email)
	else:
		logging.error('User already exists.')
Ejemplo n.º 4
0
 def post(self):
     user = users.get_current_user()
     profileId = self.request.get('profileId')
     userProfile = UserProfile.getFromEmail(profileId)
     if userProfile is None or canEditThisProfile == False:
         self.abort(404)
     user_profile_json = {}
     for field in UserProfile.getJsonFields():
         user_profile_json[field] = self.request.get(field)
     userProfile.profile = json.dumps(user_profile_json)
     userProfile.put()
     self.redirect('/profile?user_email=%s' % profileId)
Ejemplo n.º 5
0
	def post(self):
		user = users.get_current_user()
		profileId = self.request.get('profileId')
		userProfile = UserProfile.getFromEmail(profileId)
		if userProfile is None or canEditThisProfile == False:
			self.abort(404)
		user_profile_json = {}
		for field in UserProfile.getJsonFields():
			user_profile_json[field] = self.request.get(field)
		userProfile.profile = json.dumps(user_profile_json)
		userProfile.put()
		self.redirect('/profile?user_email=%s' % profileId)
Ejemplo n.º 6
0
	def post(self):
		"""We only update the profile part of the profile."""
		user = users.get_current_user()
		user_profile = UserProfile.get_by_id(user.email())
		if user_profile is None:
			self.abort(404)
		user_profile_json = {}
		for field in UserProfile.getFields():
			user_profile_json[field] = self.request.get(field)
		user_profile.profile = json.dumps(user_profile_json)
		user_profile.put()
		logging.info('profile stored')
		self.redirect('/profile')
Ejemplo n.º 7
0
    def get(self):
        (template_data,
         template) = get_template('templates/wall_of_shame.html')

        all_users = [k.id() for k in UserProfile.query().fetch(keys_only=True)]
        current_week = (datetime.today() -
                        SnippetHandler.SNIPPET_START_DATE).days / 7

        snippet_stats = {}
        for user in all_users:
            snippet_stats[user] = {}

        all_snippets = []
        RANGE = range(36, current_week)
        for i in RANGE:
            all_snippets.extend(UserSnippet.getAllSnippetsByWeek(i))
        for snippet in all_snippets:
            (week, user) = snippet.getWeekAndUser()
            snippet_stats.setdefault(user, {})[int(week)] = '1'

        all_users_stats = [
            (u, [snippet_stats[u].setdefault(k, '-1') for k in RANGE])
            for u in all_users
        ]

        # We check snippets from last week.
        snippets_good = [
            k.key.id()
            for k in UserSnippet.getAllSnippetsByWeek(current_week - 1)
        ]
        template_data['snippets_good'] = sorted(snippets_good)
        template_data['snippets_bad'] = sorted(
            list(set(all_users) - set(snippets_good)))
        template_data['all_users_stats'] = all_users_stats
        self.response.out.write(template.render(template_data))
Ejemplo n.º 8
0
def profile():
    form = CreateProfile()
    if request.method == "POST" and form.validate_on_submit():
        try:
        
            created_on=str(datetime.datetime.now()).split()[0]

            photo=form.Profile_picture.data
           
            photo_filename = secure_filename(photo.filename)
            
        
            user=UserProfile(form.Firstname.data,form.Lastname.data,form.Gender.data,form.Location.data,form.Biography.data,created_on,photo_filename)
      
        
            db.session.add(user)
            db.session.commit()
            photo.save(os.path.join(app.config['UPLOAD_FOLDER'],filename))
        
            flash("Profile Added", "success")
            return redirect(url_for("profiles"))
        except :
            db.session.rollback()
            flash("Internal Error", "danger")
            return render_template("profile.html", form =form)
    
    return render_template("profile.html", form =form)
Ejemplo n.º 9
0
def getUsersMapping():
	"""Returns a dictionary: email -> { fname, lname, photo, affiliation }.
	- level 1 caching = global variable.
	- level 2 caching = memcache
	"""
	USER_MAPPING_MEMCACHE_KEY = '__USER_MAPPING__'
	global USER_MAPPING
	if USER_MAPPING:
		return USER_MAPPING
	__user_mapping__ = memcache.get(USER_MAPPING_MEMCACHE_KEY)
	if __user_mapping__:
		logging.info('USER_MAPPING already set.')
		USER_MAPPING = __user_mapping__
		return __user_mapping__
	logging.info('Building USER_MAPPING.')
	all_users = UserProfile.query().fetch(limit=500)
	users_mapping = {}
	for u in all_users:
		users_mapping[u.key.id()] = u
		#{
		#'fname': u.fname, 'lname': u.lname,
		#'photoURL': u.photoUrl, 'affiliation': u.affiliation }
	memcache.add(USER_MAPPING_MEMCACHE_KEY, users_mapping)
	USER_MAPPING = users_mapping
	logging.info(users_mapping)
	return users_mapping
Ejemplo n.º 10
0
	def get(self):
		(template_data, template) = get_template('templates/wall_of_shame.html')
		
		all_users = [k.id() for k in UserProfile.query().fetch(keys_only=True)]
		current_week = (datetime.today() - SnippetHandler.SNIPPET_START_DATE).days / 7

		snippet_stats = {}
		for user in all_users:
			snippet_stats [user] = {}

		all_snippets = []
		RANGE = range(36, current_week)
		for i in RANGE:
			all_snippets.extend(UserSnippet.getAllSnippetsByWeek(i))
		for snippet in all_snippets:
			(week, user) = snippet.getWeekAndUser()
			snippet_stats.setdefault(user, {})[int(week)] = '1'

		all_users_stats = [ (u, [ snippet_stats[u].setdefault(k, '-1') for k in RANGE ]) for u in all_users ]

		# We check snippets from last week.
		snippets_good = [k.key.id() for k in UserSnippet.getAllSnippetsByWeek(current_week-1)]
		template_data['snippets_good'] = sorted(snippets_good)
		template_data['snippets_bad'] = sorted(list(set(all_users) - set(snippets_good)))
		template_data['all_users_stats'] = all_users_stats
		self.response.out.write(template.render(template_data))
Ejemplo n.º 11
0
def deleteAllDomainUsers(dryRun=True):
	if dryRun:
		retunr
	from model import UserProfile
	all_users_keys = UserProfile.query().fetch(keys_only=True)
	for key in all_users_keys:
		key.delete()
Ejemplo n.º 12
0
def registr_6(message):
    gas_supply_id = message.text
    if len((session.query(Supply).filter(
            Supply.gas_supply_id == gas_supply_id)).all()) != 0:
        botuseon.send_message(message.from_user.id, 'Цей номер вже зайнятий')
        botuseon.register_next_step_handler(message, registr_6)
    elif gas_supply_id.isdigit():
        supply.gas_supply_id = gas_supply_id
        new_user = UserProfile(user_id=user.id,
                               user_name=user.name,
                               user_phone=user.phone,
                               user_email=user.email)
        new_supply = Supply(user_id_fk=supply.id,
                            water_supply_id=supply.water_supply_id,
                            power_supply_id=supply.power_supply_id,
                            gas_supply_id=supply.gas_supply_id)
        session.add(new_user)
        session.commit()
        session.add(new_supply)
        session.commit()
        user.state = 1
        botuseon.send_message(
            message.from_user.id,
            'Вітаємо з реестрацією. Далі Ви можете передати дані або додати картку',
            reply_markup=keyboard2)
    else:
        botuseon.send_message(
            message.from_user.id,
            'Введіть корректний номер особового рахунку газопостачання')
        botuseon.register_next_step_handler(message, registr_6)
Ejemplo n.º 13
0
def migrateUser(old_email, new_email):
	old_user = UserProfile.get_by_id(old_email)
	print old_user
	new_user = createNewUser(old_user.fname, old_user.lname, new_email, old_user.affiliation)
	new_user.profile = old_user.profile
	new_user.put()
	old_user.key.delete()
Ejemplo n.º 14
0
	def get(self):
		if self.request.get('user_email'):
			userProfile = UserProfile.getFromEmail(self.request.get('user_email'))
			if userProfile is None:
				self.abort(404)
		else:
			userProfile = getMyProfile()
		(template_data, template) = get_template('templates/profile.html')
		userProfileData = {}
		profile_data = json.loads(userProfile.profile) if userProfile.profile else {}
		for field in UserProfile.getJsonFields():
			userProfileData[field] = profile_data.setdefault(field, '')
		template_data['user'] = userProfile
		template_data['user_profile'] = userProfileData
		template_data['profileId'] = userProfile.email
		template_data['readonly'] = not(canEditThisProfile(userProfile))
		self.response.out.write(template.render(template_data))
Ejemplo n.º 15
0
	def get(self):
		(template_data, template) = get_template('templates/update_users.html')
		from domain_services import getDomainUsers
		currentUsers = [ k.id() for k in UserProfile.query().fetch(keys_only=True)]
		domainUsers = [ k for k in getDomainUsers() if k['orgUnitPath'] == '/']
		missingUsers = [k for k in domainUsers if k['primaryEmail'] not in currentUsers]
		template_data['new_users'] = [k['primaryEmail'] for k in missingUsers]
		self.response.out.write(template.render(template_data))
Ejemplo n.º 16
0
def removeUser(email):
	p = UserProject.query(UserProject.members == email).get()
	p.members.remove('*****@*****.**')
	p.put()
	if p.members == []:
		# If only member, then we remove the project.
		p.key.delete()
	u = UserProfile.query(UserProfile.email == email).get()
	u.key.delete()
Ejemplo n.º 17
0
    def post(self):
        email = self.session['email'] = self.request.get('email', '').lower()
        password = self.request.get('password')

        # Nothing to log in with
        if not email or not password:
            return self.redirect('/signup', 'email and password required')

        # Password matches the user we found with this email
        user = UserProfile.get_by_email(email)
        if user:
            return self.redirect('/signup', 'user already exists')

        user = UserProfile.create(email, password)
        self.session['user_id'] = user.id

        # Failed to login
        self.redirect('/')
Ejemplo n.º 18
0
	def post(self):
		from domain_services import getDomainUsers, createNewUser
		currentUsers = [ k.id() for k in UserProfile.query().fetch(keys_only=True)]
		domainUsers = [ k for k in getDomainUsers() if k['orgUnitPath'] == '/']
		missingUsers = [k for k in domainUsers if k['primaryEmail'] not in currentUsers]
		for user in missingUsers:
			createNewUser(user['name']['givenName'], user['name']['familyName'], user['primaryEmail'])
			logging.info("Creating user %s:" % user['primaryEmail'])
		self.redirect('/update-users')
Ejemplo n.º 19
0
 def get(self):
     if self.request.get('user_email'):
         userProfile = UserProfile.getFromEmail(
             self.request.get('user_email'))
         if userProfile is None:
             self.abort(404)
     else:
         userProfile = getMyProfile()
     (template_data, template) = get_template('templates/profile.html')
     userProfileData = {}
     profile_data = json.loads(
         userProfile.profile) if userProfile.profile else {}
     for field in UserProfile.getJsonFields():
         userProfileData[field] = profile_data.setdefault(field, '')
     template_data['user'] = userProfile
     template_data['user_profile'] = userProfileData
     template_data['profileId'] = userProfile.email
     template_data['readonly'] = not (canEditThisProfile(userProfile))
     self.response.out.write(template.render(template_data))
Ejemplo n.º 20
0
def create_profile_return_id(user_id, date):
    """ creates a new facor profile and returns user_factor_profile_id"""

    new_profile = UserProfile(user_id=user_id, date=date)
    db.session.add(new_profile)
    db.session.commit()
    new_profile = UserProfile.query.filter(
        UserProfile.user_id == user_id).first()
    profile_id = new_profile.profile_id

    return profile_id
Ejemplo n.º 21
0
 def get(self):
     (template_data, template) = get_template('templates/update_users.html')
     from domain_services import getDomainUsers
     currentUsers = [
         k.id() for k in UserProfile.query().fetch(keys_only=True)
     ]
     domainUsers = [k for k in getDomainUsers() if k['orgUnitPath'] == '/']
     missingUsers = [
         k for k in domainUsers if k['primaryEmail'] not in currentUsers
     ]
     template_data['new_users'] = [k['primaryEmail'] for k in missingUsers]
     self.response.out.write(template.render(template_data))
Ejemplo n.º 22
0
 def post(self):
     from domain_services import getDomainUsers, createNewUser
     currentUsers = [
         k.id() for k in UserProfile.query().fetch(keys_only=True)
     ]
     domainUsers = [k for k in getDomainUsers() if k['orgUnitPath'] == '/']
     missingUsers = [
         k for k in domainUsers if k['primaryEmail'] not in currentUsers
     ]
     for user in missingUsers:
         createNewUser(user['name']['givenName'],
                       user['name']['familyName'], user['primaryEmail'])
         logging.info("Creating user %s:" % user['primaryEmail'])
     self.redirect('/update-users')
Ejemplo n.º 23
0
	def get(self):
		user = users.get_current_user()
		me = user.email()
		if decorator.has_credentials():
			service = build('plus', 'v1')
			result = service.people().get(userId='me').execute(http=decorator.http())
			photoUrl = result['image']['url']
			user_profile = UserProfile.getFromGAE(user)
			user_profile.photoUrl = photoUrl
			user_profile.put()
			self.redirect('/profile')
		else:
			logging.info('no credentials')
			url = decorator.authorize_url()
			logging.info(url)
			self.redirect(url)
Ejemplo n.º 24
0
 def get(self):
     user = users.get_current_user()
     me = user.email()
     if decorator.has_credentials():
         service = build('plus', 'v1')
         result = service.people().get(userId='me').execute(
             http=decorator.http())
         photoUrl = result['image']['url']
         user_profile = UserProfile.getFromGAE(user)
         user_profile.photoUrl = photoUrl
         user_profile.put()
         self.redirect('/profile')
     else:
         logging.info('no credentials')
         url = decorator.authorize_url()
         logging.info(url)
         self.redirect(url)
Ejemplo n.º 25
0
    def post(self):
        email = self.session['email'] = self.request.get('email', '').lower()
        password = self.request.get('password')

        if self.user:
            return self.redirect('/user', 'already logged in')

        # Nothing to log in with
        if not email or not password:
            return self.redirect('/login', 'missing password')

        # Password matches the user we found with this email
        user = UserProfile.get_by_email(email)
        if user and user.check_password(password):
            self.session['user_id'] = user.id
            return self.redirect('/')

        # Failed to login
        self.redirect('/login', 'user not found')
Ejemplo n.º 26
0
def migrateProfiles():
	with open('academy-fall2014-all.csv', 'rb') as csvfile:
		reader = csv.reader(csvfile)
		mapping = {}
		for row in reader:
			email = row[2].strip()
			if len(email.split('@')) != 2:
				print >> sys.stderr, "Not a valid entry: %s" % row
				continue
			mapping[email.split('@')[0] + '@thegovlab.org'] = email
	all_users = json.loads(open('all_users.json').read())
	for k,v in all_users.iteritems():
		if k in mapping:
			profile = UserProfile.get_by_id(mapping[k])
			if profile == None:
				print >> sys.stderr, "Cannot find user %s." % mapping[k]
				continue
			profile.profile = json.dumps(v)
			profile.put()
			print "Assigned data to user %s" % mapping[k]
Ejemplo n.º 27
0
	def get(self):
		user = users.get_current_user()
		me = user.email()
		logging.info("Fetching data for user %s." % me)
		logging.info(user.user_id())
		if decorator.has_credentials():
			logging.info('has credentials')
			service = build('plus', 'v1')
			logging.info('service created')
			result = service.people().get(userId='me').execute(http=decorator.http())
			logging.info(result)
			photoUrl = result['image']['url']
			logging.info('PhotoUrl = %s' % photoUrl)
			user_profile = UserProfile.get_by_id(user.email())
			user_profile.photoUrl = photoUrl
			user_profile.put()
			logging.info('Profile updated')
			self.redirect('/profile')
		else:
			logging.info('no credentials')
			url = decorator.authorize_url()
			logging.info(url)
			self.redirect(url)
Ejemplo n.º 28
0
	def get(self):
		user = users.get_current_user()
		me = getUserProfile(user.email())
		all_profiles = memcache.get('__UserProfile_ALL__')
		if all_profiles is None:
			logging.info("memcache MISS.")
			all_profiles = UserProfile.query(UserProfile.isDormant == False).order(UserProfile.lname, UserProfile.fname).fetch(limit=500)
			memcache.add('__UserProfile_ALL__', all_profiles, time=60 * 5)
		else:
			logging.info("memcache HIT.")
		all_users = {}
		for user in all_profiles:
			all_users.setdefault(user.affiliation, []).append(user)
		template_values = {
		'me': me,
		'admin': users.is_current_user_admin(),
		#TODO (arnaud): sort
		'faculty': all_users.setdefault('GovLab', []),
		'mit_students': all_users.setdefault('MIT', []),
		'nyu_students': all_users.setdefault('NYU', []),
		'online_students': all_users.setdefault('online', []) }
		template = get_template('templates/class_roster.html')
		self.response.out.write(template.render(template_values))
Ejemplo n.º 29
0
def profile():
    form = RegisterForm()
    if request.method == 'POST':
        User_Fname = request.form['firstname']
        User_Lname = request.form['lastname']
        User_Age = request.form['age']
        User_Gender = request.form['gender']
        User_Bio = request.form['bio']
        User_name = request.form['username']
        file_folder = app.config['UPLOAD_FOLDER']
        file = request.files['file']
        filename = secure_filename(file.filename)
        file.save(os.path.join(file_folder, filename))
        ID = makeId()
        date = timeinfo()
        user = UserProfile(User_name, User_Fname, User_Lname, User_Age,
                           User_Gender, User_Bio, date)
        db.session.add(user)
        db.session.commit()
        return redirect('home.html')

    else:
        flash('All fields are required')
        return render_template('user.html', form=form)
Ejemplo n.º 30
0
 def user(self):
     user_id = int(self.session.get('user_id') or 0)
     if user_id:
         return UserProfile.get_by_id(user_id)
Ejemplo n.º 31
0
def get_recent_users(num=10):
    """ Return the 10 most recent users """
    return UserProfile.all().order('-date_created').fetch(num)
Ejemplo n.º 32
0
 def get(self):
     govlabUsers = UserProfile.query().order(
         UserProfile.lname, UserProfile.fname).fetch(limit=50)
     (template_data, template) = get_template('templates/team.html')
     template_data['team'] = govlabUsers
     self.response.out.write(template.render(template_data))
Ejemplo n.º 33
0
def getUserProfile(email):
	return UserProfile.get_by_id(fixEmail(email))
Ejemplo n.º 34
0
def checkUser(email):
	return UserProfile.get_by_id(email) != None
Ejemplo n.º 35
0
from database_connection import engine
from sqlalchemy.orm import sessionmaker
from model import UserProfile, Card, Supply, WaterSupply, PowerSupply, GasSupply
from sqlalchemy import func

Session = sessionmaker(bind=engine)
session = Session()

bob = UserProfile(user_name='Bob',
                  user_phone='+380123456789',
                  user_email='*****@*****.**')
boba = UserProfile(user_name='Boba',
                   user_phone='+380123456780',
                   user_email='*****@*****.**')

session.add(bob)
session.commit()
session.add(boba)
session.commit()

bob_id = (session.query(UserProfile).filter(
    UserProfile.user_phone == '+380123456789')[0]).user_id
boba_id = (session.query(UserProfile).filter(
    UserProfile.user_phone == '+380123456780')[0]).user_id

bobs_card = Card(user_id_fk=bob_id,
                 card_number='1234567890123456',
                 card_name='Bob Bobovich',
                 card_date=func.current_date(),
                 card_ccv='123')
bobas_card = Card(user_id_fk=boba_id,
Ejemplo n.º 36
0
def getUserLinkedinData():
	profiles = []
	for profile in UserProfile.query().fetch():
		if profile.linkedin: profiles.append(profile.linkedin['profile'])
	print json.dumps(profiles)
Ejemplo n.º 37
0
def getMyProfile():
	user = users.get_current_user()
	me = UserProfile.getFromGAE(user)
	return me
Ejemplo n.º 38
0
	def get(self):
		govlabUsers = UserProfile.query().order(UserProfile.lname, UserProfile.fname).fetch(limit=50)
		(template_data, template) = get_template('templates/team.html')
		template_data['team'] = govlabUsers 
		self.response.out.write(template.render(template_data))