def get(self): ''' New Ajax Functions suites for multiple usage for new calit2 Template. ''' func = self.request.get("func") maxitems = self.request.get("maxitems") if maxitems != '': maxitems = int(maxitems) #template_name = self.request.get("template") template_name = "calit2" CurrentUser = self.get_user_db() template_values = { 'UserNickName': cgi.escape(CurrentUser.dispname), 'UserID': CurrentUser.key().id(), 'func': func, } if func == "done": tarsusaItemCollection_AjaxUserItems = tarsusaCore.get_tarsusaItemCollection(CurrentUser.key().id(), done=True, maxitems=maxitems) template_values['tarsusaItemCollection_AjaxUserItems'] = tarsusaItemCollection_AjaxUserItems elif func == "undone": tarsusaItemCollection_AjaxUserItems = tarsusaCore.get_tarsusaItemCollection(CurrentUser.key().id(), done=False, maxitems=maxitems) template_values['tarsusaItemCollection_AjaxUserItems'] = tarsusaItemCollection_AjaxUserItems elif func == "dailyroutine": tarsusaItemCollection_AjaxUserItems = tarsusaCore.get_dailyroutine(CurrentUser.key().id()) template_values['tarsusaItemCollection_AjaxUserItems'] = tarsusaItemCollection_AjaxUserItems elif func == "friends": UserFriendsItem_List = tarsusaCore.get_UserFriendStats(CurrentUser.key().id()) template_values['UserFriendsActivities'] = UserFriendsItem_List path = os.path.join(os.path.dirname(__file__), 'pages/%s/ajax_content_%s.html' % (template_name, "itemlist")) self.write(template.render(path, template_values))
def get(self): user_address = "*****@*****.**" if not mail.is_email_valid(user_address): # prompt user to enter a valid address #print 'error' pass else: if self.chk_login(): CurrentUser = self.get_user_db() tarsusaItemCollection = tarsusaCore.get_dailyroutine(CurrentUser.key().id()) tarsusaItem_DueToday = tarsusaCore.get_ItemsDueToday(CurrentUser.key().id()) ItemsInMail = '' for eachItem in tarsusaItem_DueToday: ItemsInMail += "<li><a href=/item/" + eachItem['id'] + ">" + eachItem['name'] + "</a></li>" DueTodayTotal = len(tarsusaItemCollection) + len(tarsusaItem_DueToday) message = mail.EmailMessage() message.sender = "*****@*****.**" message.to = user_address message.subject = "CheckNerds每日提醒 - " + str(datetime.date.today()) + " - " + str(DueTodayTotal) + "项事项" template_values = { 'PrefixCSSdir': "/", 'UserNickName': "访客", 'AnonymousVisitor': "Yes", 'Today': str(datetime.date.today()), 'EmailTitle': message.subject, 'CountItemsDueToday': str(DueTodayTotal), 'ItemsDueToday':tarsusaItemCollection + tarsusaItem_DueToday, } path = os.path.join(os.path.dirname(__file__), 'pages/mail/dailybriefing.html') final_body = template.render(path, template_values) message.html = final_body message.send()
def post(self): if self.chk_login(): CurrentUser = self.get_user_db() else: self.redirect('/') cachedUserDailyroutineToday = memcache.get_item("dailyroutine_today", CurrentUser.key().id()) #if cachedUserDailyroutineToday is not None: if cachedUserDailyroutineToday == True: strcachedUserDailyroutineToday = cachedUserDailyroutineToday else: tarsusaItemCollection_DailyRoutine = tarsusaCore.get_dailyroutine(CurrentUser.key().id()) ## Output the message for DailyRoutine ''' template_tag_donealldailyroutine = '' if Today_DoneRoutine == int(tarsusaItemCollection_DailyRoutine_count) and Today_DoneRoutine != 0: template_tag_donealldailyroutine = '<img src="img/favb16.png">恭喜,你完成了今天要做的所有事情!' elif Today_DoneRoutine == int(tarsusaItemCollection_DailyRoutine_count) - 1: template_tag_donealldailyroutine = '只差一项,加油!' elif int(tarsusaItemCollection_DailyRoutine_count) == 0: template_tag_donealldailyroutine = '还没有添加每日计划?赶快添加吧!<br />只要在添加项目时,将“性质”设置为“每天要做的”就可以了!' ''' template_values = { 'UserLoggedIn': 'Logged In', 'UserNickName': cgi.escape(CurrentUser.dispname), 'UserID': CurrentUser.key().id(), 'tarsusaItemCollection_DailyRoutine': tarsusaItemCollection_DailyRoutine, #'htmltag_DoneAllDailyRoutine': template_tag_donealldailyroutine, 'htmltag_today': datetime.datetime.date(datetime.datetime.now()), } #Manupilating Templates path = os.path.join(os.path.dirname(__file__), 'pages/ajaxpage_dailyroutine.html') strcachedUserDailyroutineToday = template.render(path, template_values) if not memcache.set_item("dailyroutinetoday", strcachedUserDailyroutineToday, CurrentUser.key().id()): logging.error('Cache set failed: ajax_ShowUserDailyRoutineToday') self.write(strcachedUserDailyroutineToday)
def test_tarsusaCore_gettarsusaDailyRoutine(self): DailyRoutine = tarsusaCore.get_dailyroutine(userid=1)