From 908dbd228395265e0d1ccf94bcfda2800163f264 Mon Sep 17 00:00:00 2001 From: Seth Woodworth Date: Wed, 2 Jan 2013 19:16:20 -0500 Subject: [PATCH] adding notes app with Note model and adding taggit tagging manager --- karmaworld/apps/notes/__init__.py | 0 karmaworld/apps/notes/admin.py | 10 +++++++ karmaworld/apps/notes/models.py | 49 +++++++++++++++++++++++++++++++ karmaworld/settings/common.py | 17 +++++++++++ karmaworld/settings/dev.py | 2 +- reqs/common.txt | 1 + 6 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 karmaworld/apps/notes/__init__.py create mode 100644 karmaworld/apps/notes/admin.py create mode 100644 karmaworld/apps/notes/models.py diff --git a/karmaworld/apps/notes/__init__.py b/karmaworld/apps/notes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/karmaworld/apps/notes/admin.py b/karmaworld/apps/notes/admin.py new file mode 100644 index 0000000..ae49e66 --- /dev/null +++ b/karmaworld/apps/notes/admin.py @@ -0,0 +1,10 @@ +#!/usr/bin/python +# -*- coding:utf8 -*- +# Copyright (C) 2012 FinalsClub Foundation +""" Administration configuration for notes """ + +from django.contrib import admin + +import models + +admin.site.register(models.Note) diff --git a/karmaworld/apps/notes/models.py b/karmaworld/apps/notes/models.py new file mode 100644 index 0000000..ff468c6 --- /dev/null +++ b/karmaworld/apps/notes/models.py @@ -0,0 +1,49 @@ +#!/usr/bin/python2.7 +# -*- coding:utf8 -*- +# Copyright (C) 2012 FinalsClub Foundation + +""" + Models for the notes django app. + Contains only the minimum for handling files and their representation +""" +import datetime +import os + +from django.db import models +from taggit.managers import TaggableManager + +class Note(models.Model): + """ A django model representing an uploaded file and associated metadata. + """ + FILE_TYPE_CHOICES = ( + ('doc', 'MS Word compatible file (.doc, .docx, .rtf, .odf)'), + ('img', 'Scan or picture of notes'), + ('pdf', 'PDF file'), + ('???', 'Unknown file'), + ) + + # Tagging system + tags = TaggableManager() + + name = models.CharField(max_length=255, blank=True, null=True) + desc = models.TextField(max_length=511, blank=True, null=True) + uploaded_at = models.DateTimeField(null=True, default=datetime.datetime.utcnow) + + file_type = models.CharField(max_length=15, blank=True, null=True, choices=FILE_TYPE_CHOICES, default='???') + # Upload files to MEDIA_ROOT/notes/YEAR/MONTH/DAY, 2012/10/30/filename + note_file = models.FileField(upload_to="notes/%Y/%m/%j/", blank=True, null=True) + + ## post gdrive conversion data + embed_url = models.URLField(max_length=1024, blank=True, null=True) + download_url = models.URLField(max_length=1024, blank=True, null=True) + # for word processor documents + html = models.TextField(blank=True, null=True) + text = models.TextField(blank=True, null=True) + + # FIXME: Not Implemented + #uploader = models.ForeignKey(User, blank=True, null=True, related_name='notes') + #course = models.ForeignKey(Course, blank=True, null=True, related_name="files") + #school = models.ForeignKey(School, blank=True, null=True) + + def __unicode__(self): + return u"{0}: {1} -- {2}".format(self.file_type, self.name, self.uploaded_at) diff --git a/karmaworld/settings/common.py b/karmaworld/settings/common.py index 0aecfb4..cb03697 100644 --- a/karmaworld/settings/common.py +++ b/karmaworld/settings/common.py @@ -196,9 +196,14 @@ THIRD_PARTY_APPS = ( # Asynchronous task queue: 'djcelery', + + # Tagging https://github.com/yedpodtrzitko/django-taggit + 'taggit', ) LOCAL_APPS = ( + # file handling app + 'karmaworld.apps.notes', ) # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps @@ -257,3 +262,15 @@ COMPRESS_JS_FILTERS = [ 'compressor.filters.template.TemplateFilter', ] ########## END COMPRESSION CONFIGURATION + +########## TAGGIT CONFIGURATION +# From https://github.com/yedpodtrzitko/django-taggit + +# Use lowercase tags +TAGGIT_FORCE_LOWERCASE = True + +# Ignore common stopwords +TAGGIT_STOPWORDS = [u'a', u'an', u'and', u'be', u'from', u'of'] + +########## END TAGGIT CONFIGURATION + diff --git a/karmaworld/settings/dev.py b/karmaworld/settings/dev.py index 2fd3297..fdf6bbc 100644 --- a/karmaworld/settings/dev.py +++ b/karmaworld/settings/dev.py @@ -26,7 +26,7 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': normpath(join(DJANGO_ROOT, 'default.db')), + 'NAME': normpath(join(DJANGO_ROOT, 'karmaworld.db')), 'USER': '', 'PASSWORD': '', 'HOST': '', diff --git a/reqs/common.txt b/reqs/common.txt index 79a8f5b..7d5924b 100644 --- a/reqs/common.txt +++ b/reqs/common.txt @@ -4,3 +4,4 @@ django-compressor==1.2 Fabric==1.4.3 South==0.7.6 Sphinx==1.1.3 +git+git://github.com/yedpodtrzitko/django-taggit.git -- 2.25.1