adding notes app with Note model and adding taggit tagging manager
[oweals/karmaworld.git] / karmaworld / apps / notes / models.py
1 #!/usr/bin/python2.7
2 # -*- coding:utf8 -*-
3 # Copyright (C) 2012  FinalsClub Foundation
4
5 """
6     Models for the notes django app.
7     Contains only the minimum for handling files and their representation
8 """
9 import datetime
10 import os
11
12 from django.db import models
13 from taggit.managers import TaggableManager
14
15 class Note(models.Model):
16     """ A django model representing an uploaded file and associated metadata.
17     """
18     FILE_TYPE_CHOICES = (
19         ('doc', 'MS Word compatible file (.doc, .docx, .rtf, .odf)'),
20         ('img', 'Scan or picture of notes'),
21         ('pdf', 'PDF file'),
22         ('???', 'Unknown file'),
23     )
24
25     # Tagging system
26     tags            = TaggableManager()
27
28     name            = models.CharField(max_length=255, blank=True, null=True)
29     desc            = models.TextField(max_length=511, blank=True, null=True)
30     uploaded_at     = models.DateTimeField(null=True, default=datetime.datetime.utcnow)
31
32     file_type   = models.CharField(max_length=15, blank=True, null=True, choices=FILE_TYPE_CHOICES, default='???')
33     # Upload files to MEDIA_ROOT/notes/YEAR/MONTH/DAY, 2012/10/30/filename
34     note_file   = models.FileField(upload_to="notes/%Y/%m/%j/", blank=True, null=True)
35
36     ## post gdrive conversion data
37     embed_url   = models.URLField(max_length=1024, blank=True, null=True)
38     download_url = models.URLField(max_length=1024, blank=True, null=True)
39     # for word processor documents
40     html        = models.TextField(blank=True, null=True)
41     text        = models.TextField(blank=True, null=True)
42
43     # FIXME: Not Implemented
44     #uploader    = models.ForeignKey(User, blank=True, null=True, related_name='notes')
45     #course      = models.ForeignKey(Course, blank=True, null=True, related_name="files")
46     #school      = models.ForeignKey(School, blank=True, null=True)
47
48     def __unicode__(self):
49         return u"{0}: {1} -- {2}".format(self.file_type, self.name, self.uploaded_at)