src/ldt/ldt/management/commands/synciri.py
author ymh <ymh.work@gmail.com>
Tue, 22 Jan 2013 13:03:10 +0100
changeset 1077 94cca4093b60
permissions -rw-r--r--
add command to sync the iri file, recreating them if necessary
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1077
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
'''
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
Created on Jan 22, 2013
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
@author: ymh
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
'''
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
from django.core.management.base import NoArgsCommand
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
from ..utils import show_progress
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
from ldt.ldt_utils.models import Content
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
class Command(NoArgsCommand):
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
    
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
    def handle_noargs(self, **options):
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
        
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
        content_list = list(Content.objects.all())
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
        writer = None
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
        for i,c in enumerate(content_list):
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
            writer = show_progress(i+1, len(content_list), "Processing content %s" % c.title, 80, writer)
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
            c.sync_iri_file()
94cca4093b60 add command to sync the iri file, recreating them if necessary
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21