This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage 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!).

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.

Release History

Release History

0.3.2

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.6

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
djcroco-0.3.2.tar.gz (12.1 kB) Copy SHA256 Checksum SHA256 Source Nov 26, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting