| author | ymh <ymh.work@gmail.com> |
| Thu, 15 Mar 2018 23:52:11 +0100 | |
| changeset 686 | 385e3a12ee27 |
| parent 618 | cb8b833ad122 |
| child 693 | 09e00f38d177 |
| child 704 | b5835dca2624 |
| permissions | -rw-r--r-- |
|
458
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
''' |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
Created on Feb 22, 2015 |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
|
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
@author: ymh |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
''' |
| 462 | 7 |
import logging |
| 492 | 8 |
import os |
| 462 | 9 |
|
| 492 | 10 |
from django.conf import settings |
11 |
from django.core.urlresolvers import reverse |
|
|
458
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
from django.db import transaction |
| 462 | 13 |
|
|
458
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
from hdalab.models.renkan import HdalabRenkanStateTransition |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
|
| 462 | 16 |
|
| 492 | 17 |
from subprocess import check_call |
18 |
||
19 |
||
20 |
||
21 |
||
| 462 | 22 |
logger = logging.getLogger(__name__) |
23 |
||
|
458
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
@transaction.atomic |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
25 |
def change_renkan_state(hda_renkan, state, message=None, author=None): |
|
686
385e3a12ee27
Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
618
diff
changeset
|
26 |
|
|
458
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
if state != hda_renkan.state: |
|
686
385e3a12ee27
Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
618
diff
changeset
|
28 |
|
|
458
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
29 |
HdalabRenkanStateTransition.objects.create(renkan=hda_renkan, from_state=hda_renkan.state, to_state=state, message=message, author=author) |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
30 |
hda_renkan.state = state |
| 462 | 31 |
hda_renkan.save() |
|
686
385e3a12ee27
Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
618
diff
changeset
|
32 |
|
| 492 | 33 |
|
34 |
def renkan_capture_preview(hdalab_renkan): |
|
35 |
#get last state date or last modification date |
|
36 |
#states are ordered by ts |
|
37 |
folder_date = hdalab_renkan.renkan.modification_date |
|
38 |
states = hdalab_renkan.states |
|
39 |
state = None |
|
40 |
if states.count() > 0: |
|
41 |
state = states.all()[0] |
|
42 |
if state: |
|
43 |
folder_date = state.ts |
|
44 |
||
45 |
rel_export_path_dir = "thumbnails/renkan/%04d/%02d/%02d" % (folder_date.year, folder_date.month, folder_date.day) |
|
46 |
export_path_dir = os.path.join(settings.MEDIA_ROOT,rel_export_path_dir) |
|
47 |
export_filename = "%s.png" % hdalab_renkan.renkan.rk_id |
|
|
686
385e3a12ee27
Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
618
diff
changeset
|
48 |
|
| 492 | 49 |
export_path = os.path.join(export_path_dir, export_filename) |
50 |
rel_export_path = os.path.join(rel_export_path_dir, export_filename) |
|
|
686
385e3a12ee27
Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
618
diff
changeset
|
51 |
|
| 492 | 52 |
if not os.path.exists(export_path_dir): |
| 618 | 53 |
try: |
54 |
os.makedirs(export_path_dir) |
|
55 |
except OSError, e: |
|
56 |
if e.errno != 17: |
|
|
686
385e3a12ee27
Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
618
diff
changeset
|
57 |
raise |
| 618 | 58 |
# time.sleep might help here |
59 |
pass |
|
|
686
385e3a12ee27
Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
618
diff
changeset
|
60 |
|
| 492 | 61 |
preview_dim = getattr(settings, 'RENKAN_PREVIEW_DIM', (500,500)) |
62 |
preview_wait = getattr(settings, 'RENKAN_PREVIEW_WAIT', 5000) |
|
63 |
||
64 |
preview_args = [ |
|
65 |
getattr(settings,'RENKAN_PREVIEW_PHANTOMJS_PATH','phantomjs'), |
|
66 |
os.path.join(os.path.dirname(os.path.abspath(__file__)),'scripts/capture-phantomjs.js'), |
|
|
686
385e3a12ee27
Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
618
diff
changeset
|
67 |
"%s%s%s?rk_id=%s" % (getattr(settings, 'FRONT_WEB_URL', settings.WEB_URL), settings.BASE_URL, reverse('renkan_full'),hdalab_renkan.renkan.rk_id), |
| 492 | 68 |
export_path, |
69 |
"--width=%d" % preview_dim[0], |
|
70 |
"--height=%d" % preview_dim[1], |
|
71 |
"--wait=%d" % preview_wait |
|
72 |
] |
|
73 |
check_call(preview_args) |
|
|
686
385e3a12ee27
Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
618
diff
changeset
|
74 |
|
| 492 | 75 |
hdalab_renkan.renkan.image = rel_export_path |
76 |
hdalab_renkan.renkan.save() |
|
77 |