Example #1
0
    def test_set_start_and_end_dates(self):
        if self.arbitrary_start_date.tzinfo:
            self.arbitrary_start_date = self.arbitrary_start_date.astimezone(get_current_timezone())
        if self.arbitrary_end_date.tzinfo:
            self.arbitrary_end_date = self.arbitrary_end_date.astimezone(get_current_timezone())
        post_data = {
            'start_date': self.arbitrary_start_date.strftime('%m/%d/%Y'),
            'start_time': self.arbitrary_start_date.strftime('%I:%M%p'),
            'end_date': self.arbitrary_end_date.strftime('%m/%d/%Y'),
            'end_time': self.arbitrary_start_date.strftime('%I:%M%p'),
            'set_duration': '',
        }

        self.client.post(reverse('surveydetails', args=[self.survey.slug]), post_data)
        self.survey = Survey.objects.get(slug="my-new-survey")
        self.assertEqual(self.survey.start_date, self.arbitrary_start_date)
        self.assertEqual(self.survey.end_date, self.arbitrary_end_date)
    def set_date(self, field, dtStr, tmStr):
        if dtStr == "":
            setattr(self, field, None)
            self.save()
            return
        try:
            dt = datetime.strptime(
                dtStr + " " + tmStr,
                '%m/%d/%Y %I:%M%p').replace(tzinfo=get_current_timezone())
            if field == 'start_date' and self.start_date:
                if self.start_date != dt and self.start_date < now(
                ) and self.has_results:
                    raise self.AlreadyPublishedError

        except ValueError:
            dt = datetime.strptime(
                dtStr, '%m/%d/%Y').replace(tzinfo=get_current_timezone())
        setattr(self, field, dt)
        self.save()
    def test_set_start_and_end_dates(self):
        if self.arbitrary_start_date.tzinfo:
            self.arbitrary_start_date = self.arbitrary_start_date.astimezone(
                get_current_timezone())
        if self.arbitrary_end_date.tzinfo:
            self.arbitrary_end_date = self.arbitrary_end_date.astimezone(
                get_current_timezone())
        post_data = {
            'start_date': self.arbitrary_start_date.strftime('%m/%d/%Y'),
            'start_time': self.arbitrary_start_date.strftime('%I:%M%p'),
            'end_date': self.arbitrary_end_date.strftime('%m/%d/%Y'),
            'end_time': self.arbitrary_start_date.strftime('%I:%M%p'),
            'set_duration': '',
        }

        self.client.post(reverse('surveydetails', args=[self.survey.slug]),
                         post_data)
        self.survey = Survey.objects.get(slug="my-new-survey")
        self.assertEqual(self.survey.start_date, self.arbitrary_start_date)
        self.assertEqual(self.survey.end_date, self.arbitrary_end_date)
Example #4
0
    def set_date(self, field, dtStr, tmStr):
        if dtStr == "":
            setattr(self, field, None)
            self.save()
            return
        try:
            dt = datetime.strptime(dtStr + " " + tmStr, '%m/%d/%Y %I:%M%p').replace(tzinfo=get_current_timezone())
            if field == 'start_date' and self.start_date:
                if self.start_date != dt and self.start_date < now() and self.has_results:
                    raise self.AlreadyPublishedError

        except ValueError:
            dt = datetime.strptime(dtStr, '%m/%d/%Y').replace(tzinfo=get_current_timezone())
        setattr(self, field, dt)
        self.save()