Re: Serving very large pdf files with django

2016-09-03 Thread 06userit
 

Hello,

Maybe you could use ImageMagick to show one page of the pdf as an image ? 
This is what I have implemented on my project : first page of pdf files can 
be pre-viewed before user uploads the whole file (if needed). In your case, 
pre-viewing could be parametrized to show page ā€˜nā€™ of the pdf file, 
probably. In my project, pre-viewing image is generated when pdf file is 
uploaded and saved by admin in myproject/media/files directory. Once pdf 
files are in media directory, users can preview those pdf files and tnen 
upload them, if needed (only first page can be pre-viewed by user. This is 
an implementation choice).


http://www.imagemagick.org/script/index.php




Implementation principles/credit can be found here :

http://www.yaconiello.com/blog/auto-generating-pdf-covers/




I am attaching the signals file_post_save file_pre_save, for information.


Cheers.

Django 1.8
Python 3.4


Note : to install ImageMagick:

sudo apt-get install libmagickwand-dev imagemagick libmagickcore-dev

The convert command allows to convert any page of pdf file into png image 
(for instance), eg :

convert -thumbnail 1280 test.pdf[0] test_1280.png
Several parameters exist to tune image quality (in my case, need to use 
density, trim and quality).

 

*models.p**y*

[ā€¦]

###

# SIGNALS #

###

from django.db.models.signals import post_save, pre_delete

from django.dispatch import receiver

from myproject.settings import MEDIA_ROOT

import subprocess


# What to do after a File is saved - receiver definition

def file_post_save(sender, instance=False, **kwargs):

# This post save function creates a thumbnail for the File

file = File.objects.get(pk=instance.pk)

command = "convert -density 300 -trim -thumbnail %s %s%s[0] 
-quality 100 %s%s" % (file.thumbnail_size, MEDIA_ROOT, file.file, 
MEDIA_ROOT, file.thumbnail)

proc = subprocess.Popen(command,

shell=True,

stdin=subprocess.PIPE,

stdout=subprocess.PIPE,

stderr=subprocess.PIPE,

)

stdout_value = proc.communicate()[0]

post_save.connect(file_post_save, sender=File, 
dispatch_uid="file_post_save_uid")

 

# What to do before a File is deleted - receiver definition

def file_pre_delete(sender, instance=False, **kwargs):

# This pre delete function deletes file and thumbnail from 
media directory

file = File.objects.get(pk=instance.pk)

command = "rm %s%s %s%s" % (MEDIA_ROOT, file.file, MEDIA_ROOT, 
file.thumbnail)

proc = subprocess.Popen(command,

shell=True,

stdin=subprocess.PIPE,

stdout=subprocess.PIPE,

stderr=subprocess.PIPE,

)

stdout_value = proc.communicate()[0]

pre_delete.connect(file_pre_delete, sender=File, 
dispatch_uid="file_pre_delete_uid")

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e409aafa-3133-47b1-b465-7d74501d0cac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Shout out to Grove Collaborative for django-sql-explorer

2016-09-03 Thread Lee Hinde
Just did a quick report for a client with django-sql-explorer (
https://github.com/groveco/django-sql-explorer) and once again I'm grateful
for its existence.

Highly recommended for quick ad-hoc reporting.

(no relationship except that I'm a Grove Co customer so I can give back a
little bit.)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMzqB6ace99Ut9fwzu%3DO7eu-pKa_RcsV%3DtjvO4-BYsBosg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Serving very large pdf files with django

2016-09-03 Thread ADEWALE ADISA
hi,
My view is that instead of combining all the images in one pdf, its better
to leave it as image and serve them individually by publishing link to each
image with text describing each page. Then the user can view any page they
are interested in. 'cause that single file is too large.
On Sep 3, 2016 6:12 PM, "Gary Roach"  wrote:

> Hi all,
>
> I am working on a project where I need to serve up large (100 -150 MB)
> static pdf files for viewing. The pdf files are jpg photos of pages from
> old log books. Downloading into the user's system is out of the question
> for obvious reasons. In addition the user may only need to see one or two
> pages out of a document. I plan on putting the static files in their own
> directory outside of the django programming and the postgresql database. I
> have looked at several addons to django but can't seem to get a "feel" for
> the whole problem. Has anyone had a similar problem and do they have a good
> solution .
>
> All help will be sincerely appreciated.
>
> OS Debian Linux
> Desktop KDE4
> Python 3.5
> Django 1.9.x
>
> Gary R.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/ms
> gid/django-users/b5e154b5-3c01-6f39-f4a1-6e285093aa45%40verizon.net.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMGzuy8XNUWXugEL0z3nOr_G2MYGz8x59NsUGM%2BZaHfW0AbYHA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Serving very large pdf files with django

2016-09-03 Thread ludovic coues
You have a few solution. You already excluded the user downloading the
full document. You can display the document directly in your page,
with solution like pdfjs, or you can extract the individual image from
the document on your server and display directly the image.

If you show the pdf, I fear your only solution is that the user
download the whole document in their browser. Same problem as with
downloading the full document. A solution would be to split the
document into individual page.

2016-09-03 19:11 GMT+02:00 Gary Roach :
> Hi all,
>
> I am working on a project where I need to serve up large (100 -150 MB)
> static pdf files for viewing. The pdf files are jpg photos of pages from old
> log books. Downloading into the user's system is out of the question for
> obvious reasons. In addition the user may only need to see one or two pages
> out of a document. I plan on putting the static files in their own directory
> outside of the django programming and the postgresql database. I have looked
> at several addons to django but can't seem to get a "feel" for the whole
> problem. Has anyone had a similar problem and do they have a good solution .
>
> All help will be sincerely appreciated.
>
> OS Debian Linux
> Desktop KDE4
> Python 3.5
> Django 1.9.x
>
> Gary R.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/b5e154b5-3c01-6f39-f4a1-6e285093aa45%40verizon.net.
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEuG%2BTbmgJVmMy4%3DxTZVedawYmfxp7HF0MeDXWxq878G0pQoqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


django symlink error for windows

2016-09-03 Thread M Hashmi
How to create a symbolic link in windows for error below using mlink?
Please advise.

Template error:
In template
C:\Python27\lib\site-packages\oscar\templates\oscar\dashboard\catalogue\product_row_image.html,
error at line 2
   'module' object has no attribute 'symlink'

   1 : {% load thumbnail %}



   2 :  {% if record.primary_image.original.url %}



   3 : {% with image=record.primary_image %}



   4 : {% thumbnail image.original "70x70" upscale=False as thumb %}



   5 : 



   6 : 



   7 : 



   8 : {% endthumbnail %}



   9 : {% endwith %}



   10 : {% else %}



   11 : ā€”



   12 : {% endif %}


Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in
get_response
  164. response = response.render()
File "C:\Python27\lib\site-packages\django\template\response.py" in render
  158. self.content = self.rendered_content
File "C:\Python27\lib\site-packages\django\template\response.py" in
rendered_content
  135. content = template.render(context, self._request)
File "C:\Python27\lib\site-packages\django\template\backends\django.py" in
render
  74. return self.template.render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in render
  210. return self._render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in _render
  202. return self.nodelist.render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in render
  905. bit = self.render_node(node, context)
File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node
  79. return node.render(context)
File "C:\Python27\lib\site-packages\django\template\loader_tags.py" in
render
  135. return compiled_parent._render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in _render
  202. return self.nodelist.render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in render
  905. bit = self.render_node(node, context)
File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node
  79. return node.render(context)
File "C:\Python27\lib\site-packages\django\template\loader_tags.py" in
render
  135. return compiled_parent._render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in _render
  202. return self.nodelist.render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in render
  905. bit = self.render_node(node, context)
File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node
  79. return node.render(context)
File "C:\Python27\lib\site-packages\django\template\loader_tags.py" in
render
  135. return compiled_parent._render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in _render
  202. return self.nodelist.render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in render
  905. bit = self.render_node(node, context)
File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node
  79. return node.render(context)
File "C:\Python27\lib\site-packages\django\template\loader_tags.py" in
render
  65. result = block.nodelist.render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in render
  905. bit = self.render_node(node, context)
File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node
  79. return node.render(context)
File "C:\Python27\lib\site-packages\django\template\loader_tags.py" in
render
  65. result = block.nodelist.render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in render
  905. bit = self.render_node(node, context)
File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node
  79. return node.render(context)
File "C:\Python27\lib\site-packages\django\template\loader_tags.py" in
render
  65. result = block.nodelist.render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in render
  905. bit = self.render_node(node, context)
File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node
  79. return node.render(context)
File "C:\Python27\lib\site-packages\django\template\defaulttags.py" in
render
  329. return nodelist.render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in render
  905. bit = self.render_node(node, context)
File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node
  79. return node.render(context)
File "C:\Python27\lib\site-packages\django\template\loader_tags.py" in
render
  65. result = block.nodelist.render(context)
File "C:

Serving very large pdf files with django

2016-09-03 Thread Gary Roach

Hi all,

I am working on a project where I need to serve up large (100 -150 MB) 
static pdf files for viewing. The pdf files are jpg photos of pages from 
old log books. Downloading into the user's system is out of the question 
for obvious reasons. In addition the user may only need to see one or 
two pages out of a document. I plan on putting the static files in their 
own directory outside of the django programming and the postgresql 
database. I have looked at several addons to django but can't seem to 
get a "feel" for the whole problem. Has anyone had a similar problem and 
do they have a good solution .


All help will be sincerely appreciated.

OS Debian Linux
Desktop KDE4
Python 3.5
Django 1.9.x

Gary R.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b5e154b5-3c01-6f39-f4a1-6e285093aa45%40verizon.net.
For more options, visit https://groups.google.com/d/optout.