From 1c1398e68052d7e604af91c63e0dadba4658bc1e Mon Sep 17 00:00:00 2001 From: Seth Woodworth Date: Wed, 28 Aug 2013 16:16:49 -0400 Subject: [PATCH] add polymorphism to RawDocument and super() save to register a celery task --- karmaworld/apps/document_upload/models.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/karmaworld/apps/document_upload/models.py b/karmaworld/apps/document_upload/models.py index cb22d67..766698e 100644 --- a/karmaworld/apps/document_upload/models.py +++ b/karmaworld/apps/document_upload/models.py @@ -8,11 +8,13 @@ from django.db import models import django_filepicker from karmaworld.apps.notes.models import Document +from karmaworld.apps.notes.models import Note +from karmaworld.apps.document_upload import tasks + class RawDocument(Document): is_processed = models.BooleanField(default=False) - class Meta: """ Sort files most recent first """ ordering = ['-uploaded_at'] @@ -23,4 +25,19 @@ class RawDocument(Document): def convert_to_note(self): """ polymorph this object into a note.models.Note object """ - pass + note = Note( + course=self.course, + name=self.name, + slug=self.slug, + ip=self.ip, + uploaded_at=self.uploaded_at, + fp_file=self.fp_file) + note.save() + for tag in self.tags.all(): + note.tags.add(tag) + return note + + def save(self, *args, **kwargs): + if not is_processed: + tasks.process_raw_document(self) + super(RawDocument, self).save(*args, **kwargs) -- 2.25.1