예제 #1
0
파일: api.py 프로젝트: gl1000007/NeuroNet
    def post(self, request, format = None,csrf_exempt = True):
        created_discussion_serializer = AddDiscussionSerializer(data=request.DATA)        
          
        if not created_discussion_serializer.is_valid():
            return Response(created_discussion_serializer.errors)
        
#         user = get_user( recived_user            = request.user,
#                          app_id                  = created_discussion_serializer.app_id,
#                          application_specific_id = created_discussion_serializer.application_specific_id)
        
        discussion, error_string = create_discussion( user                   =  request.user,
                                                      title                  =  created_discussion_serializer.object.title          ,
                                                      description            =  created_discussion_serializer.object.description    ,
                                                      location_desc          =  created_discussion_serializer.object.location_desc  ,
                                                      tags_string            =  created_discussion_serializer.object.tags_string    ,
                                                      parent_url             =  created_discussion_serializer.object.parent_url     ,
                                                      parent_url_text        =  created_discussion_serializer.object.parent_url_text,
                                                      latitude               =  created_discussion_serializer.object.latitude       ,
                                                      longitude              =  created_discussion_serializer.object.longitude      ,
                                                      picture                =  created_discussion_serializer.object.picture                     ,
                                                      movie_url              =  created_discussion_serializer.object.movie_url                   ,
                                                      movie_url_url_text     =  created_discussion_serializer.object.movie_url_url_text  ,
                                                      anyway_progress_status =  created_discussion_serializer.object.anyway_progress_status,
                                                      anyway_discuss_id      =  created_discussion_serializer.object.anyway_discuss_id      
                                                      )
                                                     
        if discussion:
            serialized_discussion = DiscussionSerializer(discussion)          
            return Response(serialized_discussion.data)
  
        return Response({'response': error_string})
예제 #2
0
def add_on_add_discussion(request, pk=None):

    use_template = 'coplay/add_on_new_discussion.html'

    if request.method == 'POST':  # If the form has been submitted...
        form = NewDiscussionForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass

            new_discussion, error_string = create_discussion(
                user=request.user,
                title=form.cleaned_data['title'],
                description=form.cleaned_data['description'],
                location_desc=form.cleaned_data['location_desc'],
                tags_string=form.cleaned_data['tags'],
                parent_url=form.cleaned_data['parent_url'],
                parent_url_text=form.cleaned_data['parent_url_text'])

            if new_discussion:
                messages.success(request,
                                 _("Your activity was created successfully"))
                return redirect(new_discussion)

            messages.error(request, error_string)
    else:
        parent_url = request.REQUEST.get('parent_url', '')
        parent_url_text = request.REQUEST.get('parent_url_text', '')
        if parent_url:
            form = NewDiscussionForm(initial={
                'parent_url': parent_url,
                'parent_url_text': parent_url_text
            })  # An unbound form
            return render(request, use_template, {
                'form': form,
                'rtl': 'dir="rtl"'
            })

        if pk:
            try:
                tag = Tag.objects.get(id=int(pk))
            except Tag.DoesNotExist:
                return render(request, 'coplay/message.html', {
                    'message': 'הנושא איננו קיים',
                    'rtl': 'dir="rtl"'
                })
            form = NewDiscussionForm(initial={'tags':
                                              tag.name})  # An unbound form
            request.user.userprofile.followed_discussions_tags.add(tag.name)
            request.user.userprofile.save()
        else:
            form = NewDiscussionForm()  # An unbound form

    data = render(request, use_template, {'form': form, 'rtl': 'dir="rtl"'})
    response = HttpResponse(data)
    response['X-Frame-Options'] = "ALLOWALL"
    return response
예제 #3
0
파일: views.py 프로젝트: gl1000007/NeuroNet
def add_on_add_discussion(request, pk = None):
    
    
    use_template = 'coplay/add_on_new_discussion.html'
    
    if request.method == 'POST': # If the form has been submitted...
        form = NewDiscussionForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            
            new_discussion, error_string = create_discussion( user             = request.user, 
                                                       title            = form.cleaned_data['title'], 
                                                       description      = form.cleaned_data['description'],                       
                                                       location_desc    = form.cleaned_data['location_desc'],
                                                       tags_string      = form.cleaned_data['tags'],
                                                       parent_url       = form.cleaned_data['parent_url'],
                                                       parent_url_text  = form.cleaned_data['parent_url_text'])
            
            if new_discussion:
                messages.success(request,_("Your activity was created successfully"))
                return redirect(new_discussion)
                
            messages.error(request, error_string)
    else:
        parent_url = request.REQUEST.get('parent_url', '')
        parent_url_text = request.REQUEST.get('parent_url_text', '')
        if parent_url:
            form = NewDiscussionForm(initial={'parent_url': parent_url,
                                              'parent_url_text': parent_url_text}) # An unbound form
            return render(request, use_template, {
                'form': form,
                'rtl': 'dir="rtl"'
            })
            
        if pk:
            try:
                tag = Tag.objects.get(id=int(pk))
            except Tag.DoesNotExist:
                return render(request, 'coplay/message.html',
                              {'message': 'הנושא איננו קיים',
                               'rtl': 'dir="rtl"'})
            form = NewDiscussionForm(initial={'tags': tag.name}) # An unbound form
            request.user.userprofile.followed_discussions_tags.add( tag.name)
            request.user.userprofile.save()
        else:
            form = NewDiscussionForm() # An unbound form


    data = render(request, use_template, {
            'form': form,
            'rtl': 'dir="rtl"'
        })
    response = HttpResponse(data)
    response['X-Frame-Options'] = "ALLOWALL"
    return response
예제 #4
0
파일: api.py 프로젝트: yaron148/NeuroNet
    def post(self, request, format=None, csrf_exempt=True):
        created_discussion_serializer = AddDiscussionSerializer(
            data=request.DATA)

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

#         user = get_user( recived_user            = request.user,
#                          app_id                  = created_discussion_serializer.app_id,
#                          application_specific_id = created_discussion_serializer.application_specific_id)

        discussion, error_string = create_discussion(
            user=request.user,
            title=created_discussion_serializer.object.title,
            description=created_discussion_serializer.object.description,
            location_desc=created_discussion_serializer.object.location_desc,
            tags_string=created_discussion_serializer.object.tags_string,
            parent_url=created_discussion_serializer.object.parent_url,
            parent_url_text=created_discussion_serializer.object.
            parent_url_text,
            latitude=created_discussion_serializer.object.latitude,
            longitude=created_discussion_serializer.object.longitude,
            picture=created_discussion_serializer.object.picture,
            movie_url=created_discussion_serializer.object.movie_url,
            movie_url_url_text=created_discussion_serializer.object.
            movie_url_url_text,
            anyway_progress_status=created_discussion_serializer.object.
            anyway_progress_status,
            anyway_discuss_id=created_discussion_serializer.object.
            anyway_discuss_id)

        if discussion:
            serialized_discussion = DiscussionSerializer(discussion)
            return Response(serialized_discussion.data)

        return Response({'response': error_string})