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


Python GeneratedCertificate.save方法代码示例

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


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

示例1: setUp

# 需要导入模块: from certificates.models import GeneratedCertificate [as 别名]
# 或者: from certificates.models.GeneratedCertificate import save [as 别名]
    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,代码行数:52,代码来源:test_mailusers.py

示例2: CertificateBase

# 需要导入模块: from certificates.models import GeneratedCertificate [as 别名]
# 或者: from certificates.models.GeneratedCertificate import save [as 别名]
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,代码行数:103,代码来源:certificate.py


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