summaryrefslogtreecommitdiffstats
path: root/welco/qualif/models.py
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2015-10-09 12:01:59 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2015-10-10 16:24:21 (GMT)
commit30e1c9cc4326d5256a006ebe7be895f1725a6cb3 (patch)
tree6a16525cc702cfe6a46480313d90931ed62039be /welco/qualif/models.py
parentd9100fabacb4faf5fc42e77b4dc37a77c31a668b (diff)
downloadwelco-30e1c9cc4326d5256a006ebe7be895f1725a6cb3.zip
welco-30e1c9cc4326d5256a006ebe7be895f1725a6cb3.tar.gz
welco-30e1c9cc4326d5256a006ebe7be895f1725a6cb3.tar.bz2
general: reorganize models in a simpler way
A source object (e.g. Mail) may now be attached to several Association objects, each one has a formdef_reference attribute (at first), and a formdata_id attribute (once submitted to wcs).
Diffstat (limited to 'welco/qualif/models.py')
-rw-r--r--welco/qualif/models.py55
1 files changed, 14 insertions, 41 deletions
diff --git a/welco/qualif/models.py b/welco/qualif/models.py
index 5373314..ecd3c37 100644
--- a/welco/qualif/models.py
+++ b/welco/qualif/models.py
@@ -24,57 +24,30 @@ from django.utils.translation import ugettext_lazy as _
from welco.utils import get_wcs_formdef_details, push_wcs_formdata, get_wcs_services
-class FormdefReference(models.Model):
- reference = models.CharField(max_length=250)
-
- @property
- def name(self):
- return get_wcs_formdef_details(self.reference).get('title')
-
-
-class FormdataReference(models.Model):
- reference = models.CharField(max_length=250)
-
- def formdef(self):
- return FormdefReference.objects.get(
- reference=self.reference.rsplit(':', 1)[0])
-
- @property
- def url(self):
- site, formdef, formdata = self.reference.split(':')
- wcs_site = get_wcs_services().get(site)
- return '%s%s/%s' % (wcs_site.get('url'), formdef, formdata)
-
-
class Association(models.Model):
source_type = models.ForeignKey(ContentType)
source_pk = models.PositiveIntegerField()
source = generic.GenericForeignKey('source_type', 'source_pk')
- triaged = models.BooleanField(default=False)
comments = models.TextField(blank=True, verbose_name=_('Comments'))
- user_id = models.CharField(max_length=50, null=True)
-
- formdefs = models.ManyToManyField(FormdefReference)
- formdatas = models.ManyToManyField(FormdataReference)
+ formdef_reference = models.CharField(max_length=250, null=True)
+ formdata_id = models.CharField(max_length=250, null=True)
def push(self, request, context):
# push validated request to wcs
if context:
context = context.copy()
context['user_id'] = self.user_id
- for formdef in self.formdefs.all():
- formdata_id = push_wcs_formdata(request, formdef.reference, context)
- reference = '%s:%s' % (formdef.reference, formdata_id)
- formdata_reference = FormdataReference(reference=reference)
- formdata_reference.save()
- self.formdatas.add(formdata_reference)
- self.save()
+ if self.formdef_reference:
+ self.formdata_id = push_wcs_formdata(request, self.formdef_reference, context)
+ self.save()
-@receiver(post_save)
-def association_triaged(sender, instance, **kwargs):
- if not sender is Association:
- return
- if instance.source.triaged != instance.triaged:
- instance.source.triaged = instance.triaged
- instance.source.save()
+ @property
+ def formdef_name(self):
+ return get_wcs_formdef_details(self.formdef_reference).get('title')
+
+ @property
+ def formdata_url(self):
+ site, formdef = self.formdef_reference.split(':')
+ wcs_site = get_wcs_services().get(site)
+ return '%s%s/%s' % (wcs_site.get('url'), formdef, self.formdata_id)