def get_cur(request): """ Get current timer """ if request.is_ajax(): try: uinfo = get_user_info(request) tl_id = request.GET.get('tl_id') if tl_id: t = timer.get_timelist_current_timer(request.user, int(tl_id)) else: t = timer.get_current_timer(uinfo) if not t: return JsonResponse({'ret':'no cur timer'}); return JsonResponse({'ret':'ok', 'valid':True, 'data':format_timer_str(t)}) except PermissionDenied: return JsonResponse({'ret':'Permission Denied'})
def test(self): now = get_utcnow() from datetime import timedelta time = now + timedelta(days=10) time_range = {'start': parseStr2utc(time - timedelta(days=1), self.tz_name), 'end': parseStr2utc(time + timedelta(days=1), self.tz_name)} # time = parseStr2utc('20110809T091606', self.tz_name) t = timer.create(time=time, title='Timer title', desc='Timer desc', user=self.owner, tlid=self.timelist.id, tzname=self.tz_name) # get_timer self.assertEqual(timer.get_timer(self.owner.id, t.id) is None, False); # get_timers self.assertEqual(len(timer.get_timers({'user': self.owner}, time_range.get('start'), time_range.get('end'))), 1) self.assertEqual(len(timer.get_timers({'user': self.owner, 'is_home': True}, time_range.get('start'), time_range.get('end'))), 1) self.assertEqual(len(timer.get_timers({'user': self.owner, 'is_own': True}, time_range.get('start'), time_range.get('end'))), 1) # error range err_time_range = {'start': parseStr2utc(time + timedelta(days=1), self.tz_name), 'end': parseStr2utc(time + timedelta(days=2), self.tz_name)} self.assertEqual(len(timer.get_timers({'user': self.owner}, err_time_range.get('start'), err_time_range.get('end'))), 0) # get_timelist_timers self.assertEqual(len(timer.get_timelist_timers(self.owner, self.timelist.id, time_range.get('start'), time_range.get('end'))), 1) self.assertEqual(len(timer.get_timelist_timers(self.owner, self.timelist.id, err_time_range.get('start'), err_time_range.get('end'))), 0) # get_crrent_timer self.assertEqual(timer.get_current_timer({'user': self.owner, 'is_own': True}).id, t.id) self.assertEqual(timer.get_current_timer({'user': self.owner, 'is_home': True}).id, t.id) self.assertEqual(timer.get_current_timer({'user': self.owner}).id, t.id) # get _timelist_current_timer self.assertEqual(timer.get_timelist_current_timer(self.owner, self.timelist.id).id, t.id) # edit title = 'test title edit' desc = 'test desc edit' t = timer.edit(user=self.owner, tid=t.id, time=time, title=title, desc=desc, tlid=self.timelist.id, tzname=self.tz_name, reminders=None) self.assertEqual(t.title, title) self.assertEqual(t.desc, desc) # delete timer.delete(self.owner, t.id) self.assertEqual(len(timer.get_timers({'user': self.owner}, time_range.get('start'), time_range.get('end'))), 0)