UNKNOWN
Project description
djcroco is a custom Django model field to add support for the Crocodoc API.
It behaves like standard FileField so you can still use most of its properties (e.g. name, size, url etc) while having extra ones to play with Crocodoc API.
djcroco is supported by Incuna (an awesome company I work for!).
Installation
To install djcroco, simply run:
pip install djcroco
Include in urls.py:
url(r'', include('djcroco.urls')),
Define Crocodoc API token in settings.py:
CROCO_API_TOKEN = '<api_token>'
Or alternatively as env variable:
export CROCO_API_TOKEN='<api_token>'
Usage
Define the field in model you wish to extend:
from django.db import models from djcroco.fields import CrocoField class Example(models.Model): name = models.CharField(max_length=255) document = CrocoField() def __unicode__(self): return self.name
Custom thumbnails size
You can pass thumbnail_size like so:
document = CrocoField(thumbnail_size=(150, 150))
Where tuple is represented as (width, height).
If you do not pass custom thumbnail size, the default will be used (100x100). The maximum dimensions for thumbnail is 300x300.
Render the awesomeness
Documents
{{ obj.document.name }}
Returns name of the document.
{{ obj.document.size }}
Returns size of the document (in bytes).
{{ obj.document.size_human }}
Returns human-readable size of the document (eg. 1.3 MB).
{{ obj.document.type }}
Returns type (extension) of the document.
{{ obj.document.uuid }}
Returns UUID of the document (each Crocodoc document has unique id).
Thumbnails
{{ obj.document.thumbnail }}
Returns thumbnail as inline image (see Data URI scheme for more details).
URLs
{{ obj.document.url }}
Returns url of the document so it can be viewed directly.
{{ obj.document.content_url }}
Returns url of the document wrapped in HttpResponse object.
Annotations
{% url ‘croco_document_edit’ uuid=obj.document.uuid user_id=<user_id> user_name=<user_name> %}
Returns url of the document to allow user to create annotations. See the docs for more details.
{% url ‘croco_document_annotations’ uuid=obj.document.uuid user_id=<user_id> %}
Returns url of the document with annotations/comments made by user with given user_id.
Downloads
{{ obj.document.download_document }}
Returns the original document in PDF format.
{{ obj.document.download_thumbnail }}
Returns a thumbnail of the document’s first page in PNG format.
{{ obj.document.download_text }}
Returns the full text from a document. Note: This method is available only if your Crocodoc account has text extraction enabled.
Dependencies
Python 2.6.x, 2.7.x
Django 1.3.x, 1.4.x, 1.5.x
crocodoc 0.1.1
Python 3.x will be supported soon!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.