src/ldt/ldt/management/commands/statannotation.py
changeset 474 5e7942f049a6
parent 468 d1ff0694500b
child 510 496917cf614a
equal deleted inserted replaced
473:a400c401f78b 474:5e7942f049a6
     1 from django.core.management.base import BaseCommand
     1 from django.core.management.base import BaseCommand
     2 from ldt.ldt_utils.models import Content
     2 from ldt.ldt_utils.models import Content
     3 from ldt.ldt_utils.stat import update_stat_content, get_empty_stat_vector
     3 from ldt.ldt_utils.stat import update_stat_content, get_empty_stat_vector, get_empty_stat_field
     4 
     4 
     5 class Command(BaseCommand):
     5 class Command(BaseCommand):
     6     help = 'Computes annotation for all contents'
     6     help = 'Computes annotation for all contents'
     7     
     7     
     8     
     8     
    11         empty_stat_vector = get_empty_stat_vector()
    11         empty_stat_vector = get_empty_stat_vector()
    12         size_stat = len(empty_stat_vector)
    12         size_stat = len(empty_stat_vector)
    13        
    13        
    14         for c in Content.objects.all():
    14         for c in Content.objects.all():
    15             if not c.stat_annotation or len( c.stat_annotation.split(',')) != size_stat:
    15             if not c.stat_annotation or len( c.stat_annotation.split(',')) != size_stat:
    16                 c.stat_annotation = c.list2str(empty_stat_vector)
    16                 c.stat_annotation = get_empty_stat_field()
    17                 c.save()
    17                 c.save()
    18             
    18             
    19             update_stat_content(c)
    19             update_stat_content(c)
    20             
    20             
    21         print "Done"                  
    21         print "Done"