username = username_from_dn(qcg_job.user_dn)
if user is not None:
if user.username != username:
- raise ValueError('Username does not match!')
+ raise ValueError('Username does not match ({} vs. {})!'.format(repr(user.username), repr(username)))
attrs['owner'] = user
else:
attrs['owner'] = User.objects.get(username=username)
return attrs
- @classmethod
- def from_qcg(cls, qcg_job):
- job = cls(**cls.qcg_map(qcg_job))
- job._job = qcg_job
-
- return job
-
class Task(models.Model):
STATUS_CHOICES = list(enumerate(field for field in dir(TaskStatus) if not field.startswith('__')))
@property
def qcg_task(self):
- if self._qcg_task is None:
- self._qcg_task = QcgTask(EPRUtils.deserialize_epr(self.epr))
+ if self._task is None:
+ self._task = QcgTask(EPRUtils.deserialize_epr(self.epr))
- return self._qcg_task
+ return self._task
@staticmethod
- def qcg_map(qcg_task, jobs=None):
+ def qcg_map(qcg_task, job=None):
attrs = get_attributes(qcg_task, ('task_id', 'status_description', 'note', 'description', 'submission_time',
'start_time', 'finish_time', 'reserved_time_slot', 'purged'))
attrs['type'] = Task.TYPE_CHOICES_REVERSED[qcg_task.type]
attrs['proxy_lifetime'] = now() + qcg_task.proxy_lifetime
- if jobs is not None and qcg_task.job_id in jobs:
- attrs['job'] = jobs[qcg_task.job_id]
+ if job is not None:
+ if qcg_task.job_id != job.job_id:
+ raise ValueError('Job id does not match ({} vs. {})!'.format(repr(qcg_task.job_id), repr(job.job_id)))
+ attrs['job'] = job
else:
attrs['job'] = Job.objects.get(job_id=qcg_task.job_id)
return attrs
- @classmethod
- def from_qcg(cls, qcg_task):
- task = cls(**cls.qcg_map(qcg_task))
- task._task = qcg_task
-
- return task
-
@property
def reserved_time_slot(self):
if self.reserved_time_start or self.reserved_time_finish: