def updateDueDate(request, company_name, member_name, option): # make sure member is an admin and has the right to access this information admin = adminAuth(request, company_name, member_name) print option if admin: # save posted data if available if request.method == 'POST': company = Company.objects.get(name=company_name) if option == 'conflicts': try: valid_datetime = datetime.strptime(request.POST['datetimepicker4'], '%m/%d/%Y %I:%M %p') company.conflicts_due = valid_datetime.replace(tzinfo=timezone.LocalTimezone()) company.save() return redirect('profiles:profile', company_name=company_name, member_name=member_name) except ValueError: return HttpResponse('You did not enter a valid date and time. So the information was not saved.') if option == 'casting': try: valid_datetime = datetime.strptime(request.POST['datetimepicker4'], '%m/%d/%Y %I:%M %p') company.casting_due = valid_datetime.replace(tzinfo=timezone.LocalTimezone()) company.save() return redirect('profiles:profile', company_name=company_name, member_name=member_name) except ValueError: return HttpResponse('You did not enter a valid date and time. So the information was not saved.') return redirect('profiles:profile', company_name, member_name,) return render(request, 'profiles/datetimepicker.html', {'company_name':company_name, 'member_name':member_name, 'option':option}) # admins and members logged in under the wrong name cannot access this page raise PermissionDenied
def handle(self, *args, **options): self.stdout.write("running...") today = datetime.datetime.combine( datetime.date.today(), datetime.time(0, 0, tzinfo=timezone.LocalTimezone())) reminder_template = get_template("email/reminder.txt") reminder_events = Event.objects.filter( start_time__gte=today + datetime.timedelta(days=1), start_time__lt=today + datetime.timedelta(days=2), ) for event in reminder_events: for user in event.participant.all(): send_template_mail(reminder_template, { 'user': user, 'event': event }, self.from_address, [user.email]) deadline_template = get_template("email/deadline.txt") deadline_frames = Frame.objects.filter( deadline__gte=today + datetime.timedelta(days=1), deadline__lt=today + datetime.timedelta(days=2), ) for frame in deadline_frames: if frame.event not in reminder_events: for user in frame.participant.all(): send_template_mail(deadline_template, { 'user': user, 'event': frame.event }, self.from_address, [user.email]) self.stdout.write("success...!")
def test_localtime_naive(self): now = datetime.datetime.now() if PY36: self.assertEqual(timezone.localtime(now), now.replace(tzinfo=timezone.LocalTimezone())) else: with self.assertRaisesMessage(ValueError, 'astimezone() cannot be applied to a naive datetime'): timezone.localtime(now)
def test_localtime(self): now = datetime.datetime.utcnow().replace(tzinfo=timezone.utc) local_tz = timezone.LocalTimezone() with timezone.override(local_tz): local_now = timezone.localtime(now) self.assertEqual(local_now.tzinfo, local_tz) local_now = timezone.localtime(now, timezone=local_tz) self.assertEqual(local_now.tzinfo, local_tz)
def test_localtime_out_of_range(self): local_tz = timezone.LocalTimezone() long_ago = datetime.datetime(1900, 1, 1, tzinfo=timezone.utc) try: timezone.localtime(long_ago, local_tz) except (OverflowError, ValueError) as exc: self.assertIn("install pytz", exc.args[0]) else: self.skipTest("Failed to trigger an OverflowError or ValueError")
def get_current_status(status_path): try: line = get_last_line(status_path) except ShellExecuteError: return None if line.startswith("real-time"): return None status = ZmapStatus() items = line.split(",") t = time.strptime(items[0], "%Y-%m-%d %X") y, m, d, h, M, s = t[0:6] status.read_time = datetime.datetime(y, m, d, h, M, s, tzinfo=timezone.LocalTimezone()) status.time_elapsed = int(items[1]) status.time_remaining = int(items[2]) status.percent_complete = float(items[3]) status.active_send_threads = int(items[4]) status.sent_total = long(items[5]) status.sent_last_one_sec = int(items[6]) status.sent_avg_per_sec = int(items[7]) status.recv_success_total = long(items[8]) status.recv_success_last_one_sec = int(items[9]) status.recv_success_avg_per_sec = int(items[10]) status.recv_total = long(items[11]) status.recv_total_last_one_sec = int(items[12]) status.recv_total_avg_per_sec = int(items[13]) status.pcap_drop_total = long(items[14]) status.drop_last_one_sec = int(items[15]) status.drop_avg_per_sec = int(items[16]) status.sendto_fail_total = long(items[17]) status.sendto_fail_last_one_sec = int(items[18]) status.sendto_fail_avg_per_sec = int(items[19]) return status
def test_pickling_unpickling(self): self.assertIsInstance(pickle.loads(pickle.dumps(timezone.UTC())), timezone.UTC) self.assertIsInstance( pickle.loads(pickle.dumps(timezone.LocalTimezone())), timezone.LocalTimezone)
def test_deepcopy(self): self.assertIsInstance(copy.deepcopy(timezone.UTC()), timezone.UTC) self.assertIsInstance(copy.deepcopy(timezone.LocalTimezone()), timezone.LocalTimezone)
def test_localtime(self): now = datetime.datetime.utcnow().replace(tzinfo=timezone.utc) local_tz = timezone.LocalTimezone() local_now = timezone.localtime(now, local_tz) self.assertEqual(local_now.tzinfo, local_tz)
def get_current_status(status_path): """ real-time, time-elapsed, time-remaining, percent-complete, hit-rate, active-send-threads, sent-total, sent-last-one-sec, sent-avg-per-sec, recv-success-total, recv-success-last-one-sec, recv-success-avg-per-sec, recv-total, recv-total-last-one-sec, recv-total-avg-per-sec, pcap-drop-total, drop-last-one-sec, drop-avg-per-sec, sendto-fail-total, sendto-fail-last-one-sec, sendto-fail-avg-per-sec :param status_path: :return: """ try: line = get_last_line(status_path) except ShellExecuteError: return None if line.startswith("real-time"): return None status = ZmapStatus() items = line.split(",") t = time.strptime(items[0], "%Y-%m-%d %X") y, m, d, h, M, s = t[0:6] status.read_time = datetime.datetime(y, m, d, h, M, s, tzinfo=timezone.LocalTimezone()) status.time_elapsed = int(items[1]) status.time_remaining = int(items[2]) status.percent_complete = float(items[3]) status.hit_rate = float(items[4]) status.active_send_threads = int(items[5]) status.sent_total = long(items[6]) status.sent_last_one_sec = int(items[7]) status.sent_avg_per_sec = int(items[8]) status.recv_success_total = long(items[9]) status.recv_success_last_one_sec = int(items[10]) status.recv_success_avg_per_sec = int(items[11]) status.recv_total = long(items[12]) status.recv_total_last_one_sec = int(items[13]) status.recv_total_avg_per_sec = int(items[14]) status.pcap_drop_total = long(items[15]) status.drop_last_one_sec = int(items[16]) status.drop_avg_per_sec = int(items[17]) status.sendto_fail_total = long(items[18]) status.sendto_fail_last_one_sec = int(items[19]) status.sendto_fail_avg_per_sec = int(items[20]) return status
def test_datetimeoffset(self): from django.utils import timezone val = timezone.make_aware(datetime.datetime.now(), timezone.LocalTimezone()) self._test(DateTimeOffsetTable, val)