First commit of new multiple document source app

This commit is contained in:
Roberto Rosario
2011-07-05 19:34:05 -04:00
parent 9968492ee9
commit 7417fca835
6 changed files with 155 additions and 0 deletions

0
apps/sources/__init__.py Normal file
View File

8
apps/sources/admin.py Normal file
View File

@@ -0,0 +1,8 @@
from django.contrib import admin
from sources.models import StagingFolder, WebForm
admin.site.register(StagingFolder)
admin.site.register(WebForm)

122
apps/sources/models.py Normal file
View File

@@ -0,0 +1,122 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from documents.models import DocumentType
from metadata.models import MetadataType
SOURCE_UMCOMPRESS_CHOICE_Y = 'y'
SOURCE_UMCOMPRESS_CHOICE_N = 'n'
SOURCE_UMCOMPRESS_CHOICE_ASK = 'a'
SOURCE_UNCOMPRESS_CHOICES = (
(SOURCE_UMCOMPRESS_CHOICE_Y, _(u'Yes')),
(SOURCE_UMCOMPRESS_CHOICE_N, _(u'No')),
)
SOURCE_INTERACTIVE_UNCOMPRESS_CHOICES = (
(SOURCE_UMCOMPRESS_CHOICE_Y, _(u'Yes')),
(SOURCE_UMCOMPRESS_CHOICE_N, _(u'No')),
(SOURCE_UMCOMPRESS_CHOICE_ASK, _(u'Ask'))
)
SOURCE_ICON_DISK = 'disk'
SOURCE_ICON_DATABASE = 'database'
SOURCE_ICON_DRIVE = 'drive'
SOURCE_ICON_DRIVE_NETWORK = 'drive_network'
SOURCE_ICON_DRIVE_USER = 'drive_user'
SOURCE_ICON_EMAIL = 'email'
SOURCE_ICON_FOLDER = 'folder'
SOURCE_ICON_WORLD = 'world'
SOURCE_ICON_CHOICES = (
(SOURCE_ICON_DISK, _(u'disk')),
(SOURCE_ICON_DATABASE, _(u'database')),
(SOURCE_ICON_DRIVE, _(u'drive')),
(SOURCE_ICON_DRIVE_NETWORK, _(u'network drive')),
(SOURCE_ICON_DRIVE_USER, _(u'user drive')),
(SOURCE_ICON_EMAIL, _(u'envelope')),
(SOURCE_ICON_FOLDER, _(u'folder')),
(SOURCE_ICON_WORLD, _(u'world'))
)
SOURCE_CHOICE_WEB_FORM = 'wform'
SOURCE_CHOICE_STAGING = 'stagn'
SOURCE_CHOICES = (
(SOURCE_CHOICE_WEB_FORM, _(u'Web form')),
(SOURCE_CHOICE_STAGING, _(u'Server staging folder')),
)
class BaseModel(models.Model):
title = models.CharField(max_length=64, verbose_name=_(u'title'))
enabled = models.BooleanField(default=True, verbose_name=_(u'enabled'))
whitelist = models.TextField(blank=True, verbose_name=_(u'whitelist'))
blacklist = models.TextField(blank=True, verbose_name=_(u'blacklist'))
document_type = models.ForeignKey(DocumentType, blank=True, null=True, verbose_name=_(u'document type'))
# M2M
# Default Metadata sets
# Default Metadata types & default values
def __unicode__(self):
return u'%s (%s)' % (self.title, dict(SOURCE_CHOICES).get(self.source_type))
class Meta:
ordering = ['title']
abstract = True
#class MetadataValue(models.Model):
# source = models.ForeignKey(BaseModel, verbose_name=_(u'document source'))
# metadata_type = models.ForeignKey(MetadataType, verbose_name=_(u'metadata type'))
# value = models.CharField(max_length=256, blank=True, verbose_name=_(u'value'))
#
# def __unicode__(self):
# return self.source
#
# class Meta:
# verbose_name = _(u'source metadata')
# verbose_name_plural = _(u'sources metadata')
class InteractiveBaseModel(BaseModel):
icon = models.CharField(blank=True, null=True, max_length=24, choices=SOURCE_ICON_CHOICES, verbose_name=_(u'icon'))
def save(self, *args, **kwargs):
if not self.icon:
self.icon = self.default_icon
super(BaseModel, self).save(*args, **kwargs)
class Meta:
abstract = True
class StagingFolder(InteractiveBaseModel):
is_interactive = True
source_type = SOURCE_CHOICE_STAGING
default_icon = SOURCE_ICON_DRIVE
folder_path = models.CharField(max_length=255, verbose_name=_(u'folder path'))
preview_width = models.IntegerField(verbose_name=_(u'preview width'))
preview_height = models.IntegerField(blank=True, null=True, verbose_name=_(u'preview height'))
uncompress = models.CharField(max_length=1, choices=SOURCE_INTERACTIVE_UNCOMPRESS_CHOICES, verbose_name=_(u'uncompress'))
delete_after_upload = models.BooleanField(default=True, verbose_name=_(u'delete after upload'))
class Meta:
verbose_name = _(u'staging folder')
verbose_name_plural = _(u'staging folder')
class WebForm(InteractiveBaseModel):
is_interactive = True
source_type = SOURCE_CHOICE_WEB_FORM
default_icon = SOURCE_ICON_DISK
uncompress = models.CharField(max_length=1, choices=SOURCE_INTERACTIVE_UNCOMPRESS_CHOICES, verbose_name=_(u'uncompress'))
#Default path
class Meta:
verbose_name = _(u'web form')
verbose_name_plural = _(u'web forms')

23
apps/sources/tests.py Normal file
View File

@@ -0,0 +1,23 @@
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.failUnlessEqual(1 + 1, 2)
__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}

1
apps/sources/views.py Normal file
View File

@@ -0,0 +1 @@
# Create your views here.

View File

@@ -149,6 +149,7 @@ INSTALLED_APPS = (
'grouping',
'mptt',
'document_indexing',
'sources',
)
TEMPLATE_CONTEXT_PROCESSORS = (