From: Seth Woodworth Date: Wed, 28 Aug 2013 20:16:49 +0000 (-0400) Subject: add polymorphism to RawDocument and super() save to register a celery task X-Git-Tag: release-20150131~386^2~107 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=1c1398e68052d7e604af91c63e0dadba4658bc1e;p=oweals%2Fkarmaworld.git add polymorphism to RawDocument and super() save to register a celery task --- 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)