Package: djcroco
djcrocois a customDjangomodel field to
add support for theCrocodoc API.It behaves like standardFileFieldso you can still use most of its properties (e.g.name,size,urletc) while having extra ones to play with Crocodoc API.djcrocois supported byIncuna(an awesome company
I work for!).RequirementsPython 2.6.x, 2.7.xDjango 1.3.x, 1.4.x, 1.5.xcrocodoc0.1.1Python 3.x will be supported soon!InstallationTo installdjcroco, simply run:pip install djcrocoInclude inurls.py:url(r'', include('djcroco.urls')),Define Crocodoc API token insettings.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 adddjcrocotoINSTALLED_APPS:INSTALLED_APPS += ('djcroco',)And load its template tags in the template you wish to use them in:{% load croco_tags %}UsageDefine the field in model you wish to extend:fromdjango.dbimportmodelsfromdjcroco.fieldsimportCrocoFieldclassExample(models.Model):name=models.CharField(max_length=255)document=CrocoField()def__unicode__(self):returnself.nameCustom thumbnails sizeYou can passthumbnail_sizelike 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 is300x300.Thumbnail cachingBy 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.classExample(models.Model):name=models.CharField(max_length=255)document=CrocoField(thumbnail_field='my_thumbnail')my_thumbnail=models.ImageField(upload_to='whatever/')Note that thethumbnail_fieldmust be a type ofImageField.Render the awesomenessDocuments{{ 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 (seeData URI schemefor 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 inHttpResponseobject.Bothurlandcontent_urlcan be extended withoptional parameters.{{ obj.document.url|editable:"true"|user_id:"1"|user_name:"admin" }}editableparam allows users to create annotations and comments while viewing the document.Default: falseuser_idanduser_namewill 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: allNote:user_filteris a renamed version of Crocodoc’sfilterin order to work in Django template system.Full list of supportedparameters.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 asdownload_thumbnailwith 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.