def isAnyEventLive(request): scheduleObj = models.Schedule.objects.filter(running=1) if not scheduleObj: return False if request.user.is_staff: # Get Live events of Scheduled courses providerObj = getProvider(request) scheduleObj = scheduleObj.filter(provider_id=providerObj.id) else: # Get live events of enrolled courses scheduleObj = scheduleObj.filter(autopublish=True) studentObj = student.models.Student.objects.filter( user_id=request.user.id)[0] courseIds = course.algos.getEnrolledCourseIds(request) enrolledCourseObj = course.models.EnrolledCourse.objects.filter( student_id=studentObj.id, active=True, course_id__in=courseIds) chaptersList = [] for ec in enrolledCourseObj: if ec.chapteraccess == '': courseChapterObj = course.models.CourseChapter.objects.filter( course_id=ec.course_id) for cco in courseChapterObj: chaptersList.append(cco.id) else: allowedModules = ec.chapteraccess.split(',') allowedModulesInt = [int(i) for i in allowedModules] chaptersList.extend(allowedModulesInt) #courseChapterObj = course.models.CourseChapter.objects.filter(Q(course_id__in=enrolledCourseObj.values('course_id'))).values('id') scheduleObj = scheduleObj.filter(Q(chapter_id__in=chaptersList)) if scheduleObj: return True return False
def get(self, request, scheduleid, *args, **kwargs): scheduleObj = schedule.models.Schedule.objects.filter(id=scheduleid) providerObj = getProvider(request) if scheduleObj[0].provider_id != providerObj.id: raise Http404() if scheduleObj: scheduleObj.delete() return redirect("schedule:add_show_schedule")
def get(self, request, *args, **kwargs): if not request.user.is_staff: raise Http404() providerObj = getProvider(request) kwargs["disableKeys"] = "false" locations = [] locationObj = provider.models.System.objects.filter( provider_id=providerObj.id) for location in locationObj: locations.append(location.name) kwargs['locations'] = locations mycourses = course.models.Course.objects.raw('SELECT * from course_course WHERE provider_id = ' + str(providerObj.id) + \ ' AND id NOT IN (SELECT parent_id from course_linkcourse)') courseDict = [] for c in mycourses: courseDetails = course.algos.getCourseDetails(c.id, False) courseInfo = {} courseInfo['name'] = c.name courseInfo['details'] = courseDetails courseDict.append(courseInfo) kwargs['mycourses'] = courseDict # Get schedule for this provider scheduleObj = models.Schedule.objects.filter( provider_id=providerObj.id) if scheduleObj: schedules = [] for schedule in scheduleObj: scheduleInfo = model_to_dict(schedule) chapterObj = course.models.CourseChapter.objects.filter( id=schedule.chapter_id)[0] sessions = chapterObj.sessions sessionsCount = 0 if sessions != '': sessionsCount = len(sessions.split(',')) scheduleInfo['id'] = schedule.id scheduleInfo['chapterName'] = chapterObj.name scheduleInfo['subjectName'] = chapterObj.subject scheduleInfo[ 'courseName'] = course.models.Course.objects.filter( id=chapterObj.course_id)[0].name scheduleInfo['courseId'] = chapterObj.course_id scheduleInfo['eventsOccured'] = sessionsCount scheduleInfo[ 'eventsRemaining'] = schedule.eventcount - sessionsCount scheduleInfo['autoPublish'] = schedule.autopublish scheduleInfo['encrypt'] = schedule.autopublish scheduleInfo['start'] = schedule.start schedules.append(scheduleInfo) kwargs['schedules'] = schedules kwargs['doRefresh'] = request.GET.get('doRefresh', '0') #kwargs['doRefresh'] = 10 return super().get(request, *args, **kwargs)
def get(self, request, *args, **kwargs): scheduleObj = models.Schedule.objects.filter(running=1) kwargs["disableKeys"] = "true" if not scheduleObj: return super().get(request, *args, **kwargs) if request.user.is_staff: # Get Live events of Scheduled courses providerObj = getProvider(request) scheduleObj = scheduleObj.filter(provider_id=providerObj.id) else: # Get live events of enrolled courses scheduleObj = scheduleObj.filter(autopublish=True) studentObj = student.models.Student.objects.filter( user_id=request.user.id)[0] courseIds = course.algos.getEnrolledCourseIds(request) enrolledCourseObj = course.models.EnrolledCourse.objects.filter( student_id=studentObj.id, active=True, course_id__in=courseIds) chaptersList = [] for ec in enrolledCourseObj: if ec.chapteraccess == '': courseChapterObj = course.models.CourseChapter.objects.filter( course_id=ec.course_id) for cco in courseChapterObj: chaptersList.append(cco.id) else: allowedModules = ec.chapteraccess.split(',') allowedModulesInt = [int(i) for i in allowedModules] chaptersList.extend(allowedModulesInt) #courseChapterObj = course.models.CourseChapter.objects.filter(Q(course_id__in=enrolledCourseObj.values('course_id'))).values('id') scheduleObj = scheduleObj.filter(Q(chapter_id__in=chaptersList)) if scheduleObj: schedules = [] kwargs["live"] = 'on' for schedule in scheduleObj: scheduleInfo = model_to_dict(schedule) chapterObj = course.models.CourseChapter.objects.filter( id=schedule.chapter_id)[0] sessions = chapterObj.sessions sessionsCount = 0 if sessions != '': sessionsCount = len(sessions.split(',')) scheduleInfo['id'] = schedule.id scheduleInfo['chapterName'] = chapterObj.name scheduleInfo['subjectName'] = chapterObj.subject scheduleInfo[ 'courseName'] = course.models.Course.objects.filter( id=chapterObj.course_id)[0].name scheduleInfo['courseId'] = chapterObj.course_id schedules.append(scheduleInfo) kwargs['schedules'] = schedules return super().get(request, *args, **kwargs)
def post(self, request, *args, **kwargs): if not request.user.is_staff: raise Http404() providerObj = getProvider(request) courseChapterName = request.POST.get('courseChapterName', "") # if this element doesnt comes, then its edit flow chapterid = '' if courseChapterName == '': chapterid = request.POST.get('scheduleChapterId') else: chapterid = courseChapterName.split(':')[2] scheduleObj = models.Schedule.objects.filter(chapter_id=chapterid) if not scheduleObj: scheduleObj = models.Schedule() scheduleObj.chapter_id = chapterid scheduleObj.provider_id = providerObj.id else: scheduleObj = scheduleObj[0] startDate = request.POST.get('startDate', '') if startDate != '': scheduleObj.start = startDate scheduleObj.eventcount = request.POST.get('eventCount') scheduleObj.duration = request.POST.get('eventDuration') scheduleObj.recurafter = request.POST.get('eventRecur') scheduleObj.system = request.POST.get('courseLocation', '') if request.POST.get('autoPublish'): scheduleObj.autopublish = True else: scheduleObj.autopublish = False ''' if request.POST.get('encrypt'): scheduleObj.encrypted = True else: scheduleObj.encrypted = False ''' scheduleObj.encrypted = True scheduleObj.save() return redirect("schedule:add_show_schedule")
def get(self, request, scheduleid, *args, **kwargs): scheduleObj = schedule.models.Schedule.objects.filter(id=scheduleid) OFUSCATE_JW = True kwargs["disableKeys"] = "true" if not scheduleObj: raise Http404() if settings.DEBUG: kwargs["debug"] = "on" else: kwargs["debug"] = "off" if OFUSCATE_JW: kwargs["offuscate"] = True else: kwargs["offuscate"] = False ip = request.META.get('HTTP_X_FORWARDED_FOR', request.META.get('REMOTE_ADDR', '')).split(',')[-1].strip() #http_x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') #ip2 = request.META.get('REMOTE_ADDR') #print('http_x_forwarded_for is: ' + http_x_forwarded_for) #print ('ip2 is : ' + ip2) scheduleObj = scheduleObj[0] userString = '?' courseChapterObj = course.models.CourseChapter.objects.filter( id=scheduleObj.chapter_id) providerid = 0 provider_user_id = 0 if request.user.is_staff: courseChapterObj = courseChapterObj[0] # Get Live events of Scheduled courses providerObj = getProvider(request) provider_user_id = providerObj.user_id providerid = providerObj.id if scheduleObj.provider_id != providerObj.id: raise Http404() scheduleObj.streamkey = '' scheduleObj.save() userString = userString + 'providerid=' + str(providerObj.id) + '&' kwargs["isOwner"] = 'yes' kwargs["courseid"] = courseChapterObj.course_id else: # check if student is enrolled for this schedule if not courseChapterObj: raise Http404() courseChapterObj = courseChapterObj[0] studentObj = student.models.Student.objects.filter( user_id=request.user.id)[0] courseIds = course.algos.getEnrolledCourseIds(request) enrolledCourseObj = course.models.EnrolledCourse.objects.filter( student_id=studentObj.id, course_id=courseChapterObj.course_id, active=True) enrolledCourseObj = enrolledCourseObj.filter( course_id__in=courseIds) if not enrolledCourseObj: raise Http404() enrolledCourseObj = enrolledCourseObj[0] kwargs["enrolledcourseid"] = enrolledCourseObj.id kwargs["isOwner"] = 'no' # dont do device verification if restricted viewing for student is set if enrolledCourseObj.viewhours > 0: kwargs["disableaccess"] = True else: kwargs["disableaccess"] = False #check view hours and alloted hours before proceed further courseObj = course.models.Course.objects.filter( id=courseChapterObj.course_id)[0] viewMinutes, allotedHours = student.views.getStudentViewAllotedHoursProviderWise( studentObj.id, courseObj.provider_id) providerid = courseObj.provider_id if allotedHours > 0 and viewMinutes >= allotedHours * 60: raise Http404() userString = userString + 'studentid=' + str(studentObj.id) + '&' providerObj = provider.models.Provider.objects.filter( id=providerid)[0] provider_user_id = providerObj.user_id # delete all access enteries for this student for this schedule schedule_liveaccessObj = models.Schedule_liveaccess.objects.filter( schedule_id=scheduleObj.id, student_id=studentObj.id) schedule_liveaccessObj.delete() # add new IP entry for this student in schedule access table schedule_liveaccessObjNew = models.Schedule_liveaccess() schedule_liveaccessObjNew.ip = ip schedule_liveaccessObjNew.nginxip = '' schedule_liveaccessObjNew.schedule_id = scheduleObj.id schedule_liveaccessObjNew.student_id = studentObj.id schedule_liveaccessObjNew.save() # store student stats in table deviceinfo = parse_user_agents(request) student.views.fillStudentPlayStats(studentObj.id, -1, ip, request.user.email, deviceinfo) #HttpResponse.set_cookie('GyaanHiveIP', ip) kwargs["isLive"] = "true" kwargs["signedurl"] = getStreamUrl( scheduleObj.streamname, providerid) + userString + 'scheduleid=' + str( scheduleObj.id) + '&userIP=' + ip kwargs["liveUrl"] = getStreamUrl( scheduleObj.streamname, providerid) + userString + 'scheduleid=' + str( scheduleObj.id) + '&userIP=' + ip kwargs["user_email"] = request.user.email kwargs["userip"] = ip kwargs["providerLogo"] = course.algos.getLogoForProvider( providerObj.user_id) self.check(kwargs) response = super().get(request, scheduleid, *args, **kwargs) response.set_cookie('GyaanHiveIP', ip) return response