Exemplo n.º 1
0
Arquivo: views.py Projeto: pixyj/feel
    def put(self, request, pk):
        course = get_course_or_404(pk)
        if course.created_by.id != request.user.id:
            return Response({"permission": "denied"}, status=status.HTTP_403_FORBIDDEN)


        serializer = CourseSerializer(data=request.data)
        if not serializer.is_valid():
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

        if request.user.id != course.created_by.id:
            return Response({"permission": "denied"}, status=status.HTTP_403_FORBIDDEN)

        validated_data = serializer.data
        audit_attrs = get_audit_attrs(course.created_by, request.user)
        validated_data.update(audit_attrs)

        previous_is_published = course.is_published
        course = serializer.update(course, validated_data)

        response = serializer.data
        if previous_is_published != course.is_published:
            #import ipdb; ipdb.set_trace()
            response = dict(serializer.data)
            if course.is_published:
                courseslug = course.publish_and_slugify()
            else:
                courseslug = None
                course.unpublish()
            if courseslug is not None:
                response['slug'] = courseslug.slug
            else:
                response['slug'] = None
                
        return Response(response, status.HTTP_200_OK)
Exemplo n.º 2
0
Arquivo: views.py Projeto: pixyj/feel
    def post(self, request):

        serializer = CourseSerializer(data=request.data)
        if not serializer.is_valid():
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

        validated_data = serializer.data
        audit_attrs = get_audit_attrs(request.user)
        validated_data.update(audit_attrs)
        
        course = serializer.create(validated_data)
        serializer = CourseSerializer(course)
        return Response(serializer.data, status.HTTP_201_CREATED)
Exemplo n.º 3
0
    def post(self, request):

        serializer = CourseSerializer(data=request.data)
        if not serializer.is_valid():
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

        validated_data = serializer.data
        audit_attrs = get_audit_attrs(request.user)
        validated_data.update(audit_attrs)

        course = serializer.create(validated_data)
        serializer = CourseSerializer(course)
        return Response(serializer.data, status.HTTP_201_CREATED)
Exemplo n.º 4
0
Arquivo: views.py Projeto: pixyj/feel
    def post(self, request, course_id):
        course = get_course_or_404(course_id)
        if course.created_by.id != request.user.id:
            return Response({"permission": "denied"}, status=status.HTTP_403_FORBIDDEN)


        audit_attrs = get_audit_attrs(request.user)

        concept_data = {"name": request.data['name'], "is_published": False}
        concept_data.update(audit_attrs)

        with transaction.atomic():
            concept = Concept.objects.create(**concept_data)
            courseconcept = CourseConcept.objects.create(concept=concept, course=course, **audit_attrs)

        return Response({"id": concept.id}, status=status.HTTP_201_CREATED)
Exemplo n.º 5
0
Arquivo: views.py Projeto: pixyj/feel
    def post(self, request, format=None):
        """
        Get course by course_id
        """
        user, _ = get_user_and_user_key(request)
        serializer = CodeQuizSerializer(data=request.data)
        if not serializer.is_valid():
            return Response(serializer.errors, status.HTTP_400_BAD_REQUEST)

        attrs = get_audit_attrs(request.user)
        attrs.update(serializer.data)
        attrs['test_cases'] = request.data['test_cases']
        codequiz = serializer.create(attrs)
        response_data = dict(serializer.data)
        response_data['id'] = codequiz.id
        return Response(response_data, status.HTTP_201_CREATED)
Exemplo n.º 6
0
Arquivo: views.py Projeto: pixyj/feel
    def put(self, request, pk):
        codequiz = get_object_or_404(CodeQuiz, id=pk)

        user, _ = get_user_and_user_key(request)
        if user.id != codequiz.created_by.id:
            return Response({"nice": "try"}, status.HTTP_403_FORBIDDEN)

        serializer = CodeQuizSerializer(data=request.data)
        if not serializer.is_valid():
            return Response(serializer.errors, status.HTTP_400_BAD_REQUEST)

        attrs = get_audit_attrs(request.user)
        attrs.update(serializer.data)
        attrs['test_cases'] = request.data['test_cases']

        serializer.update(codequiz, attrs)
        return Response(request.data)
Exemplo n.º 7
0
    def post(self, request, course_id):
        course = get_course_or_404(course_id)
        if course.created_by.id != request.user.id:
            return Response({"permission": "denied"},
                            status=status.HTTP_403_FORBIDDEN)

        audit_attrs = get_audit_attrs(request.user)

        concept_data = {"name": request.data['name'], "is_published": False}
        concept_data.update(audit_attrs)

        with transaction.atomic():
            concept = Concept.objects.create(**concept_data)
            courseconcept = CourseConcept.objects.create(concept=concept,
                                                         course=course,
                                                         **audit_attrs)

        return Response({"id": concept.id}, status=status.HTTP_201_CREATED)
Exemplo n.º 8
0
Arquivo: views.py Projeto: pixyj/feel
    def post(self, request, course_id):
        course = get_course_or_404(course_id)
        if course.created_by.id != request.user.id:
            return Response({"permission": "denied"}, status=status.HTTP_403_FORBIDDEN)

        audit_attrs = get_audit_attrs(request.user)


        try:
            start = course.courseconcept_set.get(concept=request.data['from'])
            end = course.courseconcept_set.get(concept=request.data['to'])
            dep = ConceptDependency.objects.create(course=course, start=start, end=end, **audit_attrs)

        except CourseConcept.DoesNotExist:
            return Response({"Concept does not exist"}, status.HTTP_400_BAD_REQUEST)

        except IntegrityError:
            return Response({"Dependency exists"}, status.HTTP_400_BAD_REQUEST)

        return Response({"id": dep.id}, status=status.HTTP_201_CREATED)
Exemplo n.º 9
0
    def put(self, request, pk):
        course = get_course_or_404(pk)
        if course.created_by.id != request.user.id:
            return Response({"permission": "denied"},
                            status=status.HTTP_403_FORBIDDEN)

        serializer = CourseSerializer(data=request.data)
        if not serializer.is_valid():
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

        if request.user.id != course.created_by.id:
            return Response({"permission": "denied"},
                            status=status.HTTP_403_FORBIDDEN)

        validated_data = serializer.data
        audit_attrs = get_audit_attrs(course.created_by, request.user)
        validated_data.update(audit_attrs)

        previous_is_published = course.is_published
        course = serializer.update(course, validated_data)

        response = serializer.data
        if previous_is_published != course.is_published:
            #import ipdb; ipdb.set_trace()
            response = dict(serializer.data)
            if course.is_published:
                courseslug = course.publish_and_slugify()
            else:
                courseslug = None
                course.unpublish()
            if courseslug is not None:
                response['slug'] = courseslug.slug
            else:
                response['slug'] = None

        return Response(response, status.HTTP_200_OK)
Exemplo n.º 10
0
    def post(self, request, course_id):
        course = get_course_or_404(course_id)
        if course.created_by.id != request.user.id:
            return Response({"permission": "denied"},
                            status=status.HTTP_403_FORBIDDEN)

        audit_attrs = get_audit_attrs(request.user)

        try:
            start = course.courseconcept_set.get(concept=request.data['from'])
            end = course.courseconcept_set.get(concept=request.data['to'])
            dep = ConceptDependency.objects.create(course=course,
                                                   start=start,
                                                   end=end,
                                                   **audit_attrs)

        except CourseConcept.DoesNotExist:
            return Response({"Concept does not exist"},
                            status.HTTP_400_BAD_REQUEST)

        except IntegrityError:
            return Response({"Dependency exists"}, status.HTTP_400_BAD_REQUEST)

        return Response({"id": dep.id}, status=status.HTTP_201_CREATED)