예제 #1
0
 def update(self, name, description, priority, enabled, 
            post_date, expiry_date,
            has_additional_info):
     self.name = name
     self.description = description
     self.priority = priority
     self.enabled = enabled
     self.post_date = datetime.mx_parse_datetime(post_date)
     self.expiry_date = datetime.mx_parse_datetime(expiry_date)
     self.has_additional_info = has_additional_info
     self.forms = None
     self.forms_by_name = None
예제 #2
0
 def _test_op(a, op, b, expect):
     if a is None:
         aa = None
     else:
         aa = datetime.mx_parse_datetime(a)
     if b is None:
         bb = None
     elif type(b) is DateTime.DateTimeDeltaType:
         bb = b
     else:
         bb = datetime.mx_parse_datetime(b)
     r = op(aa, bb)
     self.assertEqual(r, expect, 
                      '%s %s %s, expected %s, got %s' %\
                         (a, op.__name__, b, expect, r))
예제 #3
0
 def _test_op(a, op, b, expect):
     if a is None:
         aa = None
     else:
         aa = datetime.mx_parse_datetime(a)
     if b is None:
         bb = None
     elif type(b) is DateTime.DateTimeDeltaType:
         bb = b
     else:
         bb = datetime.mx_parse_datetime(b)
     r = op(aa, bb)
     self.assertEqual(r, expect,
                      '%s %s %s, expected %s, got %s' %\
                         (a, op.__name__, b, expect, r))
예제 #4
0
 def __init__(self,
              text,
              table=None,
              name=None,
              form_type=None,
              allow_multiple=False,
              update_time=None,
              author=None,
              username=None):
     _ElementContainer.__init__(self, text)
     if table:
         self.table = table
     if name:
         self.name = name
     if form_type:
         self.form_type = form_type
     if allow_multiple:
         self.allow_multiple = allow_multiple
     if update_time:
         if isinstance(update_time, basestring):
             try:
                 update_time = datetime.mx_parse_datetime(update_time)
             except datetime.Error, e:
                 raise common.FormDefError('update_time: %s' % e)
         self.update_time = update_time
예제 #5
0
 def _update(self, db, inplace=False, complete=False):
     if inplace:
         # Update in place
         task = self._locked_fetch(db, self.seed_task_id, self.this_user_id)
         if task is None:
             raise TaskError('Update failed - the task has been changed'
                             ' by another user')
         _set_unlocked(task)
         _clear_completed(task)
     else:
         # Create a new task, closing the old one if necessary.
         if self.seed_task_id is not None:
             task = self._locked_fetch(db, self.seed_task_id)
             if _our_lock(task, self.this_user_id):
                 _set_unlocked(task)
             _set_completed(task, self.this_user_id)
             task.db_update()
         task = db.new_row('tasks')
         task.parent_task_id = self.seed_task_id
         task.creation_date = datetime.now()
     self._copy(self, task)
     if not self.task_description or not self.task_description.strip():
         raise TaskError('Task must have a description')
     old_due = None
     if task.due_date and task.active_date:
         old_due = task.due_date - task.active_date
     if self.active_abs and self.active_abs.strip():
         try:
             active_abs = datetime.mx_parse_datetime(self.active_abs)
         except datetime.Error, e:
             raise TaskError('Start date: %s' % e)
         if not datetime.near(active_abs, task.active_date):
             task.active_date = active_abs
 def to_sql(self, value):
     if value is None:
         return None
     elif isinstance(value, str):
         try:
             return datetime.mx_parse_datetime(value).mx()
         except datetime.Error, e:
             raise dbapi.ValidationError('%s: %s' % (self.name, e))
 def to_sql(self, value):
     if value is None:
         return None
     elif isinstance(value, str):
         try:
             return datetime.mx_parse_datetime(value).mx()
         except datetime.Error, e:
             raise dbapi.ValidationError('%s: %s' % (self.name, e))
예제 #8
0
 def __init__(self, case_row, person_loader):
     for col, value in zip(self.cols, case_row):
         col = col.split('.')[-1]
         setattr(self, col, value)
     self.person = person_loader.get(self.person_id)
     self.contact_date = datetime.mx_parse_datetime(self.contact_date)
     if self.contact_type is None:
         self.contact_type = 'Unknown'
     self.case_status = casestatus.get_label(self.syndrome_id, 
                                             self.case_status)
     self.syndrome_name = syndrome.syndromes[self.syndrome_id].name
예제 #9
0
    def mx_parse_datetime(self):
        def _mx_parse_datetime(arg, expect):
            self._test(datetime.mx_parse_datetime, (arg, ), expect)

        _mx_parse_datetime('27/02/03 11:12:13',
                           DateTime.DateTime(2003, 02, 27, 11, 12, 13))
        _mx_parse_datetime('11:12:13 27/02/03',
                           DateTime.DateTime(2003, 02, 27, 11, 12, 13))
        _mx_parse_datetime('11:12:13 27/02/03',
                           DateTime.DateTime(2003, 02, 27, 11, 12, 13.999))
        t = datetime.mx_parse_datetime('11:12:13 27/02/03')
        self._test(t.time, (), DateTime.DateTimeDelta(0, 11, 12, 13))
        self._test(t.date, (), DateTime.DateTime(2003, 02, 27))
        self.assertRaises(datetime.Error, datetime.mx_parse_datetime,
                          '11:12:13pm 27/02/03')
        self.assertRaises(datetime.Error, datetime.mx_parse_datetime,
                          '11:12:13 pm 27/02/03')
예제 #10
0
 def mx_parse_datetime(self):
     def _mx_parse_datetime(arg, expect):
         self._test(datetime.mx_parse_datetime, (arg,), expect)
     
     _mx_parse_datetime('27/02/03 11:12:13', 
                        DateTime.DateTime(2003, 02, 27, 11, 12, 13))
     _mx_parse_datetime('11:12:13 27/02/03', 
                        DateTime.DateTime(2003, 02, 27, 11, 12, 13))
     _mx_parse_datetime('11:12:13 27/02/03', 
                        DateTime.DateTime(2003, 02, 27, 11, 12, 13.999))
     t = datetime.mx_parse_datetime('11:12:13 27/02/03')
     self._test(t.time, (), DateTime.DateTimeDelta(0, 11, 12, 13))
     self._test(t.date, (), DateTime.DateTime(2003, 02, 27))
     self.assertRaises(datetime.Error,
                       datetime.mx_parse_datetime, '11:12:13pm 27/02/03')
     self.assertRaises(datetime.Error,
                       datetime.mx_parse_datetime, '11:12:13 pm 27/02/03')
예제 #11
0
 def __init__(self, text, table=None, name=None,
              form_type=None, allow_multiple=False,
              update_time=None, author=None, username=None):
     _ElementContainer.__init__(self, text)
     if table:
         self.table = table
     if name:
         self.name = name
     if form_type:
         self.form_type = form_type
     if allow_multiple:
         self.allow_multiple = allow_multiple
     if update_time:
         if isinstance(update_time, basestring):
             try:
                 update_time = datetime.mx_parse_datetime(update_time)
             except datetime.Error, e:
                 raise common.FormDefError('update_time: %s' % e)
         self.update_time = update_time
 def from_sql(self, value):
     if value is not None:
         return datetime.mx_parse_datetime(value)
 def from_sql(self, value):
     if value is not None:
         return datetime.mx_parse_datetime(value)
 def from_user(self, value):
     try:
         return datetime.mx_parse_datetime(value)
     except datetime.Error:
         return value
 def normalise_date(msg, dt):
     if dt is not None:
         try:
             return str(datetime.mx_parse_datetime(dt))
         except datetime.Error, e:
             raise page_common.PageError('%s: "%s": %s' % (msg, dt, e))
예제 #16
0
 def __init__(self, *args):
     for col, value in zip(self.cols, args):
         setattr(self, col, value)
     self.date = datetime.mx_parse_datetime(self.creation_timestamp)
예제 #17
0
def normalise_date(label, dt):
    if dt is not None:
        try:
            return str(datetime.mx_parse_datetime(dt))
        except datetime.Error, e:
            raise page_common.PageError('%s: %s' % (label, e))
예제 #18
0
 def _test(a, b, expect):
     a = datetime.mx_parse_datetime(a)
     b = datetime.mx_parse_datetime(b)
     got = datetime.relative(a, b)
     self.assertEqual(got, expect, 'got %s, expected %s' % (got, expect))
예제 #19
0
def last_run(db):
    query = db.query('dupe_persons')
    return datetime.mx_parse_datetime(query.aggregate('min(timechecked)'))
예제 #20
0
 def __init__(self, *args):
     for col, value in zip(self.cols, args):
         setattr(self, col, value)
     self.date = datetime.mx_parse_datetime(self.creation_timestamp)
예제 #21
0
    def validate(self):
        _label = self.field_label
        try:
            self.person.normalise()
            self.person.validate()
        except person.Error, e:
            raise ValidationError('%s' % e)
        case_row = self.case_row
        if not case_row.local_case_id and not self.person.surname:
            raise ValidationError('Either %s or %s must be specified' %
                                  (_label('surname'), _label('local_case_id')))
        local_case_id_validate(case_row.local_case_id)
        try:
            case_row.onset_datetime = \
                datetime.mx_parse_datetime(case_row.onset_datetime)
        except datetime.Error, e:
            raise ValidationError('%s: %s' % (_label('onset_datetime'), e))
        try:
            case_row.notification_datetime = \
                datetime.mx_parse_datetime(case_row.notification_datetime)
        except datetime.Error, e:
            raise ValidationError('%s: %s' %
                                  (_label('notification_datetime'), e))
        if datetime.is_later_than(self.case_row.onset_datetime,
                                  self.case_row.notification_datetime):
            raise ValidationError(
                '%s must be after %s' %
                (_label('notification_datetime'), _label('onset_datetime')))
        if datetime.is_later_than(self.person.DOB,
                                  self.case_row.onset_datetime):
예제 #22
0
 def _test(rel, ref, expect):
     ref = datetime.mx_parse_datetime(ref)
     expect = datetime.mx_parse_datetime(expect)
     got = datetime.parse_discrete(rel, ref)
     self.assertEqual(got, expect,
                      'got %s, expected %s' % (got, expect))
예제 #23
0
 def _test(a, b, expect):
     a = datetime.mx_parse_datetime(a)
     b = datetime.mx_parse_datetime(b)
     got = datetime.relative(a, b)
     self.assertEqual(got, expect,
                      'got %s, expected %s' % (got, expect))
예제 #24
0
 def _test(rel, ref, expect):
     ref = datetime.mx_parse_datetime(ref)
     expect = datetime.mx_parse_datetime(expect)
     got = datetime.parse_discrete(rel, ref)
     self.assertEqual(got, expect, 'got %s, expected %s' % (got, expect))
 def from_user(self, value):
     try:
         return datetime.mx_parse_datetime(value)
     except datetime.Error:
         return value
예제 #26
0
     self.person.validate()
 except person.Error, e:
     raise ValidationError('%s' % e)
 case_row = self.case_row
 if not case_row.local_case_id and not self.person.surname:
     raise ValidationError('Either %s or %s must be specified' %
                           (_label('surname'), _label('local_case_id')))
 local_case_id_validate(case_row.local_case_id)
 try:
     case_row.onset_datetime = \
         datetime.mx_parse_datetime(case_row.onset_datetime)
 except datetime.Error, e:
     raise ValidationError('%s: %s' % (_label('onset_datetime'), e))
 try:
     case_row.notification_datetime = \
         datetime.mx_parse_datetime(case_row.notification_datetime)
 except datetime.Error, e:
     raise ValidationError('%s: %s' % 
                           (_label('notification_datetime'), e))
 if datetime.is_later_than(self.case_row.onset_datetime,
                           self.case_row.notification_datetime):
     raise ValidationError('%s must be after %s' %
                           (_label('notification_datetime'), 
                            _label('onset_datetime')))
 if datetime.is_later_than(self.person.DOB,
                           self.case_row.onset_datetime):
     raise ValidationError('%s must be after %s' %
                           (_label('onset_datetime'), _label('DOB')))
 if datetime.is_later_than(self.person.DOB, datetime.now()):
     raise ValidationError('\'%s\': %s must not be in the future' %
             (self.person.DOB, _label('DOB')))
예제 #27
0
     raise TaskError('Task must have a description')
 old_due = None
 if task.due_date and task.active_date:
     old_due = task.due_date - task.active_date
 if self.active_abs and self.active_abs.strip():
     try:
         active_abs = datetime.mx_parse_datetime(self.active_abs)
     except datetime.Error, e:
         raise TaskError('Start date: %s' % e)
     if not datetime.near(active_abs, task.active_date):
         task.active_date = active_abs
 elif self.active != 'nochange':
     task.active_date = datetime.parse_discrete(self.active)
 if self.due_abs and self.due_abs.strip():
     try:
         due_abs = datetime.mx_parse_datetime(self.due_abs)
     except datetime.Error, e:
         raise TaskError('Complete by date: %s' % e)
     if not datetime.near(due_abs, task.due_date):
         task.due_date = due_abs
 elif self.due != 'nochange':
     task.due_date = datetime.parse_discrete(self.due, task.active_date)
 if self.active != 'nochange' and self.due == 'nochange' and old_due:
     # If active date has changed, but due date has not, preserve the
     # relationship between the old active date and the old due date...
     task.due_date = task.active_date + old_due
 _set_assigned(task, self.this_user_id)
 task.queue_id = self.assignee.get_queue_id(db)
 if complete:
     _set_completed(task, self.this_user_id)
 assert task.assigner_id is not None