def clean_task(self): data = self.cleaned_data['task'] try: parsedate(data) except ValueError: raise ValidationError("Please add a date.") return data
def save(self, user): task = self.cleaned_data['task'] datedict = parsedate(task) f = '%m %d %Y' is_meeting = 'hours' in datedict dates = "{mon} {day} {yr}".format(mon=datedict['month'], day=datedict['day'], yr=datedict['year']) if is_meeting: startdate = dates + " {hr}:{min}".format(hr=datedict['hours'], min=datedict['minutes']) f += ' %H:%M' starttime = time.mktime(time.strptime(startdate, f)) date_started = dt.datetime.fromtimestamp(starttime) date_ended = date_started + dt.timedelta(hours=1) event = Meeting.objects.create(date_started=date_started, date_ended=date_ended, user=user) else: # Follow-Up date = dt.datetime.strptime(dates, f).date() event = FollowUp.objects.create(date=date, user=user) event.subject = task event.save() return event
def _assertdate(string, hr, day, mon, min_=None, yr=None): res = date.parsedate(string) hrs = '0' + str(hr) if hr < 10 else str(hr) self.assertEqual(res['hours'], hrs) days = '0' + str(day) if day < 10 else str(day) self.assertEqual(res['day'], days) mons = '0' + str(mon) if mon < 10 else str(mon) self.assertEqual(res['month'], mons) if min_ is not None: mins = '0' + str(min_) if min_ < 10 else str(min_) self.assertEqual(res['minutes'], mins) if yr is not None: self.assertEqual(res['year'], str(yr))