--- a/src/ldt/ldt/management/commands/statannotation.py Thu Feb 02 15:35:47 2012 +0100
+++ b/src/ldt/ldt/management/commands/statannotation.py Thu Feb 02 15:44:35 2012 +0100
@@ -1,6 +1,7 @@
from django.core.management.base import BaseCommand
from ldt.ldt_utils.models import Content
from ldt.ldt_utils.stat import update_stat_content, get_empty_stat_vector, get_empty_stat_field
+from ldt.management.utils import show_progress
class Command(BaseCommand):
help = 'Computes annotation for all contents'
@@ -10,14 +11,19 @@
empty_stat_vector = get_empty_stat_vector()
size_stat = len(empty_stat_vector)
+
+ writer = None
+ total = Content.objects.count()
+ i = 1
for c in Content.objects.all():
+ show_progress(i, total, "computing annotation stats for contents", 40, writer)
if not c.stat_annotation or len( c.stat_annotation.split(',')) != size_stat:
c.stat_annotation = get_empty_stat_field()
c.save()
update_stat_content(c)
+ i += 1
- print "Done"
return None
\ No newline at end of file
--- a/src/ldt/ldt/security/command.py Thu Feb 02 15:35:47 2012 +0100
+++ b/src/ldt/ldt/security/command.py Thu Feb 02 15:44:35 2012 +0100
@@ -2,8 +2,11 @@
from django.contrib.auth.models import Group, User
from ldt.ldt_utils.models import Project, Content
from guardian.shortcuts import assign
+from ldt.management.utils import show_progress
def set_default_permissions(verbose=False, is_migration=False, orm=None):
+ writer = None
+
if is_migration:
list_model = {'User': orm['auth.user'],
@@ -21,20 +24,29 @@
everyone, created = Group.objects.get_or_create(name=settings.PUBLIC_GROUP_NAME)
if verbose:
- print "Set project permissions..."
+ i = 1
+ total = list_model['Project'].objects.count()
for proj in list_model['Project'].objects.all():
assign('ldt_utils.change_project', proj.owner, proj)
assign('ldt_utils.view_project', proj.owner, proj)
+ if verbose:
+ show_progress(i, total, "Assign permissions to projects", 40, writer)
+ i += 1
for published_proj in list_model['Project'].objects.filter(state=2):
assign('ldt_utils.view_project', everyone, published_proj)
if verbose:
- print "Set group permissions...[This may take a while]"
+ i = 1
+ writer = None
+ total = list_model['User'].objects.count()
for user in list_model['User'].objects.all():
everyone.user_set.add(user)
+ if verbose:
+ show_progress(i, total, "Assign permissions to groups", 40, writer)
+ i += 1
for group in user.groups.exclude(name=settings.PUBLIC_GROUP_NAME):
for proj in list_model['Project'].objects.filter(owner=user):