Login

Dropbox Chooser Form Widget

Author:
tcfitzgerald
Posted:
August 20, 2013
Language:
Python
Version:
1.3
Score:
0 (after 0 ratings)

Widget to place a Dropbox Chooser button on a form. Replace data-app-key value with your Dropbox Chooser app key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
I use this to place a direct link to a file on Dropbox into a Charfield, which is then queued up to be downloaded.
You could also change the 'data-link-type' to 'preview' to link to the Dropbox preview page for the chosen file.

file = CharField(widget=DropboxChooser())

You can read more about the Dropbox Chooser dropin here: 
    https://www.dropbox.com/developers/dropins/chooser/
"""


from django import forms

class DropboxTextInput(DropboxInput, forms.TextInput):
    input_type = 'dropbox-chooser'


class DropboxChooser(DropboxTextInput):

    def __init__(self, attrs=None):
        default_attrs = {'data-link-type': 'direct', 'style': 'visibility: hidden;'}

        if attrs:
            default_attrs.update(attrs)

        super(DropboxChooser, self).__init__(default_attrs)

    def render(self, name, value, attrs=None):
        html = super(DropboxChooser, self).render(name, value, attrs)

        final_attrs = self.build_attrs(attrs, name=name)

        html += """
            <script type="text/javascript" src="https://www.dropbox.com/static/api/1/dropins.js" id="dropboxjs" data-app-key="123456789"></script>
        """

        return mark_safe(html)

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
  5. Help text hyperlinks by sa2812 1 year, 6 months ago

Comments

Please login first before commenting.