Implement GridFS storage user settings

This commit is contained in:
Roberto Rosario
2011-03-04 06:16:00 -04:00
parent 30c6292630
commit a7eee1b192
6 changed files with 19 additions and 10 deletions

View File

@@ -6,22 +6,19 @@ from django.utils.encoding import force_unicode
from pymongo import Connection from pymongo import Connection
from gridfs import GridFS from gridfs import GridFS
HOST = u'localhost'
PORT = 27017
DATABASE_NAME = u'document_storage'
#TODO: Implement user settings from storage.conf import settings
#TODO: Implement delete-open soft locking
#TODO :master_slave_connection
class GridFSStorage(Storage): class GridFSStorage(Storage):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.db = Connection(host=HOST, port=PORT)[DATABASE_NAME] self.db = Connection(host=settings.GRIDFS_HOST,
port=settings.GRIDFS_PORT)[settings.DATABASE_NAME]
self.fs = GridFS(self.db) self.fs = GridFS(self.db)
def save(self, name, content): def save(self, name, content):
#TODO: if exists adding _ plus a counter #TODO: if exists add _ plus a counter
while True: while True:
try: try:
# This file has a file path that we can move. # This file has a file path that we can move.

View File

View File

@@ -0,0 +1,6 @@
from django.conf import settings
GRIDFS_HOST = getattr(settings, 'STORAGE_GRIDFS_HOST', 'localhost')
GRIDFS_PORT = getattr(settings, 'STORAGE_GRIDFS_PORT', 27017)
DATABASE_NAME = getattr(settings, 'STORAGE_GRIDFS_DATABASE_NAME', u'document_storage')

View File

@@ -52,3 +52,4 @@
2011-Mar 04 2011-Mar 04
* Initial GridFS storage support * Initial GridFS storage support
* Implemented size and delete methods for GridFS * Implemented size and delete methods for GridFS
* Implement GridFS storage user settings

View File

@@ -90,12 +90,13 @@ TODO, WISHLIST
* Show current page in generic list template * Show current page in generic list template
* Advanced search by metadata fields * Advanced search by metadata fields
* Save advanced search by metadata setup as a virtual folder * Save advanced search by metadata setup as a virtual folder
* Avoid metadata indexing folders name clash
GridFSStorage GridFSStorage
============ ============
* Implement user settings * Implement user settings - DONE
* Implement delete-open soft locking * Implement delete-open soft locking - DEFERRED
* Implement master_slave_connection * Implement master_slave_connection
* if exists adding _ plus a counter - avoid file versioning * if exists adding _ plus a counter - avoid file versioning

View File

@@ -195,6 +195,10 @@ LOGIN_EXEMPT_URLS = (
# Storage # Storage
#DOCUMENTS_STORAGE_BACKEND = FileBasedStorage #DOCUMENTS_STORAGE_BACKEND = FileBasedStorage
# Storage - GridFS settings
#STORAGE_GRIDFS_HOST = 'localhost' # or list ['host a', 'host b']
#STORAGE_GRIDFS_PORT = 27017
#STORAGE_GRIDFS_DATABASE_NAME = u'document_storage'
# Usage # Usage
#DOCUMENTS_PREVIEW_SIZE = '640x480' #DOCUMENTS_PREVIEW_SIZE = '640x480'