Ejemplo n.º 1
0
    def form_valid(self, form):
        form.instance.discussion = self.discussion
        form.instance.user = self.request.user
        #         if Feedback.objects.filter( discussion = self.discussion, feedbabk_type = form.instance.feedbabk_type, content = form.instance.content).exists():
        #             return HttpResponseRedirect(
        #                     self.discussion.get_absolute_url())

        #         resp = super(CreateFeedbackView, self).form_valid(form)

        feedback, error_string = discussion_add_feedback(
            discussion=self.discussion,
            user=self.request.user,
            feedbabk_type=form.instance.feedbabk_type,
            content=form.instance.content,
            voice_recording=form.instance.voice_recording)
        if feedback:
            return HttpResponseRedirect(
                form.instance.discussion.get_absolute_url(
                ))  # Redirect after POST

        return render(
            self.request, 'coplay/error.html', {
                'message': error_string,
                'url': self.discussion.get_absolute_url(),
                'url_text': u"בחזרה ל" + self.discussion.title,
                'rtl': 'dir="rtl"'
            })
Ejemplo n.º 2
0
def add_feedback(request, pk):
    try:
        discussion = Discussion.objects.get(id=int(pk))
    except Discussion.DoesNotExist:
        return HttpResponse('Discussion not found')
    if request.method == 'POST': # If the form has been submitted...
        form = AddFeedbackForm(request.POST, request.FILES) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
    #         if Feedback.objects.filter( discussion = self.discussion, feedbabk_type = form.instance.feedbabk_type, content = form.instance.content).exists():
    #             return HttpResponseRedirect(
    #                     self.discussion.get_absolute_url())
                
    #         resp = super(CreateFeedbackView, self).form_valid(form) 
             
            feedback, error_string = discussion_add_feedback( discussion    = discussion, 
                                                             user           = request.user   ,
                                                             feedbabk_type  = form.cleaned_data['feedbabk_type'], 
                                                             content        = form.cleaned_data['content'],
                                                             voice_recording = form.cleaned_data['voice_recording'])
            
            if feedback:
                return HttpResponseRedirect(
                    discussion.get_absolute_url()) # Redirect after POST
                
            return render(request, 'coplay/message.html',
                                          {'message': error_string,
                                           'rtl': 'dir="rtl"',
                                           'next_url':discussion.get_absolute_url(),
                                           'next_text': u'בחזרה ל:' + discussion.title})            

        
    return HttpResponseRedirect(
                    discussion.get_absolute_url()) # Redirect after POST
Ejemplo n.º 3
0
    def post(self, request, pk, format = None,csrf_exempt = True):
        discussion = self.get_object(pk)
        created_feedback_serializer = AddFeedBackSerializer(data=request.DATA)        
        
        if not created_feedback_serializer.is_valid():
            return Response(created_feedback_serializer.errors)

        feedback, error_string = discussion_add_feedback( discussion, 
                                                          request.user,feedbabk_type = created_feedback_serializer.object.feedback_type, 
                                                          content = created_feedback_serializer.object.content)
        if feedback:
            serialized_feedback = FeedbackSerializer(feedback)
            return Response(serialized_feedback.data)
            
        return Response({'response': error_string})
Ejemplo n.º 4
0
    def post(self, request, pk, format=None, csrf_exempt=True):
        discussion = self.get_object(pk)
        created_feedback_serializer = AddFeedBackSerializer(data=request.DATA)

        if not created_feedback_serializer.is_valid():
            return Response(created_feedback_serializer.errors)

        feedback, error_string = discussion_add_feedback(
            discussion,
            request.user,
            feedbabk_type=created_feedback_serializer.object.feedback_type,
            content=created_feedback_serializer.object.content)
        if feedback:
            serialized_feedback = FeedbackSerializer(feedback)
            return Response(serialized_feedback.data)

        return Response({'response': error_string})
Ejemplo n.º 5
0
    def form_valid(self, form):
        form.instance.discussion = self.discussion
        form.instance.user = self.request.user
#         if Feedback.objects.filter( discussion = self.discussion, feedbabk_type = form.instance.feedbabk_type, content = form.instance.content).exists():
#             return HttpResponseRedirect(
#                     self.discussion.get_absolute_url())
            
#         resp = super(CreateFeedbackView, self).form_valid(form) 
         
        feedback, error_string = discussion_add_feedback( discussion    = self.discussion, 
                                                         user           = self.request.user   ,
                                                         feedbabk_type  = form.instance.feedbabk_type, 
                                                         content        = form.instance.content,
                                                         voice_recording = form.instance.voice_recording)
        if feedback:
            return HttpResponseRedirect(form.instance.discussion.get_absolute_url()) # Redirect after POST
        
        return render(self.request, 'coplay/error.html',
                              {'message': error_string,
                               'url': self.discussion.get_absolute_url(),
                               'url_text': u"בחזרה ל" + self.discussion.title,
                               'rtl': 'dir="rtl"'})
Ejemplo n.º 6
0
def add_feedback(request, pk):
    try:
        discussion = Discussion.objects.get(id=int(pk))
    except Discussion.DoesNotExist:
        return HttpResponse('Discussion not found')
    if request.method == 'POST':  # If the form has been submitted...
        form = AddFeedbackForm(request.POST,
                               request.FILES)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            #         if Feedback.objects.filter( discussion = self.discussion, feedbabk_type = form.instance.feedbabk_type, content = form.instance.content).exists():
            #             return HttpResponseRedirect(
            #                     self.discussion.get_absolute_url())

            #         resp = super(CreateFeedbackView, self).form_valid(form)

            feedback, error_string = discussion_add_feedback(
                discussion=discussion,
                user=request.user,
                feedbabk_type=form.cleaned_data['feedbabk_type'],
                content=form.cleaned_data['content'],
                voice_recording=form.cleaned_data['voice_recording'])

            if feedback:
                return HttpResponseRedirect(
                    discussion.get_absolute_url())  # Redirect after POST

            return render(
                request, 'coplay/message.html', {
                    'message': error_string,
                    'rtl': 'dir="rtl"',
                    'next_url': discussion.get_absolute_url(),
                    'next_text': u'בחזרה ל:' + discussion.title
                })

    return HttpResponseRedirect(
        discussion.get_absolute_url())  # Redirect after POST