def send_rfps_to_subscribers(self): """ As the function name implies, all subscribed users will receive an RFP update to their email accounts. By comparing an RFP's parse date to a subscription's last update date, we ensure dups aren't being sent out. Returns a list of results based on what happened for each subscription. """ results = [] subs = Subscription.all() for sub in subs: try: # Grab what user info, add first, last name later user = User.query(query.FilterNode('username', '=', sub.username)).get() # Ensure the the sub's username is associated with an actual account # by checking if the email exists. if user.email: self._send_rfps_to_subscribers(sub, user.first_name, user.email, results) else: msg = 'No email found for username: %s and keyword: %s' % (sub.username, sub.keyword) logging.info(msg) results.append('Error: ' + msg) except: msg = 'Problem with sending RFPs for some subscription, maybe bad user object' logging.info(msg) results.append('Error: ' + msg) return results
def printUser(): print "User List:" print 100 * '#' for user in User.query().fetch(): for name in user._properties: print str(name) + ":" + str(getattr(user, name)) print 100 * '#'
def get(self): printUser() names = [ str(getattr(user, 'auth_ids')[0]) for user in User.query().fetch() ] names.sort() self.render_template('template.html', {'names': names})
def get(self): users = User.query().fetch() tasklist_name = self.request.get('tasklist_name', DEFAULT_TASKLIST_NAME) tasks_query = Task.query(ancestor=tasklist_key(tasklist_name)).order(-Task.date) tasks = tasks_query.fetch() self.render_template('authenticated.html', locals())
def printUser(): print "User List:" print 100 * '#' for user in User.query().fetch(): for name in user._properties: print str(name) + ":" + str(getattr(user, name)) print 100 * '#'
def get(self): users = User.query().fetch() tasklist_name = self.request.get('tasklist_name', DEFAULT_TASKLIST_NAME) tasks_query = Task.query( ancestor=tasklist_key(tasklist_name)).order(-Task.date) tasks = tasks_query.fetch() self.render_template('authenticated.html', locals())
def send_reports(self): queue = taskqueue.Queue('mail') keys = User.query().fetch(keys_only=True) for key in keys: task = taskqueue.Task( url='/worker/send_report', params={ 'key': key.urlsafe(), } ) queue.add(task)
def generate_reportAction(self): model={'num_comments':0,'num_articles':0,'num_users':0} # number of new comments in the last 24 hours model['num_comments']=Comments.all().filter("created >",(datetime.datetime.now()-datetime.timedelta(days=1))).count() # number of new articles in the last 24 hours model['num_articles']=ArticleModel.all().filter("updated >",(datetime.datetime.now()-datetime.timedelta(days=1))).count() # number of new users in the last 24 hours qry = User.query(User.created > datetime.datetime.now()-datetime.timedelta(days=1)) model['num_users']=qry.count() mail.send_mail('*****@*****.**', '*****@*****.**', 'Daily Activity Report',str(model)) return model
def sendMailCall(call): #TODO: fix template message = mail.EmailMessage(sender="MercatoLibero <*****@*****.**>", subject="Nuova chiamata") users = User.query().fetch() to = "" for user in users: to += user.email + ";" message.to = to path = os.path.join(os.path.dirname(__file__), 'templates', 'mail_call.html') calls_open = Call.query(Call.status == "OPEN").fetch() open = [e.to_dict() for e in calls_open] params = dict(call=call.to_dict(), open=open) res = template.render(path, params) message.html = res message.send()
def get(self): self.response.headers['Content-Type'] = 'application/json' print self.request.headers['Authorization'] user = authenticate(self.request, int(self.request.get('userid'))) if not user: self.response.write(resp.fail_auth()) else: q = User.query() def convert(user): return { 'firstname': user.firstname, 'lastname': user.lastname, 'email': user.auth_ids[0], 'id': user.key.id(), 'img': user.img } self.response.write(resp.success(q.map(convert)))
def get(self): self.response.headers['Content-Type'] = 'application/json' print self.request.headers['Authorization'] user = authenticate(self.request, int(self.request.get('userid'))) if not user: self.response.write(resp.fail_auth()) else: q = User.query() def convert(user): return { 'firstname' : user.firstname, 'lastname' : user.lastname, 'email' : user.auth_ids[0], 'id' : user.key.id(), 'img' : user.img } self.response.write( resp.success( q.map(convert) ) )
def send_rfps_to_subscribers(self): """ As the function name implies, all subscribed users will receive an RFP update to their email accounts. By comparing an RFP's parse date to a subscription's last update date, we ensure dups aren't being sent out. Returns a list of results based on what happened for each subscription. """ results = [] subs = Subscription.all() for sub in subs: try: # Grab what user info, add first, last name later user = User.query( query.FilterNode('username', '=', sub.username)).get() # Ensure the the sub's username is associated with an actual account # by checking if the email exists. if user.email: self._send_rfps_to_subscribers(sub, user.first_name, user.email, results) else: msg = 'No email found for username: %s and keyword: %s' % ( sub.username, sub.keyword) logging.info(msg) results.append('Error: ' + msg) except: msg = 'Problem with sending RFPs for some subscription, maybe bad user object' logging.info(msg) results.append('Error: ' + msg) return results
def sendMailResult(): # TODO: test this message = mail.EmailMessage(sender="MercatoLibero <*****@*****.**>", subject="Risultati") users = User.query().fetch() to = "" for user in users: to += user.email + ";" message.to = to calls_open = Call.query(Call.status == "OPEN").fetch() status = Config.query().get() if not status: status = Config() status.is_open = True status.put() if len(calls_open) > 0: path = os.path.join(os.path.dirname(__file__), 'templates', 'mail_results.html') params = dict(open=[e.to_dict() for e in calls_open]) res = template.render(path, params) for o in calls_open: o.status = "CLOSED" o.put() message.html = res message.send()
def calculate_user_knowledge(user=None,userpage=0,question=None,useranswer=None): from datetime import datetime today = datetime.today() #get the total number of questions for each category categorycount={} limit=100 page=0 questions=[0] cats={} total_records=0 if user and user.username: if userpage==0: users=[user] else: users=[] else: users=User.query().fetch(200) for user in users: # get all the answers that the user has submitted page=0 useranswers=[1] userknowledges = {} while useranswers: if question: if useranswer: if page==0: useranswers=[useranswer] else: useranswers=[] else: useranswers=UserAnswerModel.all().filter("username ="******"question =",question).fetch(limit,page*limit) else: useranswers=UserAnswerModel.all().filter("username ="******""" logging.info(today) logging.info(answer.topa) logging.info(answer.updated) logging.info("topa="+str(topa)) logging.info("delay="+str(delay)) logging.info("decay="+str(decay)) """ #logging.info("point =1.0+ "+str(topa)+"-"+str(delay)+"-"+str(decay)+"="+str(point)) else: point=0.0 for cat_key in question.cats: if userknowledges.has_key(cat_key): userknowledges[cat_key]=userknowledges[cat_key]+point else: userknowledges[cat_key]=point #for catkey in userknowledges: # logging.info("changing score for "+str(catkey)) for cat_key in userknowledges: category=CategoryModel.get(cat_key) userknowledge=UserKnowledgeModel.all().filter("username ="******"category =",category).get() maxscore=KnowledgeLib.getMaxScore(category) if not userknowledge: userknowledge=UserKnowledgeModel(username=user.username,category=category) total_records=total_records+1 userknowledge.score=userknowledges[cat_key] userknowledge.pct=(0.0+userknowledge.score/maxscore) userknowledge.save() return None
def get(self): printUser() names = [str(getattr(user, 'auth_ids')[0]) for user in User.query().fetch()] names.sort() self.render_template('template.html', {'names': names})
def getAllUsers(self): return User.query() return users
# webapp2 user store, how do you query it from webapp2_extras.appengine.auth.models import User myusers = User.query().fetch()
def applyApprovals(article,user1=None,approvals1=None,approve=True): x=0 if not article.numapprovals: article.numapprovals=0 if not article.r2: article.r2=0 if not article.v2: article.v2=0 if user1: users=[user1] else: users=User.query().fetch(200) for user in users: x=x+1 if not user1: user.username=user.auth_ids[0] if approvals1: approvals=approvals1 else: approvals=ArticleLib.getApprovals(article, user) if approve: article.numapprovals=article.numapprovals+1 memcache.incr("n_approvals_"+str(article.key()),1,None,article.numapprovals-1) #foo=memcache.get("n_approvals_"+str(article.key())) #logging.info("incrememted napprovals to "+str(foo)) article_cats=ArticleLib.getArticleCategories(article) for article_cat in article_cats: if approvals.has_key(article_cat.category.name): if approve: article_cat.v2=article_cat.v2+int(approvals[article_cat.category.name].score*100) else: article_cat.v2=article_cat.v2-int(approvals[article_cat.category.name].score*100) else: if approve: article_cat.v2=article_cat.v2+1 else: article_cat.v2=article_cat.v2-1 if article_cats: db.put(article_cats) impact=10+ArticleLib.calculate_impact(article, user.username) #logging.info("apply_impact to article: "+str(article.key())) #logging.info("apply impact = "+str(impact)) #foo=memcache.get("article_r2_"+str(article.key())) #logging.info("current rank ="+str(foo)) if approve: #memcache.incr("article_r2_"+str(article.key()),impact) #velocity=memcache.get("article_v2_"+str(article.key())) #logging.info("current v2 = "+str(velocity)) #logging.info("incrementing velocity +"+str(impact)) if article.v2+impact < 9223372036854774807: #memcache.incr("article_r2_"+str(article.key()),impact,None,article.r2+impact) memcache.incr("article_v2_"+str(article.key()),impact,None,10) article.v2=article.v2+impact else: #logging.info("descrementing velocity +"+str(impact)) #memcache.decr("article_r2_"+str(article.key()),impact) if article.v2-impact >=0: #memcache.decr("article_r2_"+str(article.key()),impact,None,article.r2-impact) memcache.decr("article_v2_"+str(article.key()),impact,None,2) article.v2=article.v2-impact article.save() # clear cache #article_cats=ArticleLib.getArticleCategories(article,True,True) return True
def get(self): if len(User.query().fetch()) == 0: bootstrap('test') self.render_response('admin/login.html')