Skip to content

Commit

Permalink
Merge pull request #1 from leonardoo/dev
Browse files Browse the repository at this point in the history
Update to django 1.7 and test
  • Loading branch information
leonardoo committed Mar 16, 2015
2 parents 8645648 + 9db4c36 commit ed0ac8b
Show file tree
Hide file tree
Showing 29 changed files with 382 additions and 264 deletions.
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.
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', '[email protected]'),
)

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

0 comments on commit ed0ac8b

Please sign in to comment.