Dropbox Chooser Form Widget

 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. Select or Create widget by Naster 1 month, 3 weeks ago
  2. Field value as plain text which can't be edited by user by szczavv 4 years, 6 months ago
  3. Custom CheckboxSelectMultiple by martync 4 years, 6 months ago
  4. autocompleter with database query by bbolli 6 years, 9 months ago
  5. Form widget for text inputs with external link. version2 by ramusus 4 years, 10 months ago

Comments

(Forgotten your password?)