当前位置: 首页>>代码示例>>Python>>正文


Python models.GeneratedCertificate类代码示例

本文整理汇总了Python中certificates.models.GeneratedCertificate的典型用法代码示例。如果您正苦于以下问题:Python GeneratedCertificate类的具体用法?Python GeneratedCertificate怎么用?Python GeneratedCertificate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GeneratedCertificate类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_refundable_when_certificate_exists

    def test_refundable_when_certificate_exists(self, cutoff_date):
        """ Assert that enrollment is not refundable once a certificat has been generated."""

        cutoff_date.return_value = datetime.now(pytz.UTC) + timedelta(days=1)

        self.assertTrue(self.enrollment.refundable())

        GeneratedCertificateFactory.create(
            user=self.user,
            course_id=self.course.id,
            status=CertificateStatuses.downloadable,
            mode='verified'
        )

        self.assertFalse(self.enrollment.refundable())
        self.assertFalse(
            self.enrollment.refundable(
                user_already_has_certs_for=GeneratedCertificate.course_ids_with_certs_for_user(self.user)
            )
        )

        # Assert that can_refund overrides this and allows refund
        self.enrollment.can_refund = True
        self.assertTrue(self.enrollment.refundable())
        self.assertTrue(
            self.enrollment.refundable(
                user_already_has_certs_for=GeneratedCertificate.course_ids_with_certs_for_user(self.user)
            )
        )
开发者ID:auvipy,项目名称:edx-platform,代码行数:29,代码来源:test_refunds.py

示例2: test_course_ids_with_certs_for_user

    def test_course_ids_with_certs_for_user(self):
        # Create one user with certs and one without
        student_no_certs = UserFactory()
        student_with_certs = UserFactory()
        student_with_certs.profile.allow_certificate = True
        student_with_certs.profile.save()

        # Set up a couple of courses
        course_1 = CourseFactory.create()
        course_2 = CourseFactory.create()

        # Generate certificates
        GeneratedCertificateFactory.create(
            user=student_with_certs,
            course_id=course_1.id,
            status=CertificateStatuses.downloadable,
            mode='honor'
        )
        GeneratedCertificateFactory.create(
            user=student_with_certs,
            course_id=course_2.id,
            status=CertificateStatuses.downloadable,
            mode='honor'
        )

        # User with no certs should return an empty set.
        self.assertSetEqual(
            GeneratedCertificate.course_ids_with_certs_for_user(student_no_certs),
            set()
        )
        # User with certs should return a set with the two course_ids
        self.assertSetEqual(
            GeneratedCertificate.course_ids_with_certs_for_user(student_with_certs),
            {course_1.id, course_2.id}
        )
开发者ID:shevious,项目名称:edx-platform,代码行数:35,代码来源:tests.py

示例3: _listen_for_passing_grade

def _listen_for_passing_grade(sender, user, course_id, **kwargs):  # pylint: disable=unused-argument
    """
    Listen for a learner passing a course, send cert generation task,
    downstream signal from COURSE_GRADE_CHANGED
    """

    # No flags enabled
    if (
        not waffle.waffle().is_enabled(waffle.SELF_PACED_ONLY) and
        not waffle.waffle().is_enabled(waffle.INSTRUCTOR_PACED_ONLY)
    ):
        return

    # Only SELF_PACED_ONLY flag enabled
    if waffle.waffle().is_enabled(waffle.SELF_PACED_ONLY):
        if not courses.get_course_by_id(course_key, depth=0).self_paced:
            return

    # Only INSTRUCTOR_PACED_ONLY flag enabled
    elif waffle.waffle().is_enabled(waffle.INSTRUCTOR_PACED_ONLY):
        if courses.get_course_by_id(course_key, depth=0).self_paced:
            return
    if GeneratedCertificate.certificate_for_student(self.user, self.course_id) is None:
        generate_certificate.apply_async(
            student=user,
            course_key=course_id,
        )
        log.info(u'Certificate generation task initiated for {user} : {course} via passing grade'.format(
            user=user.id,
            course=course_id
        ))
开发者ID:Stanford-Online,项目名称:edx-platform,代码行数:31,代码来源:signals.py

示例4: _section_certificates

def _section_certificates(course):
    """Section information for the certificates panel.

    The certificates panel allows global staff to generate
    example certificates and enable self-generated certificates
    for a course.

    Arguments:
        course (Course)

    Returns:
        dict

    """
    example_cert_status = None
    html_cert_enabled = certs_api.has_html_certificates_enabled(course.id, course)
    if html_cert_enabled:
        can_enable_for_course = True
    else:
        example_cert_status = certs_api.example_certificates_status(course.id)

        # Allow the user to enable self-generated certificates for students
        # *only* once a set of example certificates has been successfully generated.
        # If certificates have been misconfigured for the course (for example, if
        # the PDF template hasn't been uploaded yet), then we don't want
        # to turn on self-generated certificates for students!
        can_enable_for_course = example_cert_status is not None and all(
            cert_status["status"] == "success" for cert_status in example_cert_status
        )
    instructor_generation_enabled = settings.FEATURES.get("CERTIFICATES_INSTRUCTOR_GENERATION", False)
    certificate_statuses_with_count = {
        certificate["status"]: certificate["count"]
        for certificate in GeneratedCertificate.get_unique_statuses(course_key=course.id)
    }

    return {
        "section_key": "certificates",
        "section_display_name": _("Certificates"),
        "example_certificate_status": example_cert_status,
        "can_enable_for_course": can_enable_for_course,
        "enabled_for_course": certs_api.cert_generation_enabled(course.id),
        "instructor_generation_enabled": instructor_generation_enabled,
        "html_cert_enabled": html_cert_enabled,
        "active_certificate": certs_api.get_active_web_certificate(course),
        "certificate_statuses_with_count": certificate_statuses_with_count,
        "status": CertificateStatuses,
        "certificate_generation_history": CertificateGenerationHistory.objects.filter(course_id=course.id).order_by(
            "-created"
        ),
        "urls": {
            "generate_example_certificates": reverse("generate_example_certificates", kwargs={"course_id": course.id}),
            "enable_certificate_generation": reverse("enable_certificate_generation", kwargs={"course_id": course.id}),
            "start_certificate_generation": reverse("start_certificate_generation", kwargs={"course_id": course.id}),
            "start_certificate_regeneration": reverse(
                "start_certificate_regeneration", kwargs={"course_id": course.id}
            ),
            "list_instructor_tasks_url": reverse("list_instructor_tasks", kwargs={"course_id": course.id}),
        },
    }
开发者ID:lemontreeran,项目名称:edx-platform,代码行数:59,代码来源:instructor_dashboard.py

示例5: setUp

    def setUp(self):
        CourseFactory.create(org='TESTX', number='1', display_name='TEST1',
                             start=datetime.datetime(2010, 5, 12, 2, 42, tzinfo=utc),
                             end=datetime.datetime(2011, 5, 12, 2, 42, tzinfo=utc))
        CourseFactory.create(org='TESTX', number='2', display_name='TEST2',
                             start=datetime.datetime(2010, 5, 12, 2, 42, tzinfo=utc),
                             end=datetime.datetime(2011, 5, 12, 2, 42, tzinfo=utc))
        CourseFactory.create(org='TESTX', number='3', display_name='TEST3',
                             start=datetime.datetime(2010, 5, 12, 2, 42, tzinfo=utc),
                             end=datetime.datetime(2011, 5, 12, 2, 42, tzinfo=utc))

        self.fred = fred = User(username='fred', email='[email protected]')
        fred.save()
        UserProfile(user=fred, name='Fred Flintstone').save()
        LinkedIn(user=fred, has_linkedin_account=True).save()
        self.barney = barney = User(
            username='barney', email='[email protected]')
        barney.save()

        LinkedIn(user=barney, has_linkedin_account=True).save()
        UserProfile(user=barney, name='Barney Rubble').save()

        self.adam = adam = User(
            username='adam', email='[email protected]')
        adam.save()

        LinkedIn(user=adam, has_linkedin_account=True).save()
        UserProfile(user=adam, name='Adam (חיים פּלי)').save()
        self.cert1 = cert1 = GeneratedCertificate(
            status='downloadable',
            user=fred,
            course_id='TESTX/1/TEST1',
            name='TestX/Intro101',
            download_url='http://test.foo/test')
        cert1.save()
        cert2 = GeneratedCertificate(
            status='downloadable',
            user=fred,
            course_id='TESTX/2/TEST2')
        cert2.save()
        cert3 = GeneratedCertificate(
            status='downloadable',
            user=barney,
            course_id='TESTX/3/TEST3')
        cert3.save()
        cert5 = GeneratedCertificate(
            status='downloadable',
            user=adam,
            course_id='TESTX/3/TEST3')
        cert5.save()
开发者ID:BeiLuoShiMen,项目名称:edx-platform,代码行数:50,代码来源:test_mailusers.py

示例6: create

 def create(self):
     self.certificate_obj = GeneratedCertificate(
         user_id=self.user_id,
         course_id=self.course_id,
         grade=self.grade,
         status=self.certificate_status
     )
     if self.certificate_status == 'downloadable':
         self.certificate_obj.download_url = self.pdf_url_filename
     else:
         self.certificate_obj.download_url = ''
     self.certificate_obj.save()
开发者ID:defance,项目名称:edx-ifmo-mod,代码行数:12,代码来源:certificate.py

示例7: is_entitlement_regainable

    def is_entitlement_regainable(self, entitlement):
        """
        Determines from the policy if an entitlement can still be regained by the user, if they choose
        to by leaving and regaining their entitlement within policy.regain_period days from start date of
        the course or their redemption, whichever comes later, and the expiration period hasn't passed yet
        """
        if entitlement.enrollment_course_run:
            if GeneratedCertificate.certificate_for_student(
                    entitlement.user_id, entitlement.enrollment_course_run.course_id) is not None:
                return False

            # This is >= because a days_until_expiration 0 means that the expiration day has not fully passed yet
            # and that the entitlement should not be expired as there is still time
            return self.get_days_until_expiration(entitlement) >= 0
        return False
开发者ID:lduarte1991,项目名称:edx-platform,代码行数:15,代码来源:models.py

示例8: is_certificate_invalid

def is_certificate_invalid(student, course_key):
    """Check that whether the student in the course has been invalidated
    for receiving certificates.

    Arguments:
        student (user object): logged-in user
        course_key (CourseKey): The course identifier.

    Returns:
        Boolean denoting whether the student in the course is invalidated
        to receive certificates
    """
    is_invalid = False
    certificate = GeneratedCertificate.certificate_for_student(student, course_key)
    if certificate is not None:
        is_invalid = CertificateInvalidation.has_certificate_invalidation(student, course_key)

    return is_invalid
开发者ID:edx-solutions,项目名称:edx-platform,代码行数:18,代码来源:api.py

示例9: fire_ungenerated_certificate_task

def fire_ungenerated_certificate_task(user, course_key):
    """
    Helper function to fire un-generated certificate tasks

    The 'mode_is_verified' query is copied from the GeneratedCertificate model,
    but is done here in an attempt to reduce traffic to the workers.
    If the learner is verified and their cert has the 'unverified' status,
    we regenerate the cert.
    """
    enrollment_mode, __ = CourseEnrollment.enrollment_mode_for_user(user, course_key)
    mode_is_verified = enrollment_mode in GeneratedCertificate.VERIFIED_CERTS_MODES
    cert = GeneratedCertificate.certificate_for_student(user, course_key)
    if mode_is_verified and (cert is None or cert.status == 'unverified'):
        generate_certificate.apply_async(kwargs={
            'student': unicode(user.id),
            'course_key': unicode(course_key),
        })
        return True
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:18,代码来源:signals.py

示例10: refundable

    def refundable(self):
        """
        For paid/verified certificates, students may receive a refund if they have
        a verified certificate and the deadline for refunds has not yet passed.
        """
        # In order to support manual refunds past the deadline, set can_refund on this object.
        # On unenrolling, the "unenroll_done" signal calls CertificateItem.refund_cert_callback(),
        # which calls this method to determine whether to refund the order.
        # This can't be set directly because refunds currently happen as a side-effect of unenrolling.
        # (side-effects are bad)
        if getattr(self, 'can_refund', None) is not None:
            return True

        # If the student has already been given a certificate they should not be refunded
        if GeneratedCertificate.certificate_for_student(self.user, self.course_id) is not None:
            return False

        course_mode = CourseMode.mode_for_course(self.course_id, 'verified')
        if course_mode is None:
            return False
        else:
            return True
开发者ID:roadlit,项目名称:edx-platform,代码行数:22,代码来源:models.py

示例11: test_ineligible_cert_whitelisted

    def test_ineligible_cert_whitelisted(self):
        """Test that audit mode students can receive a certificate if they are whitelisted."""
        # Enroll as audit
        CourseEnrollmentFactory(
            user=self.user_2,
            course_id=self.course.id,
            is_active=True,
            mode='audit'
        )
        # Whitelist student
        CertificateWhitelistFactory(course_id=self.course.id, user=self.user_2)

        # Generate certs
        with patch('courseware.grades.grade', Mock(return_value={'grade': 'Pass', 'percent': 0.75})):
            with patch.object(XQueueInterface, 'send_to_queue') as mock_send:
                mock_send.return_value = (0, None)
                self.xqueue.add_cert(self.user_2, self.course.id)

        # Assert cert generated correctly
        self.assertTrue(mock_send.called)
        certificate = GeneratedCertificate.certificate_for_student(self.user_2, self.course.id)
        self.assertIsNotNone(certificate)
        self.assertEqual(certificate.mode, 'audit')
开发者ID:attiyaIshaque,项目名称:edx-platform,代码行数:23,代码来源:test_queue.py

示例12: _section_certificates

def _section_certificates(course):
    """Section information for the certificates panel.

    The certificates panel allows global staff to generate
    example certificates and enable self-generated certificates
    for a course.

    Arguments:
        course (Course)

    Returns:
        dict

    """
    example_cert_status = None
    html_cert_enabled = certs_api.has_html_certificates_enabled(course.id, course)
    if html_cert_enabled:
        can_enable_for_course = True
    else:
        example_cert_status = certs_api.example_certificates_status(course.id)

        # Allow the user to enable self-generated certificates for students
        # *only* once a set of example certificates has been successfully generated.
        # If certificates have been misconfigured for the course (for example, if
        # the PDF template hasn't been uploaded yet), then we don't want
        # to turn on self-generated certificates for students!
        can_enable_for_course = (
            example_cert_status is not None and
            all(
                cert_status['status'] == 'success'
                for cert_status in example_cert_status
            )
        )
    instructor_generation_enabled = settings.FEATURES.get('CERTIFICATES_INSTRUCTOR_GENERATION', False)
    certificate_statuses_with_count = {
        certificate['status']: certificate['count']
        for certificate in GeneratedCertificate.get_unique_statuses(course_key=course.id)
    }

    return {
        'section_key': 'certificates',
        'section_display_name': _('Certificates'),
        'example_certificate_status': example_cert_status,
        'can_enable_for_course': can_enable_for_course,
        'enabled_for_course': certs_api.cert_generation_enabled(course.id),
        'is_self_paced': course.self_paced,
        'instructor_generation_enabled': instructor_generation_enabled,
        'html_cert_enabled': html_cert_enabled,
        'active_certificate': certs_api.get_active_web_certificate(course),
        'certificate_statuses_with_count': certificate_statuses_with_count,
        'status': CertificateStatuses,
        'certificate_generation_history':
            CertificateGenerationHistory.objects.filter(course_id=course.id).order_by("-created"),
        'urls': {
            'generate_example_certificates': reverse(
                'generate_example_certificates',
                kwargs={'course_id': course.id}
            ),
            'enable_certificate_generation': reverse(
                'enable_certificate_generation',
                kwargs={'course_id': course.id}
            ),
            'start_certificate_generation': reverse(
                'start_certificate_generation',
                kwargs={'course_id': course.id}
            ),
            'start_certificate_regeneration': reverse(
                'start_certificate_regeneration',
                kwargs={'course_id': course.id}
            ),
            'list_instructor_tasks_url': reverse(
                'list_instructor_tasks',
                kwargs={'course_id': course.id}
            ),
        }
    }
开发者ID:NhaTrang,项目名称:edx-platform,代码行数:76,代码来源:instructor_dashboard.py

示例13: CertificateBase

class CertificateBase(object):

    type = ''  # Honor, Simple or Others
    user_id = 0
    percent = 0  # 0-100

    # HTML File
    source_dir = ''
    source_files = {}
    course_id = ''
    course_name = ''

    certificate_obj = None
    course_key = None

    certsys = None

    @classmethod
    def from_string(cls, str, certsys):
        params = str.split(',')
        return cls(params[0], params[1], params[2], certsys)

    def __init__(self, user_id, percent, type, certsys):
        self.user_id = user_id
        self.percent = percent
        self.type = type.strip().strip('"')
        self.certsys = certsys

        self.course_key = CourseKey.from_string(self.course_id)

        try:
            self.certificate_obj = GeneratedCertificate.objects.get(user_id=self.user_id, course_id=self.course_key)
        except GeneratedCertificate.DoesNotExist:
            pass

    def generate(self):

        # Get source file
        source_file = self.source_files[self.type] if self.type in self.source_files else None

        if source_file is None:
            print "Wanted to generate certificate for user_id=%s with mode=%s but have no file specified" % \
                  (self.user_id, self.type)
            return False

        source_file = "%s/%s" % (self.source_dir, source_file)

        if not os.path.isfile(source_file):
            print "Wanted to generate certificate for user_id=%s with mode=%s but have no file: %s" % \
                  (self.user_id, self.type, source_file)

        utils.ensure_dir(self.pdf_local_location)

        try:
            string = utils.get_file_contents(source_file).format(
                student_name=self.student_printed_name.encode('utf-8'),
                title='{course_name}'.format(
                    student_name=self.student_printed_name.encode('utf8'),
                  course_name=self.course_name
                )
           )
        except Exception as e:
           print "File not found: %s" % source_file
           raise e

        try:
            p = Popen(['weasyprint', '--base-url', self.source_dir, '-', self.pdf_local_filename], stdin=PIPE)
            p.communicate(input=string)
        except Exception as e:
            print "Weasyprint not found"
            raise e

        print "Generated certificate for user_id=%s" % (self.user_id,)

    def create(self):
        self.certificate_obj = GeneratedCertificate(
            user_id=self.user_id,
            course_id=self.course_id,
            grade=self.grade,
            status=self.certificate_status
        )
        if self.certificate_status == 'downloadable':
            self.certificate_obj.download_url = self.pdf_url_filename
        else:
            self.certificate_obj.download_url = ''
        self.certificate_obj.save()

    def update(self):
        self.certificate_obj.grade = self.grade
        if self.certificate_status == 'downloadable':
            self.certificate_obj.download_url = self.pdf_url_filename
        else:
            self.certificate_obj.download_url = ''
        self.certificate_obj.status = self.certificate_status
        self.certificate_obj.save()

    def process(self):

        if self.certificate_obj is None:
            print "Certificate object is created"
#.........这里部分代码省略.........
开发者ID:defance,项目名称:edx-ifmo-mod,代码行数:101,代码来源:certificate.py


注:本文中的certificates.models.GeneratedCertificate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。