class="del-code nl-4 ol-4">
-]
+]
@@ -112,7 +112,7 @@ class MaintenaceInfo(BaseModelMixin): |
||
| 112 | 112 |
'model_id': self.model_id, |
| 113 | 113 |
'model_name': model.model_name if model else '', |
| 114 | 114 |
'model_full_name': model.model_full_name if model else '', |
| 115 |
- #'model_image_url': model.image2_url, |
|
| 115 |
+ # 'model_image_url': model.image2_url, |
|
| 116 | 116 |
'log_id': self.log_id, |
| 117 | 117 |
'sn': self.sn, |
| 118 | 118 |
'desc': self.desc, |
@@ -153,7 +153,7 @@ def activity_contribute_create(request): |
||
| 153 | 153 |
try: |
| 154 | 154 |
lensman = LensmanInfo.objects.get(user_id=user_id, status=True) |
| 155 | 155 |
user_name = lensman.name |
| 156 |
- except: |
|
| 156 |
+ except LensmanInfo.DoesNotExist: |
|
| 157 | 157 |
pass |
| 158 | 158 |
|
| 159 | 159 |
try: |
@@ -44,7 +44,6 @@ def upload_document_files(files, file_type='png'): |
||
| 44 | 44 |
file_ids = file_ids + res.FileIds |
| 45 | 45 |
_files = _files[20:] |
| 46 | 46 |
|
| 47 |
- |
|
| 48 | 47 |
return file_ids |
| 49 | 48 |
|
| 50 | 49 |
|
@@ -4,6 +4,15 @@ from __future__ import division |
||
| 4 | 4 |
|
| 5 | 5 |
|
| 6 | 6 |
try: |
| 7 |
+ from cStringIO import StringIO |
|
| 8 |
+ from cStringIO import StringIO as BytesIO |
|
| 9 |
+except ImportError: |
|
| 10 |
+ try: |
|
| 11 |
+ from StringIO import StringIO |
|
| 12 |
+ from StringIO import StringIO as BytesIO |
|
| 13 |
+ except ImportError: |
|
| 14 |
+ from io import BytesIO, StringIO |
|
| 15 |
+try: |
|
| 7 | 16 |
from PIL import Image |
| 8 | 17 |
except ImportError: |
| 9 | 18 |
import Image |
@@ -17,3 +26,18 @@ def make_thumbnail(im_path, im_thumbnail_path=None, max_width=360): |
||
| 17 | 26 |
im.thumbnail((thumb_width, thumb_height), Image.ANTIALIAS) |
| 18 | 27 |
im.save(im_thumbnail_path or im_path, im.format or 'JPEG', quality=90) |
| 19 | 28 |
return width, height, thumb_width, thumb_height |
| 29 |
+ |
|
| 30 |
+ |
|
| 31 |
+def make_thumbnail2(data, w=360, h=240): |
|
| 32 |
+ im = Image.open(BytesIO(data)) |
|
| 33 |
+ fmt = im.format.lower() |
|
| 34 |
+ width, height = im.size |
|
| 35 |
+ if width > height: |
|
| 36 |
+ thumb_width, thumb_height = w, height * w / width |
|
| 37 |
+ else: |
|
| 38 |
+ thumb_width, thumb_height = width * h / height, h |
|
| 39 |
+ im.thumbnail((thumb_width, thumb_height), Image.ANTIALIAS) |
|
| 40 |
+ out = BytesIO() |
|
| 41 |
+ im.save(out, format=fmt) |
|
| 42 |
+ data = out.getvalue() |
|
| 43 |
+ return data |