fixes in model attributes
authorMaciej Tronowski <mtro@man.poznan.pl>
Wed, 25 Feb 2015 11:41:26 +0000 (12:41 +0100)
committerMaciej Tronowski <mtro@man.poznan.pl>
Wed, 25 Feb 2015 11:41:26 +0000 (12:41 +0100)
qcg/migrations/0001_initial.py
qcg/models.py
qcg/templates/qcg/task.html

index c2f06b5..85f384f 100644 (file)
@@ -44,9 +44,10 @@ class Migration(migrations.Migration):
             fields=[
                 ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                 ('host_name', models.CharField(max_length=100, verbose_name='Host')),
+                ('status', models.IntegerField(verbose_name='Status', choices=[(0, b'CANCELED'), (1, b'FAILED'), (2, b'FINISHED'), (3, b'PENDING'), (4, b'POSTPROCESSING'), (5, b'PREPROCESSING'), (6, b'RUNNING'), (7, b'STOPPED'), (8, b'SUBMISSION'), (9, b'UNCOMMITTED'), (10, b'UNSUBMITTED')])),
                 ('status_description', models.TextField(default=b'', verbose_name='Opis statusu', blank=True)),
-                ('processes_count', models.PositiveIntegerField(verbose_name='Liczba procesor\xf3w')),
-                ('slots_count', models.PositiveIntegerField(verbose_name='Liczba slot\xf3w')),
+                ('processes_count', models.PositiveIntegerField(verbose_name='Liczba proces\xf3w')),
+                ('slots_count', models.PositiveIntegerField(verbose_name='Liczba rdzeni')),
                 ('processes_group_id', models.TextField(default=b'', verbose_name='Identyfikator grupy proces\xf3w', blank=True)),
                 ('submission_time', models.DateTimeField(verbose_name='Data wys\u0142ania')),
                 ('estimated_start_time', models.DateTimeField(null=True, verbose_name='Przewidywana data rozpocz\u0119cia', blank=True)),
@@ -94,7 +95,7 @@ class Migration(migrations.Migration):
             fields=[
                 ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                 ('name', models.CharField(max_length=32, verbose_name='Nazwa')),
-                ('count', models.PositiveSmallIntegerField(null=True, verbose_name='Liczba slot\xf3w', blank=True)),
+                ('count', models.PositiveSmallIntegerField(null=True, verbose_name='Liczba rdzeni', blank=True)),
                 ('allocation', models.ForeignKey(related_name='nodes', verbose_name='Alokacja', to='qcg.Allocation')),
             ],
             options={
index 8c2be2d..451d7fb 100644 (file)
@@ -4,7 +4,7 @@ from django.core.urlresolvers import reverse
 from django.db import models
 from django.utils.timezone import now
 from pyqcg.service import Job as QcgJob, Task as QcgTask
-from pyqcg.utils import JobStatus, TaskStatus, TaskType
+from pyqcg.utils import JobStatus, TaskStatus, TaskType, AllocationType, EPRUtils
 
 from qcg.utils import username_from_dn, get_attributes
 
@@ -55,7 +55,7 @@ class Job(models.Model):
     @property
     def qcg_job(self):
         if self._job is None:
-            self._job = QcgJob(self.epr)
+            self._job = QcgJob(EPRUtils.deserialize_epr(self.epr))
 
         return self._job
 
@@ -64,14 +64,14 @@ class Job(models.Model):
         attrs = get_attributes(qcg_job, ('job_id', 'note', 'description', 'submission_time', 'finish_time',
                                          'project', 'purged'))
 
-        attrs['epr'] = str(qcg_job.epr)
+        attrs['epr'] = EPRUtils.serialize_epr(qcg_job.epr)
         attrs['status'] = Job.STATUS_CHOICES_REVERSED[qcg_job.status]
         attrs['proxy_lifetime'] = now() + qcg_job.proxy_lifetime
 
         username = username_from_dn(qcg_job.user_dn)
         if user is not None:
             if user.username != username:
-                raise ValueError('')
+                raise ValueError('Username does not match!')
             attrs['owner'] = user
         else:
             attrs['owner'] = User.objects.get(username=username)
@@ -129,7 +129,7 @@ class Task(models.Model):
     @property
     def qcg_task(self):
         if self._qcg_task is None:
-            self._qcg_task = QcgTask(self.epr)
+            self._qcg_task = QcgTask(EPRUtils.deserialize_epr(self.epr))
 
         return self._qcg_task
 
@@ -138,7 +138,7 @@ class Task(models.Model):
         attrs = get_attributes(qcg_task, ('task_id', 'status_description', 'note', 'description', 'submission_time',
                                           'start_time', 'finish_time', 'reserved_time_slot', 'purged'))
 
-        attrs['epr'] = str(qcg_task.epr)
+        attrs['epr'] = EPRUtils.serialize_epr(qcg_task.epr)
         attrs['status'] = Task.STATUS_CHOICES_REVERSED[qcg_task.status]
         attrs['type'] = Task.TYPE_CHOICES_REVERSED[qcg_task.type]
         attrs['proxy_lifetime'] = now() + qcg_task.proxy_lifetime
@@ -169,13 +169,17 @@ class Task(models.Model):
 
     @property
     def short_host_names(self):
-        return {alloc.host_name.split('.')[0] for alloc in self.allocations.all()}
+        return {alloc.host_name.split('.', 1)[0] for alloc in self.allocations.all()}
 
 
 class Allocation(models.Model):
+    STATUS_CHOICES = list(enumerate(field for field in dir(AllocationType) if not field.startswith('__')))
+    STATUS_CHOICES_REVERSED = {v: k for k, v in STATUS_CHOICES}
+
     task = models.ForeignKey(Task, verbose_name='Zadanie', related_name='allocations')
 
     host_name = models.CharField(u"Host", max_length=100)
+    status = models.IntegerField(u"Status", choices=STATUS_CHOICES)
     status_description = models.TextField(u"Opis statusu", blank=True, default='')
     processes_count = models.PositiveIntegerField(u"Liczba procesów")
     slots_count = models.PositiveIntegerField(u"Liczba rdzeni")
@@ -201,10 +205,14 @@ class Allocation(models.Model):
 
     @staticmethod
     def qcg_map(qcg_allocation):
-        return get_attributes(qcg_allocation, ('host_name', 'status_description', 'processes_count', 'slots_count',
-                                               'processes_group_id', 'submission_time', 'estimated_start_time',
-                                               'finish_time', 'local_submission_time', 'local_start_time',
-                                               'local_finish_time', 'purged', 'efficiency', 'comment', 'memory_usage'))
+        attrs = get_attributes(qcg_allocation, ('host_name', 'status_description', 'processes_count', 'slots_count',
+                                                'processes_group_id', 'submission_time', 'estimated_start_time',
+                                                'finish_time', 'local_submission_time', 'local_start_time',
+                                                'local_finish_time', 'purged', 'efficiency', 'comment', 'memory_usage'))
+
+        attrs['status'] = Allocation.STATUS_CHOICES_REVERSED[qcg_allocation.status]
+
+        return attrs
 
 
 class NodeInfo(models.Model):
index c1278e3..e9255d4 100644 (file)
@@ -41,6 +41,7 @@
                     <ul class="list-group">
                         {% for alloc in task.allocations.all %}
                             <li class="list-group-item">
+                                {% display_attribute 'Status' alloc.get_status_display %}
                                 {% display_attribute 'Komentarz' alloc.comment %}
                                 {% display_attribute 'Host' alloc.host_name %}
                                 {% display_attribute 'Opis statusu' alloc.status_description %}