Login

Dropbox Chooser Form Widget

Author:
tcfitzgerald
Posted:
August 20, 2013
Language:
Python
Version:
1.3
Tags:
form widget dropbox chooser
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. Select or Create widget by Naster 1 year, 2 months ago
  2. Field value as plain text which can't be edited by user by szczavv 5 years, 7 months ago
  3. Custom CheckboxSelectMultiple by martync 5 years, 6 months ago
  4. autocompleter with database query by bbolli 7 years, 10 months ago
  5. Form widget for text inputs with external link. version2 by ramusus 5 years, 11 months ago

Comments

Please login first before commenting.