UNKNOWN
Project description
This repository is dead!
This repository is not maintained anymore, Crocodoc was acquired by Box.net and also this product was never easy to work with.
djcroco
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.
Requirements
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!
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>'
When optional parameters for URLs are used (see below for more details) - then you need to add djcroco to INSTALLED_APPS:
INSTALLED_APPS += ('djcroco',)
And load its template tags in the template you wish to use them in:
{% load croco_tags %}
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.
Thumbnail caching
By default the thumbnail will be generated every time template gets rendered and this involves hitting Crocodoc API for each thumbnail. It could be time expensive if you have many items on a single page. To avoid above issue you can point to a field where the thumbnail will be saved and served from there the next time.
class Example(models.Model):
name = models.CharField(max_length=255)
document = CrocoField(thumbnail_field='my_thumbnail')
my_thumbnail = models.ImageField(upload_to='whatever/')
Note that the thumbnail_field must be a type of ImageField.
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 (note: each Crocodoc document has unique id).
Thumbnails
{{ obj.document.thumbnail }}
Returns thumbnail as inline image (see Data URI scheme for more details). See below for how to download a thumbnail.
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.
Both url and content_url can be extended with optional parameters.
{{ obj.document.url|editable:"true"|user_id:"1"|user_name:"admin" }}
editable param allows users to create annotations and comments while viewing the document. Default: false
user_id and user_name will be shown in the viewer to attribute annotations and comments to their author. Required if editable is true
{{ obj.document.url|user_filter:"1,2,3" }}
Limits which users’ annotations and comments are shown. Possible values are: all, none, or a comma-separated list of user IDs. Default: all
Note: user_filter is a renamed version of Crocodoc’s filter in order to work in Django template system.
Full list of supported parameters.
Downloads
{{ obj.document.download_document }}
Returns the original document in PDF format.
{{ obj.document.download_document|annotated:"true" }}
Returns the original document with annotations. Default: false
{{ obj.document.download_document|user_filter:"1,2,3" }}
Returns the original document with annotations limited to given users. Possible values are: all, none, or a comma-separated list of user IDs. Default: all
{{ obj.document.download_thumbnail }}
Returns a thumbnail of the document’s first page in PNG format.
{{ obj.document.download_thumbnail|size:"99x99" }}
Same as download_thumbnail with custom dimensions of the thumbnail in the format {width}x{height}. Largest dimensions allowed are 300x300. Default: 100x100
{{ 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.
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
File details
Details for the file django-croco-0.4.2.tar.gz
.
File metadata
- Download URL: django-croco-0.4.2.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c50c1eb6e35cf1c45f7148b9b6df8fd7dcf125ae050c471cd625682072d58ce |
|
MD5 | 0d52971ec094075bd2001f9b859b5185 |
|
BLAKE2b-256 | 8c24ea842ad03cb7f07a6d14be3cc93e4540daf9ca65c88e271e31810a368560 |