commands: added a command for sending batched documents to MyCourse
This commit is contained in:
parent
23676f995e
commit
98e1548f68
|
@ -0,0 +1,50 @@
|
|||
# vim:spell:spelllang=fr
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
import os
|
||||
from optparse import make_option
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db import transaction
|
||||
|
||||
from ... import models, django_ws
|
||||
|
||||
class Command(BaseCommand):
|
||||
'''
|
||||
Envoyer les demandes blackboard
|
||||
'''
|
||||
can_import_django_settings = True
|
||||
requires_model_validation = True
|
||||
args = ''
|
||||
help = 'Envoyer les demandes blackboard'
|
||||
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option("--send", action="store_true"),
|
||||
make_option("--list", action="store_true"),)
|
||||
|
||||
@transaction.commit_on_success
|
||||
def handle(self, *args, **options):
|
||||
logger = logging.getLogger()
|
||||
bb_pushs = models.BlackBoardPush.objects.filter(request__history__new_status__start=True)
|
||||
if options['list']:
|
||||
for push in bb_pushs:
|
||||
print ' - document', os.path.basename(push.request.uploadfile.name), 'de', push.request.user.display_name(), 'dans le cours', push.course_name,
|
||||
if push.visible_to_students:
|
||||
print '(visible aux étudiants)',
|
||||
print
|
||||
if options['send']:
|
||||
conn = django_ws.get_bb_conn()
|
||||
for push in bb_pushs:
|
||||
logger.info('sending request %s to mycourse', push.request.pk)
|
||||
logger.info('from user %s', push.request.user.display_name().encode('utf-8'))
|
||||
logger.info('into course %s', push.course_name.encode('utf-8'))
|
||||
if push.visible_to_students:
|
||||
logger.info('visible to students')
|
||||
ok, result = conn.send_file(push.request.uploadfile, [push.course_name], push.visible_to_students)
|
||||
if ok:
|
||||
push.send = True
|
||||
push.save()
|
||||
logger.info('sending succeeded')
|
||||
else:
|
||||
logger.error('sending failed: %s', result.encode('utf-8'))
|
Reference in New Issue