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


Python Tracker.has_completed_trackers方法代码示例

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


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

示例1: download_course

# 需要导入模块: from oppia.models import Tracker [as 别名]
# 或者: from oppia.models.Tracker import has_completed_trackers [as 别名]
    def download_course(self, request, **kwargs):
        self.is_authenticated(request)
        self.throttle_check(request)
        
        pk = kwargs.pop('pk', None)
        try:
            if request.user.is_staff:
                course = self._meta.queryset.get(pk = pk,is_archived=False)
            else:
                course = self._meta.queryset.get(pk = pk, is_archived=False,is_draft=False)
        except Course.DoesNotExist:
            raise Http404(_(u"Course not found"))
        except ValueError:
            try:
                if request.user.is_staff:
                    course = self._meta.queryset.get(shortname = pk,is_archived=False)
                else:
                    course = self._meta.queryset.get(shortname = pk, is_archived=False,is_draft=False)
            except Course.DoesNotExist:
                raise Http404(_(u"Course not found"))
         
        file_to_download = course.getAbsPath();
        schedule = course.get_default_schedule()
        has_completed_trackers = Tracker.has_completed_trackers(course,request.user)
        cohort = Cohort.member_now(course,request.user)
        if cohort:
            if cohort.schedule:
                schedule = cohort.schedule
        
        # add scheduling XML file     
        if schedule or has_completed_trackers:
            file_to_download = settings.COURSE_UPLOAD_DIR +"temp/"+ str(request.user.id) + "-" + course.filename
            shutil.copy2(course.getAbsPath(), file_to_download)
            zip = zipfile.ZipFile(file_to_download,'a')
            if schedule:
                zip.writestr(course.shortname +"/schedule.xml",schedule.to_xml_string())
            if has_completed_trackers:
                zip.writestr(course.shortname +"/tracker.xml",Tracker.to_xml_string(course,request.user))
            zip.close()

        wrapper = FileWrapper(file(file_to_download))
        response = HttpResponse(wrapper, content_type='application/zip')
        response['Content-Length'] = os.path.getsize(file_to_download)
        response['Content-Disposition'] = 'attachment; filename="%s"' %(course.filename)
        
        # Add to tracker
        tracker = Tracker()
        tracker.user = request.user
        tracker.course = course
        tracker.type = 'download'
        tracker.data = json.dumps({'version':course.version })
        tracker.ip = request.META.get('REMOTE_ADDR','0.0.0.0')
        tracker.agent = request.META.get('HTTP_USER_AGENT','unknown')
        tracker.save()
                
        course_downloaded.send(sender=self, course=course, user=request.user)
        
        return response
开发者ID:QCInvestments,项目名称:django-oppia,代码行数:60,代码来源:resources.py

示例2: download_detail

# 需要导入模块: from oppia.models import Tracker [as 别名]
# 或者: from oppia.models.Tracker import has_completed_trackers [as 别名]
    def download_detail(self, request, **kwargs):
        self.is_authenticated(request)
        self.throttle_check(request)

        pk = kwargs.pop("pk", None)
        try:
            course = self._meta.queryset.get(pk=pk)
        except Course.DoesNotExist:
            raise NotFound(_(u"Course download not found"))

        file_to_download = course.getAbsPath()
        schedule = course.get_default_schedule()
        has_completed_trackers = Tracker.has_completed_trackers(course, request.user)
        cohort = Cohort.member_now(course, request.user)
        if cohort:
            if cohort.schedule:
                schedule = cohort.schedule

        # add scheduling XML file
        if schedule or has_completed_trackers:
            file_to_download = settings.COURSE_UPLOAD_DIR + "temp/" + str(request.user.id) + "-" + course.filename
            shutil.copy2(course.getAbsPath(), file_to_download)
            zip = zipfile.ZipFile(file_to_download, "a")
            if schedule:
                zip.writestr(course.shortname + "/schedule.xml", schedule.to_xml_string())
            if has_completed_trackers:
                zip.writestr(course.shortname + "/tracker.xml", Tracker.to_xml_string(course, request.user))
            zip.close()

        wrapper = FileWrapper(file(file_to_download))
        response = HttpResponse(wrapper, content_type="application/zip")
        response["Content-Length"] = os.path.getsize(file_to_download)
        response["Content-Disposition"] = 'attachment; filename="%s"' % (course.filename)

        md = CourseDownload()
        md.user = request.user
        md.course = course
        md.course_version = course.version
        md.ip = request.META.get("REMOTE_ADDR", "0.0.0.0")
        md.agent = request.META.get("HTTP_USER_AGENT", "unknown")
        md.save()

        course_downloaded.send(sender=self, course=course, user=request.user)

        return response
开发者ID:niamathsa,项目名称:django-oppia,代码行数:47,代码来源:resources.py


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