def saveComment(self): results = {'result': False} text = self.request.get('commentText') pointRootUrlsafe = self.request.get('p') parentCommentUrlsafe = self.request.get('parentKey') user = self.current_user if user: try: comment = Comment.create( text, user, pointRootUrlsafe, parentCommentUrlsafe) if comment: pst_date = PST.convert(comment.date) results = { 'result': True, 'userName': user.name, 'userURL': user.url, 'avatar_url': user.avatar_url if hasattr(user, 'avatar_url') else '/static/img/icon_triceratops_black_47px.png', 'text': text, 'date': pst_date.strftime('%b. %d, %Y, %I:%M %p'), 'parentUrlsafe': parentCommentUrlsafe, 'myUrlSafe':comment.key.urlsafe(), 'level': comment.level } except WhysaurusException as e: results['error'] = str(e) resultJSON = json.dumps(results) self.response.headers.add_header('content-type', 'application/json', charset='utf-8') self.response.out.write(resultJSON)
def queueNightlyTask(self): now = PST.convert(datetime.datetime.now()) tomorrow = now + datetime.timedelta(days = 1) half_past_midnight = datetime.time(hour=7, minute=30) # PST taskTime = datetime.datetime.combine(tomorrow, half_past_midnight) t = Task(url='/job/DBIntegrityCheck', method="GET", eta=taskTime) t.add(queue_name="dbchecker")
def queueNightlyTask(self): now = PST.convert(datetime.datetime.now()) tomorrow = now + datetime.timedelta(days=1) half_past_midnight = datetime.time(hour=7, minute=30) # PST taskTime = datetime.datetime.combine(tomorrow, half_past_midnight) t = Task(url='/job/DBIntegrityCheck', method="GET", eta=taskTime) t.add(queue_name="dbchecker")
def get(self): mode = self.request.get('mode') bigMessage = [] namespace_manager.set_namespace('') namespaces = PrivateArea.query() for pa in namespaces.iter(): logging.info("Looking at private area: " + pa.name) bigMessage = bigMessage + self.checkNamespace(pa.name) bigMessage = bigMessage + self.checkNamespace('') template_values = { 'messages': bigMessage, 'user': self.current_user, 'currentArea': self.session.get('currentArea') } if mode and mode == 'screen': self.response.out.write( self.template_render('message.html', template_values)) else: path = os.path.join(os.path.dirname(__file__), '../templates/dbcheck.html') # old version, delete once the new version is working: # mail.send_mail(sender='*****@*****.**', # to='*****@*****.**', # subject='Database Integrity Check Results %s' % str(PST.convert(datetime.datetime.now())), # html=template.render(path, template_values), # body=str(bigMessage), # reply_to="*****@*****.**" # ) # new version: message = mail.EmailMessage( sender='*****@*****.**', to='*****@*****.**', cc='*****@*****.**', subject='Database Integrity Check Results %s' % str(PST.convert(datetime.datetime.now())), body=str(bigMessage), reply_to="*****@*****.**") if html: message.html = template.render(path, template_values), message.send() # (end of new version) self.queueNightlyTask() template_values = { 'message': "Sent email successfully. Queued nightly task.", 'user': self.current_user, 'currentArea': self.session.get('currentArea') } self.response.out.write( self.template_render('message.html', template_values))
def saveComment(self): results = {'result': False} text = self.request.get('commentText') pointRootUrlsafe = self.request.get('p') parentCommentUrlsafe = self.request.get('parentKey') user = self.current_user if user: try: pointRoot = PointRoot.getByUrlsafe(pointRootUrlsafe) if pointRoot: comment = Comment.create(text, user, pointRoot, parentCommentUrlsafe) if comment: pst_date = PST.convert(comment.date) results = { 'result': True, 'userName': user.name, 'userURL': user.url, 'avatar_url': user.avatar_url if hasattr(user, 'avatar_url') else '/static/img/icon_triceratops_black_47px.png', 'text': text, 'date': pst_date.strftime('%b. %d, %Y, %I:%M %p'), 'parentUrlsafe': parentCommentUrlsafe, 'myUrlSafe': comment.key.urlsafe(), 'level': comment.level } Point.addNotificationTask(pointRoot.key, user.key, 3, text) else: results[ 'error'] = 'Unable to find the point to add this comment' except WhysaurusException as e: results['error'] = str(e) resultJSON = json.dumps(results) self.response.headers[ "Content-Type"] = 'application/json; charset=utf-8' self.response.out.write(resultJSON)
def get(self): mode = self.request.get('mode') bigMessage = [] namespace_manager.set_namespace('') namespaces = PrivateArea.query() for pa in namespaces.iter(): logging.info("Looking at private area: " + pa.name) bigMessage = bigMessage + self.checkNamespace(pa.name) bigMessage = bigMessage + self.checkNamespace('') template_values = { 'messages': bigMessage, 'user': self.current_user, 'currentArea':self.session.get('currentArea') } if mode and mode == 'screen': path = os.path.join(os.path.dirname(__file__), '../templates/message.html') self.response.out.write(template.render(path, template_values)) else: path = os.path.join(os.path.dirname(__file__), '../templates/dbcheck.html') mail.send_mail(sender='*****@*****.**', to='*****@*****.**', subject='Database Integrity Check Results %s' % str(PST.convert(datetime.datetime.now())), html=template.render(path, template_values), body=str(bigMessage), reply_to="*****@*****.**" ) self.queueNightlyTask() template_values = { 'message': "Sent email successfully. Queued nightly task.", 'user': self.current_user, 'currentArea':self.session.get('currentArea') } path = os.path.join(os.path.dirname(__file__), '../templates/message.html') self.response.out.write(template.render(path, template_values))
def saveComment(self): results = {'result': False} text = self.request.get('commentText') pointRootUrlsafe = self.request.get('p') parentCommentUrlsafe = self.request.get('parentKey') user = self.current_user if user: try: pointRoot = PointRoot.getByUrlsafe(pointRootUrlsafe) if pointRoot: comment = Comment.create( text, user, pointRoot, parentCommentUrlsafe) if comment: pst_date = PST.convert(comment.date) results = { 'result': True, 'userName': user.name, 'userURL': user.url, 'avatar_url': user.avatar_url if hasattr(user, 'avatar_url') else '/static/img/icon_triceratops_black_47px.png', 'text': text, 'date': pst_date.strftime('%b. %d, %Y, %I:%M %p'), 'parentUrlsafe': parentCommentUrlsafe, 'myUrlSafe':comment.key.urlsafe(), 'level': comment.level } Point.addNotificationTask(pointRoot.key, user.key, 3, text) else: results['error'] = 'Unable to find the point to add this comment' except WhysaurusException as e: results['error'] = str(e) resultJSON = json.dumps(results) self.response.headers["Content-Type"] = 'application/json; charset=utf-8' self.response.out.write(resultJSON)
def post(self): mail.send_mail( sender='*****@*****.**', to='*****@*****.**', subject='WHYSAURUS CONTACT RE: ' + self.request.get('subject') +' || DATE: '+ str(PST.convert(datetime.datetime.now())), body='From: ' + self.request.get('email') + '\n\n' + self.request.get('message'), reply_to=self.request.get('email') ) template_values = { 'message': "Thank you for your message.", } self.response.out.write(self.template_render('message.html', template_values))
def PSTdateText(self): return PST.convert(self.date).strftime('%b. %d, %Y, %I:%M %p')
def PSTdateText(self): return PST.convert(self.date).strftime("%b. %d, %Y, %I:%M %p")