Skip to main content

UNKNOWN

Project description

djcroco extends your Django model to add support for the Crocodoc API.

Installation

To install djcroco, simply:

pip install djcroco

Add to your INSTALLED_APPS:

...
'djcroco',
...

Include urls in your urls.py:

url(r'', include('djcroco.urls')),

Define Crocodoc API token and the model you want to extend, in your settings.py:

CROCO_MODEL = 'app_name.model_name'
CROCO_API_TOKEN = '<api_token>'

Usage

Define the model you wish to extend:

from django.db import models

from djcroco.models import CrocoModel


class Example(CrocoModel):
    name = models.CharField(max_length=255)
    file = models.FileField(upload_to='examples/')
    thumbnail = models.ImageField(upload_to='examples/thumbnails/', blank=True,
        null=True, editable=False)

    def __unicode__(self):
        return self.name

Note the below:

  • CrocoModel is an abstract model. More info about abstract models.

  • Your model must contain the above fields of file and thumbnail, and exactly the same field instances as in the example.

How it works:

  • Every time you save your model, the djcroco uploads document to Crocodoc to start conversion process. Only supported documents are uploaded. List of supported documents.

  • When the template renders, the get_thumbnail method creates a thumbnail to display in your app.

  • The get_absolute_view_url creates a viewing session on Crocodoc so you can embed the document in your app. It returns only an URL so it is up to you how you use it.

Render the awesomeness in your template:

<ul>
{% for obj in object_list %}
    <li>Name: {{ obj.name }}</li>
    <li>Size: {{ obj.human_file_size }}</li>
    <li>Extension: {{ obj.file_ext }}</li>
    <li><img src="{{ obj.get_thumbnail }}"></li>

    {% if obj.is_viewable %}
    <li><a href="{{ obj.get_absolute_view_url }}">View</a></li>
    {% endif %}

    {% if obj.is_downloadable %}
    <li><a href="{{ obj.get_absolute_download_url }}">Download</a></li>
    {% endif %}
{% endfor %}
</ul>

Dependencies

djcroco depends only on crocodoc-python in order to communicate with Crocodoc API service.

Limitations

djcroco was tested on Django 1.4/Python 2.7.3. Other versions of Django/Python will be supported soon.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djcroco-0.1.tar.gz (4.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page