-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from maxicecilia/master
Migrate to Dropbox API v2
- Loading branch information
Showing
11 changed files
with
103 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
from django.core.management.base import NoArgsCommand | ||
from dropbox import rest, session | ||
from django_dropbox.settings import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TYPE | ||
from django.core.management.base import NoArgsCommand, CommandError | ||
from dropbox import DropboxOAuth2FlowNoRedirect | ||
|
||
from django_dropbox.settings import CONSUMER_KEY, CONSUMER_SECRET | ||
|
||
|
||
class Command(NoArgsCommand): | ||
|
||
def handle_noargs(self, *args, **options): | ||
sess = session.DropboxSession(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TYPE) | ||
request_token = sess.obtain_request_token() | ||
auth_flow = DropboxOAuth2FlowNoRedirect(CONSUMER_KEY, CONSUMER_SECRET) | ||
|
||
url = sess.build_authorize_url(request_token) | ||
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) | ||
authorize_url = auth_flow.start() | ||
self.stdout.write('1. Go to: {}'.format(authorize_url)) | ||
self.stdout.write('2. Click "Allow" (you might have to log in first).') | ||
self.stdout.write('3. Copy the authorization code.') | ||
auth_code = raw_input("Enter the authorization code here: ").strip() | ||
|
||
print "DROPBOX_ACCESS_TOKEN = '%s'" % access_token.key | ||
print "DROPBOX_ACCESS_TOKEN_SECRET = '%s'" % access_token.secret | ||
try: | ||
oauth_result = auth_flow.finish(auth_code) | ||
self.stdout.write("DROPBOX_ACCESS_TOKEN = '{}'".format(oauth_result.access_token)) | ||
except Exception as e: | ||
raise CommandError('Error: {}'.format(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
from django.contrib import admin | ||
from dropbox_testing.models import Person | ||
|
||
|
||
class PersonAdmin(admin.ModelAdmin): | ||
list_display = ('image',) | ||
|
||
def image(self, obj): | ||
if obj.photo: | ||
return '<img src="%s">' % obj.photo.url | ||
return '' | ||
image.allow_tags = True | ||
|
||
admin.site.register(Person, PersonAdmin) | ||
admin.site.register(Person, PersonAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
#!/usr/bin/env python | ||
from django.core.management import execute_manager | ||
import imp | ||
try: | ||
imp.find_module('settings') # Assumed to be in the same directory. | ||
except ImportError: | ||
import sys | ||
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__) | ||
sys.exit(1) | ||
import os | ||
import sys | ||
|
||
import settings | ||
|
||
if __name__ == "__main__": | ||
execute_manager(settings) | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") | ||
from django.core.management import execute_from_command_line | ||
execute_from_command_line(sys.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
dropbox>=2.0.0 | ||
dropbox>=7.3.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
from django_dropbox import version | ||
from setuptools import setup | ||
|
||
|
||
def get_packages(): | ||
# setuptools can't do the job :( | ||
packages = [] | ||
|
@@ -12,14 +13,13 @@ def get_packages(): | |
|
||
return packages | ||
|
||
requires = ['dropbox>=2.0.0'] | ||
requires = ['dropbox==7.3.1'] | ||
|
||
setup(name='django-dropbox', | ||
version=version, | ||
description='A Django App that contains a Django Storage which uses Dropbox.', | ||
author=u'Andres Torres Marroquin', | ||
author_email='[email protected]', | ||
url='https://github.com/andres-torres-marroquin/django-dropbox', | ||
packages=get_packages(), | ||
install_requires=requires, | ||
) | ||
version=version, | ||
description='A Django App that contains a Django Storage which uses Dropbox.', | ||
author=u'Andres Torres Marroquin', | ||
author_email='[email protected]', | ||
url='https://github.com/andres-torres-marroquin/django-dropbox', | ||
packages=get_packages(), | ||
install_requires=requires,) |