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


Python models.Tracker类代码示例

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


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

示例1: obj_create

    def obj_create(self, bundle, **kwargs):
        
        if 'username' not in bundle.data:
            raise BadRequest(_(u'Username missing'))
        
        if 'password' not in bundle.data:
            raise BadRequest(_(u'Password missing'))
        
        username = bundle.data['username']
        password = bundle.data['password']
        
        u = authenticate(username=username, password=password)
        if u is not None:
            if u.is_active:
                login(bundle.request,u)
                # Add to tracker
                tracker = Tracker()
                tracker.user = u
                tracker.type = 'login'
                tracker.ip = bundle.request.META.get('REMOTE_ADDR','0.0.0.0')
                tracker.agent =bundle.request.META.get('HTTP_USER_AGENT','unknown')
                tracker.save()
            else:
                raise BadRequest(_(u'Authentication failure'))
        else:
            raise BadRequest(_(u'Authentication failure'))

        del bundle.data['password']
        key = ApiKey.objects.get(user = u)
        bundle.data['api_key'] = key.key
        bundle.obj = u 
        return bundle 
开发者ID:QCInvestments,项目名称:django-oppia,代码行数:32,代码来源:resources.py

示例2: download_detail

    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,代码行数:45,代码来源:resources.py

示例3: obj_create

    def obj_create(self, bundle, **kwargs):

        if "username" not in bundle.data:
            raise BadRequest(_(u"Username missing"))

        if "password" not in bundle.data:
            raise BadRequest(_(u"Password missing"))

        username = bundle.data["username"]
        password = bundle.data["password"]

        u = authenticate(username=username, password=password)
        if u is not None:
            if u.is_active:
                login(bundle.request, u)
                # Add to tracker
                tracker = Tracker()
                tracker.user = u
                tracker.type = "login"
                tracker.ip = bundle.request.META.get("REMOTE_ADDR", "0.0.0.0")
                tracker.agent = bundle.request.META.get("HTTP_USER_AGENT", "unknown")
                tracker.save()
            else:
                raise BadRequest(_(u"Authentication failure"))
        else:
            raise BadRequest(_(u"Authentication failure"))

        del bundle.data["password"]
        key = ApiKey.objects.get(user=u)
        bundle.data["api_key"] = key.key
        bundle.obj = u
        return bundle
开发者ID:aoa4eva,项目名称:django-oppia,代码行数:32,代码来源:resources.py

示例4: scorecard_view

def scorecard_view(request):
    auth = ApiKeyAuthentication()
    if auth.is_authenticated(request) is not True:
        return HttpResponse("Unauthorized", status=401)

    record_mobile_tracker(request, None, "scorecard", '{"en":"homepage"}')

    start_date = datetime.datetime.now() - datetime.timedelta(days=14)
    end_date = datetime.datetime.now()
    media = {
        "views": Tracker.activity_views(user=request.user, type="media", start_date=start_date, end_date=end_date),
        "secs": Tracker.activity_secs(user=request.user, type="media", start_date=start_date, end_date=end_date),
        "points": Points.media_points(user=request.user, start_date=start_date, end_date=end_date),
    }
    quiz = {
        "views": Tracker.activity_views(user=request.user, type="quiz", start_date=start_date, end_date=end_date),
        "secs": Tracker.activity_secs(user=request.user, type="quiz", start_date=start_date, end_date=end_date),
        "points": Points.quiz_points(user=request.user, start_date=start_date, end_date=end_date),
    }
    acts = {
        "views": Tracker.activity_views(user=request.user, type="page", start_date=start_date, end_date=end_date),
        "secs": Tracker.activity_secs(user=request.user, type="page", start_date=start_date, end_date=end_date),
        "points": Points.page_points(user=request.user, start_date=start_date, end_date=end_date),
    }
    total = {
        "views": acts["views"] + quiz["views"] + media["views"],
        "secs": acts["secs"] + quiz["secs"] + media["secs"],
        "points": acts["points"] + quiz["points"] + media["points"],
    }
    scorecard = {"media": media, "quiz": quiz, "acts": acts, "total": total}
    return render_to_response(
        "oppia/mobile/scorecard.html", {"scorecard": scorecard}, context_instance=RequestContext(request)
    )
开发者ID:kingctan,项目名称:django-oppia,代码行数:33,代码来源:views.py

示例5: download_activity

 def download_activity(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"))
     
     return HttpResponse(Tracker.to_xml_string(course,request.user), content_type='text/xml')
开发者ID:QCInvestments,项目名称:django-oppia,代码行数:22,代码来源:resources.py

示例6: scorecard_view

def scorecard_view(request):
    auth = ApiKeyAuthentication()
    if auth.is_authenticated(request) is not True:
        return HttpResponse('Unauthorized', status=401)
    start_date = datetime.datetime.now() - datetime.timedelta(days=14)
    end_date = datetime.datetime.now()
    media = {'views':Tracker.activity_views(user=request.user,type='media',start_date=start_date,end_date=end_date),
             'secs':Tracker.activity_secs(user=request.user,type='media',start_date=start_date,end_date=end_date),
             'points':Points.media_points(user=request.user,start_date=start_date,end_date=end_date)}
    quiz = {'views':Tracker.activity_views(user=request.user,type='quiz',start_date=start_date,end_date=end_date),
             'secs':Tracker.activity_secs(user=request.user,type='quiz',start_date=start_date,end_date=end_date),
             'points':Points.quiz_points(user=request.user,start_date=start_date,end_date=end_date)}
    acts = {'views':Tracker.activity_views(user=request.user,type='page',start_date=start_date,end_date=end_date),
             'secs':Tracker.activity_secs(user=request.user,type='page',start_date=start_date,end_date=end_date),
             'points':Points.page_points(user=request.user,start_date=start_date,end_date=end_date)}
    total = {'views':acts['views'] + quiz['views'] + media['views'],
             'secs': acts['secs'] + quiz['secs'] + media['secs'],
             'points': acts['points'] + quiz['points'] + media['points'],}
    scorecard = {'media':media, 'quiz':quiz, 'acts':acts, 'total': total}
    return render_to_response('oppia/mobile/scorecard.html',{ 'scorecard':scorecard }, context_instance=RequestContext(request))
开发者ID:mohideen-openwave,项目名称:django-oppia,代码行数:20,代码来源:views.py

示例7: course_activity_view

def course_activity_view(request, course_id, activity_id):
    course = can_view_course(request, course_id)
    activity = Activity.objects.get(pk=activity_id)
    
    # log the activity in the tracker
    tracker = Tracker()
    tracker.user = request.user
    tracker.course = course
    tracker.type = activity.type 
    tracker.data = ""
    tracker.ip = request.META.get('REMOTE_ADDR','0.0.0.0')
    tracker.agent = request.META.get('HTTP_USER_AGENT','unknown')
    tracker.activity_title = activity.title
    tracker.section_title = activity.section.title
    tracker.save()
    
    if activity.type == "page":
        activity_content_file = activity.get_content()
        
        with codecs.open(settings.MEDIA_ROOT + "courses/" + course.shortname + "/" + activity_content_file, "r", "utf-8") as f:
            s = f.read()
        
        template = re.compile('\<body(?P<body>.*?)>(?P<content>.*)\<\/body\>', re.DOTALL)
        
        activity_content = template.search(s).group('content')
        activity_content =  activity_content.replace("images/",settings.MEDIA_URL + "courses/" + course.shortname + "/images/")
        
        return render_to_response('oppia/preview/course_activity_page.html',
                                  {'course': course, 'activity': activity , 'content' : activity_content }, 
                                  context_instance=RequestContext(request))
    else:
        activity_content= None
        return render_to_response('oppia/preview/course_activity_not_supported.html',
                                  {'course': course, 'activity': activity , 'content' : activity_content }, 
                                  context_instance=RequestContext(request)) 
开发者ID:DigitalCampus,项目名称:django-ujjwal-oppia,代码行数:35,代码来源:views.py

示例8: download_course

    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,代码行数:58,代码来源:resources.py

示例9: dehydrate_quiz_secs

 def dehydrate_quiz_secs(self,bundle):
     start_date = datetime.datetime.now() - datetime.timedelta(days=14)
     end_date = datetime.datetime.now()
     return Tracker.activity_secs(user=bundle.obj,type='quiz',start_date=start_date,end_date=end_date)
开发者ID:mohideen-openwave,项目名称:django-oppia,代码行数:4,代码来源:resources.py

示例10: dehydrate_page_views

 def dehydrate_page_views(self,bundle):
     start_date = datetime.datetime.now() - datetime.timedelta(days=14)
     end_date = datetime.datetime.now()
     return Tracker.activity_views(user=bundle.obj,type='page',start_date=start_date,end_date=end_date)
开发者ID:mohideen-openwave,项目名称:django-oppia,代码行数:4,代码来源:resources.py

示例11: record_mobile_tracker

def record_mobile_tracker(request, course_id, type, page):
    t = Tracker()
    t.user = request.user
    t.ip = request.META.get('REMOTE_ADDR','0.0.0.0')
    t.agent = request.META.get('HTTP_USER_AGENT','unknown')
    t.digest = ""
    t.data = ""
    t.course = course_id
    t.type = type
    t.completed = True
    t.activity_title = page
    t.save()
    return
    
    
    
开发者ID:DigitalCampus,项目名称:django-swaziland-oppia,代码行数:13,代码来源:views.py

示例12: obj_create

    def obj_create(self, bundle, **kwargs):
        if not settings.OPPIA_ALLOW_SELF_REGISTRATION:
            raise BadRequest(_(u'Registration is disabled on this server.'))
        required = ['username',
                    'password',
                    'passwordagain', 
                    'email', 
                    'firstname', 
                    'lastname',
                    'sex',
                    'age_range',
                    'role',
                    'location']

        check_required_params(bundle, required)

        data = {'username': bundle.data['username'],
                'password': bundle.data['password'],
                'password_again': bundle.data['passwordagain'],
                'email': bundle.data['email'],
                'sex': bundle.data['sex'],
                'age_range': bundle.data['age_range'],
                'role': bundle.data['role'],
                'location': bundle.data['location'],
                'first_name': bundle.data['firstname'],
                'last_name': bundle.data['lastname'], }
        rf = RegisterForm(data)
        if not rf.is_valid():
            str = ""
            for key, value in rf.errors.items():
                for error in value:
                    str += error + "\n"
            raise BadRequest(str)
        else:
            username = bundle.data['username']
            password = bundle.data['password']
            email = bundle.data['email']
            first_name = bundle.data['firstname']
            last_name = bundle.data['lastname']
        try:
            bundle.obj = User.objects.create_user(username, email, password)
            bundle.obj.first_name = first_name
            bundle.obj.last_name = last_name
            bundle.obj.save()

            user_profile = UserProfile()
            user_profile.user = bundle.obj
            user_profile.sex = bundle.data['sex']
            user_profile.age_range = bundle.data['age_range']
            user_profile.role = bundle.data['role']
            user_profile.location = bundle.data['location']
            user_profile.save()

            u = authenticate(username=username, password=password)
            if u is not None and u.is_active:
                login(bundle.request, u)
                # Add to tracker
                tracker = Tracker()
                tracker.user = u
                tracker.type = 'register'
                tracker.ip = bundle.request.META.get('REMOTE_ADDR', oppia.api.DEFAULT_IP_ADDRESS)
                tracker.agent = bundle.request.META.get('HTTP_USER_AGENT', 'unknown')
                tracker.save()
            key = ApiKey.objects.get(user=u)
            bundle.data['api_key'] = key.key
        except IntegrityError:
            raise BadRequest(_(u'Username "%s" already in use, please select another' % username))
        del bundle.data['passwordagain']
        del bundle.data['password']
        del bundle.data['firstname']
        del bundle.data['lastname']
        del bundle.data['age_range'] 
        del bundle.data['role'] 
        del bundle.data['location'] 
        return bundle   
开发者ID:DigitalCampus,项目名称:django-nurhi-oppia,代码行数:75,代码来源:resources.py


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