|
492
|
1 |
# -*- coding: utf-8 -*- |
|
|
2 |
''' |
|
|
3 |
Created on Jan 30, 2012 |
|
|
4 |
|
|
|
5 |
@author: ymh |
|
|
6 |
''' |
|
|
7 |
|
|
|
8 |
import logging |
|
|
9 |
from optparse import make_option |
|
|
10 |
|
|
|
11 |
from django.conf import settings |
|
|
12 |
from django.core.management.base import NoArgsCommand |
|
|
13 |
from django.core.management.color import no_style |
|
|
14 |
|
|
|
15 |
from hdabo.utils import show_progress |
|
|
16 |
from hdalab.models.renkan import HdalabRenkan |
|
|
17 |
from hdalab.services import renkan_capture_preview |
|
|
18 |
|
|
|
19 |
|
|
|
20 |
logger = logging.getLogger(__name__) |
|
|
21 |
|
|
|
22 |
class Command(NoArgsCommand): |
|
|
23 |
''' |
|
|
24 |
calculate renkan preview. |
|
|
25 |
''' |
|
|
26 |
options = '' |
|
|
27 |
help = """calculate renkan preview.""" |
|
|
28 |
|
|
|
29 |
option_list = NoArgsCommand.option_list + ( |
|
|
30 |
make_option('--all', |
|
|
31 |
action='store_true', |
|
|
32 |
dest='all', |
|
|
33 |
default=False, |
|
|
34 |
help='force all tags to be updated, not only those not yet processed'), |
|
|
35 |
) |
|
|
36 |
|
|
|
37 |
|
|
|
38 |
def handle_noargs(self, **options): |
|
|
39 |
|
|
|
40 |
self.style = no_style() |
|
|
41 |
|
|
|
42 |
self.all = options.get('all', False) |
|
|
43 |
|
|
|
44 |
queryset = HdalabRenkan.objects.filter(state=HdalabRenkan.PUBLISHED) |
|
|
45 |
|
|
|
46 |
if not self.all: |
|
|
47 |
queryset = queryset.filter(renkan__image = settings.DEFAULT_RENKAN_ICON) |
|
|
48 |
|
|
|
49 |
count = queryset.count() |
|
|
50 |
|
|
|
51 |
writer = None |
|
|
52 |
for i,hdalab_renkan in enumerate(queryset.select_related()): |
|
|
53 |
writer = show_progress(i+1, count, hdalab_renkan.renkan.title, 50, writer) |
|
|
54 |
if hdalab_renkan.renkan.image and hdalab_renkan.renkan.image != settings.DEFAULT_RENKAN_ICON: |
|
|
55 |
hdalab_renkan.renkan.image.delete(False) |
|
|
56 |
hdalab_renkan.renkan.image.delete_thumbnails() |
|
|
57 |
|
|
|
58 |
renkan_capture_preview(hdalab_renkan) |
|
|
59 |
|