コード例 #1
0
ファイル: course.py プロジェクト: kartikshah1/Test
    def create(self, request, pk=None, *args):
        """
        Function for creating an offering in a category
        """
        serializer = OfferingSerializer(data=request.DATA)
        if serializer.is_valid():
            serializer.save()
            coursehistory = CourseHistory(user=request.user,
                                          course=serializer.object,
                                          active='A',
                                          is_owner=True)
            coursehistory.save()

            # Usersetting for the discussion forum
            usersetting = UserSetting(user=request.user,
                                      forum=serializer.object.forum,
                                      super_user=True,
                                      moderator=True,
                                      badge='IN')
            usersetting.save()
            # send for approval now

            ## Create a 'General' tag for each course
            tag = Tag(forum=serializer.object.forum)
            tag.tag_name = 'General'
            tag.title = 'General'
            tag.save()

            return Response(serializer.data)
        else:
            content = serializer.errors
            return Response(content, status.HTTP_400_BAD_REQUEST)
コード例 #2
0
ファイル: course.py プロジェクト: kartikshah1/Test
    def create(self, request, *args):
        """
        Function for creating a course in a category
        """
        serializer = CourseSerializer(data=request.DATA, files=request.FILES)
        if serializer.is_valid():
            serializer.save()
            coursehistory = CourseHistory(user=request.user,
                                          course=serializer.object,
                                          active='A',
                                          is_owner=True)
            coursehistory.save()

            # Usersetting for the discussion forum
            usersetting = UserSetting(user=request.user,
                                      forum=serializer.object.forum,
                                      super_user=True,
                                      moderator=True,
                                      badge='IN')
            usersetting.save()
            # send for approval now
            return Response(serializer.data)
        else:
            content = serializer.errors
            return Response(content, status.HTTP_400_BAD_REQUEST)
コード例 #3
0
ファイル: course.py プロジェクト: kartikshah1/Test
    def create(self, request, pk=None, *args):
        """
        Function for creating an offering in a category
        """
        serializer = OfferingSerializer(data=request.DATA)
        if serializer.is_valid():
            serializer.save()
            coursehistory = CourseHistory(
                user=request.user,
                course=serializer.object,
                active='A',
                is_owner=True
            )
            coursehistory.save()

            # Usersetting for the discussion forum
            usersetting = UserSetting(
                user=request.user,
                forum=serializer.object.forum, super_user=True, moderator=True, badge='IN')
            usersetting.save()
            # send for approval now

            ## Create a 'General' tag for each course
            tag = Tag(forum=serializer.object.forum)
            tag.tag_name = 'General'
            tag.title = 'General'
            tag.save()

            return Response(serializer.data)
        else:
            content = serializer.errors
            return Response(content, status.HTTP_400_BAD_REQUEST)
コード例 #4
0
ファイル: course.py プロジェクト: kartikshah1/Test
    def create(self, request, *args):
        """
        Function for creating a course in a category
        """
        serializer = CourseSerializer(data=request.DATA, files=request.FILES)
        if serializer.is_valid():
            serializer.save()
            coursehistory = CourseHistory(
                user=request.user,
                course=serializer.object,
                active='A',
                is_owner=True
            )
            coursehistory.save()

            # Usersetting for the discussion forum
            usersetting = UserSetting(
                user=request.user,
                forum=serializer.object.forum, super_user=True, moderator=True, badge='IN')
            usersetting.save()
            # send for approval now
            return Response(serializer.data)
        else:
            content = serializer.errors
            return Response(content, status.HTTP_400_BAD_REQUEST)
コード例 #5
0
ファイル: course.py プロジェクト: kartikshah1/Test
 def register(self, request, pk=None):
     """
         Register a student to a course.
     """
     course = get_object_or_404(Course, pk=pk, type='O')
     try:
         coursehistory = CourseHistory.objects.get(
             course=course,
             user=request.user,
         )
         if coursehistory.active == 'U':
             coursehistory.active = 'A'
             coursehistory.save()
             #  TODO: shift the usersetting to the approve function
             usersetting = UserSetting.objects.filter(
                 user=request.user, forum=course.forum)
             if len(usersetting) > 0:
                 usersetting = usersetting[0]
                 usersetting.is_active = True
                 usersetting.save()
             return Response("Successfully registered", status.HTTP_202_ACCEPTED)
         else:
             return Response(
                 "Your approval is pending. Please contact instructor for your approval",
                 status.HTTP_400_BAD_REQUEST
             )
     except:
         coursehistory = CourseHistory(
             course=course,
             user=request.user,
             active='A'
         )
         if course.enrollment_type == 'M':
             coursehistory.active = 'P'
         coursehistory.save()
         usersetting = UserSetting(user=request.user, forum=course.forum)
         usersetting.save()
         return Response("Successfully registered", status.HTTP_202_ACCEPTED)
コード例 #6
0
ファイル: course.py プロジェクト: kartikshah1/Test
 def register(self, request, pk=None):
     """
         Register a student to a course.
     """
     course = get_object_or_404(Course, pk=pk, type='O')
     try:
         coursehistory = CourseHistory.objects.get(
             course=course,
             user=request.user,
         )
         if coursehistory.active == 'U':
             coursehistory.active = 'A'
             coursehistory.save()
             #  TODO: shift the usersetting to the approve function
             usersetting = UserSetting.objects.filter(user=request.user,
                                                      forum=course.forum)
             if len(usersetting) > 0:
                 usersetting = usersetting[0]
                 usersetting.is_active = True
                 usersetting.save()
             return Response("Successfully registered",
                             status.HTTP_202_ACCEPTED)
         else:
             return Response(
                 "Your approval is pending. Please contact instructor for your approval",
                 status.HTTP_400_BAD_REQUEST)
     except:
         coursehistory = CourseHistory(course=course,
                                       user=request.user,
                                       active='A')
         if course.enrollment_type == 'M':
             coursehistory.active = 'P'
         coursehistory.save()
         usersetting = UserSetting(user=request.user, forum=course.forum)
         usersetting.save()
         return Response("Successfully registered",
                         status.HTTP_202_ACCEPTED)