Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
36b402f
add testing
leonardoo Dec 29, 2014
60941ec
valid travis
leonardoo Dec 29, 2014
be88fe4
mistake :P
leonardoo Dec 29, 2014
5435704
second mistake D:
leonardoo Dec 29, 2014
20c1840
new settings
leonardoo Dec 29, 2014
4caaba3
settings
leonardoo Dec 29, 2014
83daca6
settings2
leonardoo Dec 29, 2014
a20bcb8
mistakes
leonardoo Dec 29, 2014
c00ae77
remove test for py2.6
leonardoo Dec 29, 2014
ae18bb1
remote test for py 2.6
leonardoo Dec 29, 2014
2916f3e
let django manage files with ContentFile
leonardoo Dec 29, 2014
b7ff090
compat
leonardoo Dec 29, 2014
b4e854a
conver indent to spaces
leonardoo Dec 29, 2014
b087a73
fix
leonardoo Dec 29, 2014
0a41caf
fix2
leonardoo Dec 29, 2014
996c6b3
import force_bytes
leonardoo Dec 29, 2014
ce164fc
test for delete
leonardoo Dec 29, 2014
50a80c4
not force_bytes
leonardoo Dec 29, 2014
eb134bd
remove force_bytes
leonardoo Dec 29, 2014
4441189
sinx
leonardoo Dec 29, 2014
3887b50
compat django 1.7 and demo
leonardoo Mar 15, 2015
f307af6
demo config and new version
leonardoo Mar 15, 2015
9d0230f
fix setup and add env to gitignore
leonardoo Mar 15, 2015
73ece26
update requeriments
leonardoo Mar 15, 2015
6905e20
test valid for models
leonardoo Mar 15, 2015
055b3bd
fix error when use str() in the model change by model.__str__()
leonardoo Mar 15, 2015
938f90b
force to text file name in model
leonardoo Mar 15, 2015
ef6a8d5
for text to be a bytestring in py3
leonardoo Mar 16, 2015
90cff9b
change in setup
leonardoo Mar 16, 2015
9db4c36
better explanation about install and configure the app
leonardoo Mar 16, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.pyc
django_dropbox.egg-info/
dist/
env/
venv/
bin/
lib/
Expand Down
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: python
python: 2.7
env:
matrix:
- TOX_ENV=py27-django14
- TOX_ENV=py27-django15
- TOX_ENV=py27-django16
- TOX_ENV=py27-django17
- TOX_ENV=py34-django15
- TOX_ENV=py34-django16
- TOX_ENV=py34-django17
- TOX_ENV=coverage
global:
- secure: ZdqsHM92b1pPklUT6S4j7mbnIQINOE5+QKOFoXqgq/N4lDHX8XvHywWDfn6iigr0R9Nj9F5RmzPB/EyaSbPb/RM14y1BlHPL4Jqwu83+JAyS6QxZqt1cAgrnG++rpJCnTT6tZTsiXgyWo6RCxMTQFAXQsvye6br0w5rLxP7Ymyg=
- secure: XLLNIUgl5VsSy1w6i34z0Vo2NHRQcX9e8TS4Mg4Iq1fDT9WjLGG8tN2Nu4CFzrOK6PjCBFMTHgt88UJiQ45dxAzIFl+ApysqB+E2Z42r3HggiDn2iHfu8S/csSxgcFoI5qjyqeW3tDEOZfxtMZ18hqAPVFBlZ7QwmSSl7TeHb8k=
- secure: ULa2n0dqO1/Vf8QpBXVz47XQ963LXEvD59/TmoxXffusMV47aASSv4j+kXU2+RwvzTDWO5k1afd5esebwGUiv78l/x5Ta4QiDpX6uxxPTQk/CGHEuUTMru7d/CYf3xPAB5Vu/mexaPHmPAT4sO3I9Sef6LIsFSNsXp/LkmbT3NQ=
- secure: gXWm2BJJ7FoGMc09uzPUMpEeFCJMQE3awvJ9nnx6n1I4D7GZPyE7Ukm+o4o8DsjO/nBQzAqkMNJi4J2E4H0FvHnLHif8ktE0JATf3jYAHhOZO4NaY5aikSliMvH2a+JkfNZsUbUbq8zzcZMpyNX2O4N0cIZc9tplQznHD8RMrJU=
install:
- pip install tox
script:
- tox -e $TOX_ENV
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# django-dropbox
> Version 0.0.1
> Version 0.0.5

# What

Expand Down Expand Up @@ -28,6 +28,8 @@ additionally you must need to set the next settings:
DROPBOX_ACCESS_TOKEN = 'xxx'
DROPBOX_ACCESS_TOKEN_SECRET = 'xxx'

ACCESS_TYPE = 'app_folder'

if you don't have `DROPBOX_CONSUMER_KEY` or `DROPBOX_CONSUMER_SECRET`
you will need to create an Dropbox app at [Dropbox for Developers](https://www.dropbox.com/developers)
then set `DROPBOX_CONSUMER_KEY` and `DROPBOX_CONSUMER_SECRET` settings in `settings.py`,
Expand All @@ -36,3 +38,22 @@ after that run:
$ python manage.py get_dropbox_token

And follow up on screen instructions, finally set the `DROPBOX_ACCESS_TOKEN` and `DROPBOX_ACCESS_TOKEN_SECRET` in `settings.py`


# Config in app

for use in your app project in the models, you have to add

from django_dropbox.storage import DropboxStorage

STORAGE = DropboxStorage()

and in the fields like

file_1 = models.FileField(upload_to="pathtoupload",storage=STORAGE)

or

logo = models.ImageField(upload_to='pathtoupload', storage=STORAGE)


17 changes: 13 additions & 4 deletions django_dropbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
VERSION = (0, 0, 4)
"""
Django accounts management made easy.

def get_version():
return '%s.%s.%s' % VERSION
"""
default_app_config = 'django_dropbox.apps.DjangoDropboxConfig'

VERSION = (0, 0, 5)

version = get_version()
__version__ = '.'.join((str(each) for each in VERSION[:4]))

def get_version():
"""
Returns string with digit parts only as version.
"""
return '.'.join((str(each) for each in VERSION[:3]))
6 changes: 6 additions & 0 deletions django_dropbox/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class DjangoDropboxConfig(AppConfig):
name = 'django_dropbox'
verbose_name = 'Django Dropbox'
21 changes: 21 additions & 0 deletions django_dropbox/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

from io import BytesIO, StringIO

from django.utils import six
from django.utils.six.moves.urllib import parse as urlparse

try:
from django.utils.deconstruct import deconstructible
except ImportError: # Django 1.7+ migrations
deconstructible = lambda klass, *args, **kwargs: klass


def getFile(content=None):
if not content:
return BytesIO()

if six.PY3:
stream_class = StringIO if isinstance(content, six.text_type) else BytesIO
else:
stream_class = BytesIO
return stream_class(content)
9 changes: 5 additions & 4 deletions django_dropbox/management/commands/get_dropbox_token.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
from django.core.management.base import NoArgsCommand
from dropbox import rest, session
from django_dropbox.settings import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TYPE
Expand All @@ -9,12 +10,12 @@ def handle_noargs(self, *args, **options):
request_token = sess.obtain_request_token()

url = sess.build_authorize_url(request_token)
print "Url:", url
print "Please visit this website and press the 'Allow' button, then hit 'Enter' here."
print("Url:", url)
print("Please visit this website and press the 'Allow' button, then hit 'Enter' here.")
raw_input()

# This will fail if the user didn't visit the above URL and hit 'Allow'
access_token = sess.obtain_access_token(request_token)

print "DROPBOX_ACCESS_TOKEN = '%s'" % access_token.key
print "DROPBOX_ACCESS_TOKEN_SECRET = '%s'" % access_token.secret
print("DROPBOX_ACCESS_TOKEN = '%s'" % access_token.key)
print("DROPBOX_ACCESS_TOKEN_SECRET = '%s'" % access_token.secret)
File renamed without changes.
24 changes: 24 additions & 0 deletions django_dropbox/runtests/dbtest/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import django_dropbox.storage


class Migration(migrations.Migration):

dependencies = [
]

operations = [
migrations.CreateModel(
name='TestDropbox',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('file_test', models.FileField(storage=django_dropbox.storage.DropboxStorage(location=b'/test/djangodropbox'), null=True, upload_to=b'.')),
],
options={
},
bases=(models.Model,),
),
]
File renamed without changes.
19 changes: 19 additions & 0 deletions django_dropbox/runtests/dbtest/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django_dropbox.storage import DropboxStorage
from django.utils.encoding import force_text


STORAGE = DropboxStorage(location="/test/djangodropbox")


@python_2_unicode_compatible
class TestDropbox(models.Model):
"""
Model for test django-dropbox storage
"""
file_test = models.FileField(upload_to=".",storage = STORAGE, null=True)

def __str__(self):
return os.path.basename(self.file_test.name)
4 changes: 4 additions & 0 deletions django_dropbox/runtests/dbtest/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import django

if django.VERSION < (1, 6):
from .test_models import *
20 changes: 20 additions & 0 deletions django_dropbox/runtests/dbtest/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.core.files.base import ContentFile
from django.test import TestCase
from django_dropbox.storage import DropboxStorage
from django.utils import six
from django_dropbox.runtests.dbtest.models import TestDropbox

class DropboxStorageTest(TestCase):

def setUp(self):
self.file_name = "test.txt"
self.file_content = six.b("this is a test")

def test_file_create_in_model(self):
"""
File must be create in model.
"""
model = TestDropbox()
model.file_test.save(self.file_name, ContentFile(self.file_content))
self.assertEqual(model.__str__(),self.file_name)
model.file_test.delete()
22 changes: 22 additions & 0 deletions django_dropbox/runtests/runtests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'django_dropbox.runtests.test_settings'

import django
from django.conf import settings
from django.test.utils import get_runner

if __name__ == "__main__":
if django.VERSION >= (1, 7, 0):
# starting from 1.7.0 we need to run setup() in order to populate
# app config
django.setup()
if not settings.configured:
settings.configure(myapp_defaults, DEBUG=True)

TestRunner = get_runner(settings)
test_runner = TestRunner()
failures = test_runner.run_tests(["django_dropbox"])
sys.exit(failures)
122 changes: 122 additions & 0 deletions django_dropbox/runtests/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import os
import sys

import django

DEBUG = True
TEMPLATE_DEBUG = DEBUG

settings_dir = os.path.dirname(__file__)
PROJECT_ROOT = os.path.abspath(settings_dir)

ADMINS = (
# ('Your Name', 'your_email@example.com'),
)

MANAGERS = ADMINS

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(PROJECT_ROOT, 'development.db'),
}
}

# Internationalization
TIME_ZONE = 'America/Chicago'
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True


# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = '12345'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.locale.LocaleMiddleware',
)

#ROOT_URLCONF = 'urls'
#WSGI_APPLICATION = 'demo.wsgi.application'

#TEMPLATE_DIRS = (
# os.path.join(PROJECT_ROOT, 'templates/'),
#)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
"django_dropbox",
"django_dropbox.runtests.dbtest",
)

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}

# Needed for Storage

DROPBOX_CONSUMER_KEY = '9lyr7cjqblxb2kv'
DROPBOX_CONSUMER_SECRET = '4saauuu6alx0iiz'
DROPBOX_ACCESS_TOKEN = 'vkf07symi6iadqba'
DROPBOX_ACCESS_TOKEN_SECRET = 'rz32iqtxsrfuwko'
#DROPBOX_CONSUMER_KEY = os.environ['DROPBOX_CONSUMER_KEY']
#DROPBOX_CONSUMER_SECRET = os.environ['DROPBOX_CONSUMER_SECRET']
#DROPBOX_ACCESS_TOKEN = os.environ['DROPBOX_ACCESS_TOKEN']
#DROPBOX_ACCESS_TOKEN_SECRET = os.environ['DROPBOX_ACCESS_TOKEN_SECRET']
ACCESS_TYPE = 'app_folder'
Loading