Example #1
0
    def handle(self, *args, **options):
        """
        This handler operation does the actual work!
        """
        if len(args) != 1 and len(args) != 2:
            raise CommandError("delete_course requires one or more arguments: <course_id> |commit|")

        try:
            course_key = CourseKey.from_string(args[0])
        except InvalidKeyError:
            course_key = SlashSeparatedCourseKey.from_deprecated_string(args[0])

        commit = False
        if len(args) == 2:
            commit = args[1] == 'commit'

        if commit:
            print('Actually going to delete the course references from LMS database....')
            print('Note: There is a corresponding CMS command you must run BEFORE this command.')

            if hasattr(settings, 'TEST_ROOT'):
                SignalHandler.course_deleted.send(sender=None, course_key=course_key)
            else:

                if query_yes_no("Deleting ALL records with references to course {0}. Confirm?".format(course_key), default="no"):
                    if query_yes_no("Are you sure. This action cannot be undone!", default="no"):

                        # Broadcast the deletion event to CMS listeners
                        print 'Notifying LMS system components...'
                        SignalHandler.course_deleted.send(sender=None, course_key=course_key)

                        print 'LMS Course Cleanup Complete!'
def analyze_entity(entity_id):

    if entity_is_earmark(entity_id):
        print "Entity is matched to earmark already, your data might be stale. Ignoring entity %d" % (entity_id)
        return
    if entity_is_negative_example(entity_id):
        print "Entity %d is flagged as negative example, ignoring" % (entity_id)
        return
    entity = Entity(entity_id)
    question = "Does this entity look like an earmark?\n%s\nId: %d\nPath: %s\n" % (
        entity.entity_inferred_name,
        entity_id,
        path_tools.doc_id_to_path(entity.document_id),
    )
    is_earmark = prompt.query_yes_no(question, default="yes")
    if is_earmark:
        question = "Does it match an earmark on OMB website?\n"
        is_match = prompt.query_yes_no(question, default="yes")
        if is_match:
            question = "What is the earmark id?\n"
            earmark_id = prompt.query_number(question)
            amend_earmark.match_earmark_with_entity(earmark_id, entity.id)
        else:
            question = "Are you sure you want to create new earmark?\n"
            if prompt.query_yes_no(question, default="yes"):
                # question = "Please enter a year for the earmark?\n"
                year = path_tools.get_report_year(entity.document_id)  # prompt.query_number(question)
                amend_earmark.crete_new_earmark(entity.id, year)
    else:
        # it is not an earmark, now flag it as negative
        question = "Do you want to flag it as negative match?\n"
        if prompt.query_yes_no(question, default="yes"):
            amend_earmark.insert_entity_to_negative_table(entity_id)
            print "Entity %d has been labeled as negative example" % (entity_id)
    print chr(27) + "[2J"  # this clears the terminal
    def handle(self, *args, **options):
        try:
            # a course key may have unicode chars in it
            try:
                course_key = text_type(options['course_key'], 'utf8')
            # May already be decoded to unicode if coming in through tests, this is ok.
            except TypeError:
                course_key = text_type(options['course_key'])
            course_key = CourseKey.from_string(course_key)
        except InvalidKeyError:
            raise CommandError('Invalid course_key: {}'.format(options['course_key']))

        if not modulestore().get_course(course_key):
            raise CommandError('Course not found: {}'.format(options['course_key']))

        print('Preparing to delete course %s from module store....' % options['course_key'])

        if query_yes_no('Are you sure you want to delete course {}?'.format(course_key), default='no'):
            if query_yes_no('Are you sure? This action cannot be undone!', default='no'):
                delete_course(course_key, ModuleStoreEnum.UserID.mgmt_command, options['keep_instructors'])

                if options['remove_assets']:
                    contentstore().delete_all_course_assets(course_key)
                    print('Deleted assets for course'.format(course_key))

                print('Deleted course {}'.format(course_key))
    def handle(self, *args, **options):
        """
        This handler operation does the actual work!
        """
        if len(args) != 1 and len(args) != 2:
            raise CommandError("delete_course requires one or more arguments: <course_id> |commit|")

        try:
            course_key = CourseKey.from_string(args[0])
        except InvalidKeyError:
            course_key = SlashSeparatedCourseKey.from_deprecated_string(args[0])

        commit = False
        if len(args) == 2:
            commit = args[1] == 'commit'

        if commit:
            print('Actually going to delete the course references from LMS database....')
            print('Note: There is a corresponding CMS command you must run BEFORE this command.')

            if hasattr(settings, 'TEST_ROOT'):
                course_deleted.send(sender=None, course_key=course_key)
            else:

                if query_yes_no("Deleting ALL records with references to course {0}. Confirm?".format(course_key), default="no"):
                    if query_yes_no("Are you sure. This action cannot be undone!", default="no"):

                        # Broadcast the deletion event to CMS listeners
                        print 'Notifying LMS system components...'
                        course_deleted.send(sender=None, course_key=course_key)

                        print 'LMS Course Cleanup Complete!'
    def handle(self, *args, **options):
        try:
            course_key = CourseKey.from_string(options['course_key'])
        except InvalidKeyError:
            raise CommandError("Invalid course_key: '%s'." % options['course_key'])

        if not modulestore().get_course(course_key):
            raise CommandError("Course with '%s' key not found." % options['course_key'])

        print 'Going to delete the %s course from DB....' % options['course_key']
        if query_yes_no("Deleting course {0}. Confirm?".format(course_key), default="no"):
            if query_yes_no("Are you sure. This action cannot be undone!", default="no"):
                delete_course(course_key, ModuleStoreEnum.UserID.mgmt_command, options['keep_instructors'])
                print "Deleted course {}".format(course_key)
Example #6
0
    def handle(self, *args, **options):
        if not options.get('age'):
            raise CommandError(
                "bulk_delete_courses_with_reference_data command requires one integer argument: --age"
            )

        age_in_days = int(options.get('age'))
        if query_yes_no(
                "Are you sure you want to delete all courses and their reference data having no activity "
                "in last %s days. This action cannot be undone!" % age_in_days,
                default="no"):
            created_time = datetime.now(
                pytz.UTC) + timedelta(days=-age_in_days)
            courses = self.module_store.get_courses()

            for course in courses:
                last_edited_on = getattr(course, 'edited_on')
                if last_edited_on and last_edited_on < created_time:
                    self.total_courses += 1
                    try:
                        self.delete_course_and_data(course.id)
                        self.total_deleted += 1
                    except Exception as ex:  # pylint: disable=broad-except
                        log.exception("Exception while deleting course %s",
                                      ex.message)

            completion_message = "command completed. Total {} courses deleted out of {}".format(
                self.total_deleted, self.total_courses)
            log.info(completion_message)
def label_earmark(earmark, matches, conn, cmd, cur):
    
    os.system('clear')

    short_desc = normalize(earmark['short_description'])
    full_desc = normalize(earmark['full_description'])
    recipient = normalize(earmark['recipient'])

    print "Lets Label Earmark: %d" % earmark['earmark_id']
    #print "Recipient: %s" % bcolors.OKGREEN + recipient + bcolors.ENDC
    print "Short Desription: %s" % bcolors.OKGREEN + short_desc + bcolors.ENDC
    print "Full Description: %s" % bcolors.OKGREEN + full_desc + bcolors.ENDC

    consecutive_nos = 0
    labeled = False

    for i in range(len(matches)):
        score = matches[i][0]
        entity = matches[i][1]
        earmark_document_id = matches[i][2]
        entity_id = entity['id']

        query_str = bcolors.WARNING + entity['entity_inferred_name'] + bcolors.ENDC

        #Auto label the rest false
        if consecutive_nos > 10:
            cur.execute(cmd, (earmark['earmark_id'], earmark_document_id, entity_id, score, False))


        elif score >= AUTO_LABEL_POSITIVE:
            print "Auto Lableing: %s" % query_str
            cur.execute(cmd, (earmark['earmark_id'], earmark_document_id, entity_id, score, True))
            labeled = True

        elif score <= AUTO_LABEL_NEGATIVE:
            pass
            #cur.execute(cmd, (earmark['earmark_id'], earmark_document_id, entity_id, score, False))

        else:
            print path_tools.doc_id_to_path(earmark_document_id)
            if query_yes_no(query_str):
                cur.execute(cmd, (earmark['earmark_id'], earmark_document_id, entity_id, score,  True))
                consecutive_nos = 0
            else:
                cur.execute(cmd, (earmark['earmark_id'], earmark_document_id, entity_id, score, False))
                consecutive_nos += 1
            labeled = True

    if not labeled:
        print "no matches above minimum theshold!"
        cur.execute(cmd, (earmark['earmark_id'], -1, -1, 0, False))



    conn.commit()
Example #8
0
    def handle(self, *args, **options):
        if len(args) != 1 and len(args) != 2:
            raise CommandError("delete_course requires one or more arguments: <course_id> |commit|")

        try:
            course_key = CourseKey.from_string(args[0])
        except InvalidKeyError:
            course_key = SlashSeparatedCourseKey.from_deprecated_string(args[0])

        commit = False
        if len(args) == 2:
            commit = args[1] == 'commit'

        if commit:
            print('Actually going to delete the course from DB....')
            print('Note: There is a corresponding LMS cleanup command you should run afterwards')

            if query_yes_no("Deleting course {0}. Confirm?".format(course_key), default="no"):
                if query_yes_no("Are you sure. This action cannot be undone!", default="no"):
                    delete_course_and_groups(course_key, ModuleStoreEnum.UserID.mgmt_command)
Example #9
0
    def handle(self, *args, **options):
        try:
            course_key = CourseKey.from_string(options['course_key'])
        except InvalidKeyError:
            raise CommandError("Invalid course_key: '%s'." %
                               options['course_key'])

        if not modulestore().get_course(course_key):
            raise CommandError("Course with '%s' key not found." %
                               options['course_key'])

        print 'Going to delete the %s course from DB....' % options[
            'course_key']
        if query_yes_no("Deleting course {0}. Confirm?".format(course_key),
                        default="no"):
            if query_yes_no("Are you sure. This action cannot be undone!",
                            default="no"):
                delete_course(course_key, ModuleStoreEnum.UserID.mgmt_command,
                              options['keep_instructors'])
                print "Deleted course {}".format(course_key)
def analyze_entity(entity_id):

    if entity_is_earmark(entity_id):
        print "Entity is matched to earmark already, your data might be stale. Ignoring entity %d" % (
            entity_id)
        return
    if entity_is_negative_example(entity_id):
        print "Entity %d is flagged as negative example, ignoring" % (
            entity_id)
        return
    entity = Entity(entity_id)
    question = "Does this entity look like an earmark?\n%s\nId: %d\nPath: %s\n" % (
        entity.entity_inferred_name, entity_id,
        path_tools.doc_id_to_path(entity.document_id))
    is_earmark = prompt.query_yes_no(question, default="yes")
    if is_earmark:
        question = "Does it match an earmark on OMB website?\n"
        is_match = prompt.query_yes_no(question, default="yes")
        if is_match:
            question = "What is the earmark id?\n"
            earmark_id = prompt.query_number(question)
            amend_earmark.match_earmark_with_entity(earmark_id, entity.id)
        else:
            question = "Are you sure you want to create new earmark?\n"
            if prompt.query_yes_no(question, default="yes"):
                #question = "Please enter a year for the earmark?\n"
                year = path_tools.get_report_year(
                    entity.document_id)  #prompt.query_number(question)
                amend_earmark.crete_new_earmark(entity.id, year)
    else:
        # it is not an earmark, now flag it as negative
        question = "Do you want to flag it as negative match?\n"
        if prompt.query_yes_no(question, default="yes"):
            amend_earmark.insert_entity_to_negative_table(entity_id)
            print "Entity %d has been labeled as negative example" % (
                entity_id)
    print chr(27) + "[2J"  # this clears the terminal
    def handle(self, *args, **options):
        course_id = options.get('course_id')
        compute_for_all_open_courses = options.get('compute_for_all_open_courses')
        compute_for_inactive_courses = options.get('compute_for_inactive_courses')
        months_back_limit = options.get('months_back_limit')
        interactive = options.get('interactive')

        if course_id:
            task_compute_social_scores_in_course.delay(course_id)
        elif compute_for_all_open_courses or compute_for_inactive_courses:
            # prompt for user confirmation in interactive mode
            execute = query_yes_no(
                "Are you sure to compute social engagement scores for all selected courses?"
                , default="no"
            ) if interactive else True

            if execute:
                courses = CourseOverview.objects.none()
                today = datetime.datetime.today().replace(tzinfo=UTC)

                # Add active courses to queryset if compute_for_all_open_courses is True
                if compute_for_all_open_courses:
                    courses |= CourseOverview.objects.filter(
                        Q(end__gte=today) |
                        Q(end__isnull=True)
                    )
                # Add inactive courses to queryset if compute_for_inactive_courses is True
                if compute_for_inactive_courses:
                    filter_set = Q(end__lt=today)
                    # If user set months back limit, add filter to queryset
                    if months_back_limit:
                        backwards_query_limit_date = (
                            datetime.datetime.today() - relativedelta(months=months_back_limit)
                        ).replace(tzinfo=UTC)
                        filter_set &= Q(end__gte=backwards_query_limit_date)
                    # Filter courses and add them to courses list
                    courses |= CourseOverview.objects.filter(filter_set)

                for course in courses:
                    course_id = unicode(course.id)
                    task_compute_social_scores_in_course.delay(course_id)
                    log.info("Task queued to compute social engagment score for course %s", course_id)
Example #12
0
    def handle(self, *args, **options):

        course_id = options.get('course_id')
        compute_for_all_open_courses = options.get(
            'compute_for_all_open_courses')
        if course_id:
            task_compute_social_scores_in_course.delay(course_id)
        elif compute_for_all_open_courses:
            if query_yes_no(
                    "Are you sure to compute social engagement scores for all open courses?",
                    default="no"):
                open_courses = CourseOverview.objects.filter(
                    Q(end__gte=datetime.datetime.today().replace(tzinfo=UTC))
                    | Q(end__isnull=True))
                for course in open_courses:
                    course_id = unicode(course.id)
                    task_compute_social_scores_in_course.delay(course_id)
                    log.info(
                        "Task queued to compute social engagment score for course %s",
                        course_id)