3 # Copyright (C) 2012 FinalsClub Foundation
6 Models for the notes django app.
7 Contains only the minimum for handling files and their representation
12 from django.db import models
13 from taggit.managers import TaggableManager
15 class Note(models.Model):
16 """ A django model representing an uploaded file and associated metadata.
20 ('doc', 'MS Word compatible file (.doc, .docx, .rtf, .odf)'),
21 ('img', 'Scan or picture of notes'),
23 (UNKNOWN_FILE, 'Unknown file'),
27 tags = TaggableManager()
29 name = models.CharField(max_length=255, blank=True, null=True)
30 desc = models.TextField(max_length=511, blank=True, null=True)
31 uploaded_at = models.DateTimeField(null=True, default=datetime.datetime.utcnow)
33 file_type = models.CharField(max_length=15, blank=True, null=True, choices=FILE_TYPE_CHOICES, default=UNKNOWN_FILE)
34 # Upload files to MEDIA_ROOT/notes/YEAR/MONTH/DAY, 2012/10/30/filename
35 note_file = models.FileField(upload_to="notes/%Y/%m/%j/", blank=True, null=True)
37 ## post gdrive conversion data
38 embed_url = models.URLField(max_length=1024, blank=True, null=True)
39 download_url = models.URLField(max_length=1024, blank=True, null=True)
40 # for word processor documents
41 html = models.TextField(blank=True, null=True)
42 text = models.TextField(blank=True, null=True)
44 # FIXME: Not Implemented
45 #uploader = models.ForeignKey(User, blank=True, null=True, related_name='notes')
46 #course = models.ForeignKey(Course, blank=True, null=True, related_name="files")
47 #school = models.ForeignKey(School, blank=True, null=True)
49 def __unicode__(self):
50 return u"{0}: {1} -- {2}".format(self.file_type, self.name, self.uploaded_at)
52 def save(self, *args, **kwargs):
53 """ override built-in save to ensure contextual self.name """
54 # TODO: If self.name isn't set, generate one based on uploaded_name
55 # if we fail to set the Note.name earlier than this, use the saved filename
58 super(Note, self).save(*args, **kwargs)