def post_rec_feedback(id):
    '''
    post feedback of ranking for recommendation with identifier id
    Args:
        id: identifier of ranking for recommendation

    Returns:
        post message
    '''
    clicks = request.values.get('clicks', None)
    if clicks is None:
        clicks = request.json.get('clicks', None)

    if clicks is not None:
        recommendation = Result.query.get_or_404(id)
        feedback = Feedback(start=recommendation.q_date,
                            session_id=recommendation.session_id,
                            interleave=recommendation.tdi is not None,
                            clicks=clicks)

        db.session.add(feedback)
        db.session.commit()
        recommendation.feedback_id = feedback.id
        db.session.add(recommendation)
        db.session.commit()
        recommendations = Result.query.filter_by(tdi=recommendation.id).all()
        for r in recommendations:
            r.feedback_id = feedback.id
        db.session.add_all(recommendations)
        db.session.commit()

        return jsonify({"msg": "Added new feedback with success!"}), 201
示例#2
0
def reply_feedback(request):
    if request.user.is_authenticated():
        if request.method == 'POST':
            sug = str(request.POST.get("suggestion").encode('utf-8'))
            feedbacks = Feedback.objects.filter(
                articledetails_id=request.POST.get("article"),
                email=request.POST.get("email"),
                name=request.POST.get("name"))
            for feedback in feedbacks:
                if feedback.suggestion.raw.encode('utf-8') == sug:
                    return HttpResponse(
                        simplejson.dumps({
                            'duplicate': True,
                            'name': request.POST.get("name")
                        }))
            Feedback(user=request.POST.get("user_id"),
                     articledetails_id=request.POST.get("article"),
                     suggestion=request.POST.get("suggestion"),
                     email=request.POST.get("email"),
                     name=request.POST.get("name"),
                     parent_id=request.POST.get("parent")).save()
            reply = Feedback.objects.filter(
                user=request.POST.get("user_id"),
                articledetails_id=request.POST.get("article"),
                suggestion=request.POST.get("suggestion"),
                email=request.POST.get("email"),
                name=request.POST.get("name"),
                parent_id=request.POST.get("parent"))
            return HttpResponse(
                simplejson.dumps({
                    'date': str(reply[0].date),
                    'id': reply[0].id,
                    'suggestion': request.POST.get("suggestion"),
                    'parent': request.POST.get("parent")
                }))
示例#3
0
 def post(self, request, *args, **kwargs):
     if not self.wrap_check_sign_result():
         return self.render_to_response(dict())
     content = request.POST.get('content')
     session = request.POST.get('session', None)
     user = WeUser.objects.filter(session=session)
     # if not user.exists():
     #     self.message = 'session 不存在或已过期'
     #     self.status_code = SW.ERROR_PERMISSION_DENIED
     #     return self.render_to_response({})
     # user = user[0]
     if content:
         is_advice = True if request.POST.get(
             'is_advice') == 'true' else False
         scene_id = request.POST.get("scene_id")
         form_id = request.POST.get('form_id', '')
         new_feedback = Feedback(content=content)
         new_feedback.form_id = form_id
         new_feedback.feed_type = 2 if is_advice else 1
         if user.exists():
             new_feedback.author = user[0]
         if scene_id:
             scenes = Scene.objects.filter(id=scene_id)
             if scenes.exists():
                 new_feedback.scene = scenes[0]
         new_feedback.save()
         return self.render_to_response({})
     self.message = '参数缺失'
     self.status_code = SW.ERROR_DATA
     return self.render_to_response({})
示例#4
0
def post_feedback(id):
    # 1) check if ranking with id exists
    # 2) check if feedback is not already in db

    '''
    add user feedback to database (collect data for statistics)

    @param id:  ranking id (int)

    @return:    HTTP status message 
    '''

    clicks = request.values.get('clicks', None)
    if clicks is None:
        clicks = request.json.get('clicks', None)

    if clicks is not None:
        ranking = Result.query.get_or_404(id)
        feedback = Feedback(start=ranking.q_date,
                            session_id=ranking.session_id,
                            interleave=ranking.tdi is not None,
                            clicks=clicks)

        db.session.add(feedback)
        db.session.commit()
        ranking.feedback_id = feedback.id
        db.session.add(ranking)
        db.session.commit()
        rankings = Result.query.filter_by(tdi=ranking.id).all()
        for r in rankings:
            r.feedback_id = feedback.id
        db.session.add_all(rankings)
        db.session.commit()

        return jsonify({"msg": "Added new feedback with success!"}), 201
示例#5
0
 def save(self):
     feedback = Feedback(text=self.cleaned_data['text'],
                         date=datetime.now(),
                         wealth=self.wealth)
     feedback.save()
     send_mail('New feedback!', feedback.text, SENDER_EMAIL,
               [FEEDBACK_EMAIL])
示例#6
0
def modify(request):
    if request.user.is_authenticated():
        if request.method == 'POST':
            sug = str(request.POST.get("suggestion").encode('utf-8'))
            feedbacks = Feedback.objects.filter(
                articledetails_id=request.POST.get("article"),
                email=request.POST.get("email"),
                name=request.POST.get("name"))
            for feedback in feedbacks:
                if feedback.suggestion.raw.encode('utf-8') in sug:
                    return HttpResponse(
                        simplejson.dumps({
                            'duplicate': True,
                            'name': request.POST.get("name")
                        }))
            else:
                Feedback(user=request.POST.get("user_id"),
                         articledetails_id=request.POST.get("article"),
                         suggestion=request.POST.get("suggestion"),
                         email=request.POST.get("email"),
                         name=request.POST.get("name")).save()
                feedback = Feedback.objects.filter(
                    articledetails_id=request.POST.get("article"),
                    suggestion=request.POST.get("suggestion"),
                    email=request.POST.get("email"),
                    name=request.POST.get("name"))

            if request.user.username != "admin":
                fb_user = FacebookSession.objects.get(user=request.user)
                # GraphAPI is the main class from facebook_sdp.py
                graph = facebook_sdk.GraphAPI(fb_user.access_token)
                attachment = {}
                attachment[
                    'link'] = settings.domain + "sharek/" + request.POST.get(
                        "class_slug") + "/" + request.POST.get(
                            "article_slug") + "/"
                attachment[
                    'picture'] = settings.domain + settings.STATIC_URL + "images/facebook.png"
                message = 'لقد شاركت في كتابة #دستور_مصر وقمت بالتعليق على ' + get_object_or_404(
                    ArticleDetails, id=request.POST.get(
                        "article")).header.name.encode('utf-8') + " من الدستور"
                graph.put_wall_post(message, attachment)

            return HttpResponse(
                simplejson.dumps({
                    'date': str(feedback[0].date),
                    'id': feedback[0].id,
                    'suggestion': request.POST.get("suggestion")
                }))
def add_feedback(request, product_id):
    if request.method == 'POST':
        feedback = Feedback(user=request.user,
                            text=request.POST.get("text"),
                            rate=int(request.POST.get("rate")),
                            datetime=datetime.now(),
                            product=BaseProduct.objects.get(id=product_id))
        feedback.save()
        if request.FILES:
            for photo in request.FILES.getlist("photos"):
                image = Image(image=photo)
                image.save()
                feedback.images.add(image)
            feedback.save()

    return HttpResponseRedirect(f"/product/{product_id}")
示例#8
0
文件: views.py 项目: satyam-seth/mic
def feedback(request):
    if request.method=='POST':
        fm=FeedbackFrom(request.POST)
        if fm.is_valid():
            nm=fm.cleaned_data['name']
            tp=fm.cleaned_data['problem']
            mg=fm.cleaned_data['message']
            current_dt=timezone.now()
            reg=Feedback(name=nm,problem=tp,message=mg,datetime=current_dt)
            reg.save()
            messages.success(request,'Thank you for your valuable feedback, it will help us to improve your experience.')
        return redirect('home')
    else:
        fm=FeedbackFrom()
    
    context={
        'feedback_active':'active',
        'feedback_disabled':'disabled',
        'form':fm
        }
    return render(request,'core/feedback.html',context)
示例#9
0
def modify(request):
    if request.user.is_authenticated():
        if request.method == 'POST':
            sug = str(request.POST.get("suggestion").encode('utf-8'))
            article = get_object_or_404(ArticleDetails,
                                        id=request.POST.get("article"))
            feedbacks = Feedback.objects.filter(
                articledetails_id=request.POST.get("article"),
                email=request.POST.get("email"),
                name=request.POST.get("name"))
            for feedback in feedbacks:
                if feedback.suggestion.raw.encode('utf-8') == sug:
                    return HttpResponse(
                        simplejson.dumps({
                            'duplicate': True,
                            'name': request.POST.get("name")
                        }))

            Feedback(user=request.POST.get("user_id"),
                     articledetails_id=request.POST.get("article"),
                     suggestion=request.POST.get("suggestion"),
                     email=request.POST.get("email"),
                     name=request.POST.get("name")).save()
            feedback = Feedback.objects.filter(
                articledetails_id=request.POST.get("article"),
                suggestion=request.POST.get("suggestion"),
                email=request.POST.get("email"),
                name=request.POST.get("name"))
            article.feedback_count = article.feedback_count + 1
            article.save()

            if request.user.username != "admin":
                # post on twitter or facebook
                if UserSocialAuth.auth_provider(
                        request.user.username) == 'facebook':
                    extra_data = UserSocialAuth.get_extra_data(
                        request.user.username)
                    access_token = extra_data['access_token']
                    # GraphAPI is the main class from facebook_sdp.py
                    art = get_object_or_404(ArticleDetails,
                                            id=request.POST.get("article"))
                    art_name = art.header.name.encode('utf-8')
                    art_body = art.summary.raw.encode('utf-8')
                    graph = facebook_sdk.GraphAPI(access_token)
                    attachment = {}
                    attachment['name'] = art_name
                    attachment['link'] = shorten_url(
                        settings.domain + "sharek/" +
                        request.POST.get("class_slug") + "/" +
                        request.POST.get("article_slug") + "/comment/" +
                        str(feedback[0].id) + "/")
                    attachment[
                        'picture'] = settings.domain + settings.STATIC_URL + "images/facebook-thumb.jpg"
                    attachment['description'] = art_body
                    message = 'لقد شاركت في كتابة #دستور_مصر وقمت بالتعليق على ' + art_name + " من الدستور"
                    graph.put_wall_post(message, attachment)

                if UserSocialAuth.auth_provider(
                        request.user.username) == 'twitter':
                    extra_data = UserSocialAuth.get_extra_data(
                        request.user.username)
                    access_token = extra_data['access_token']
                    access_token_secret = access_token[access_token.find('=') +
                                                       1:access_token.find('&'
                                                                           )]
                    access_token_key = access_token[access_token.rfind('=') +
                                                    1:]
                    api = twitter.Api(
                        consumer_key=settings.TWITTER_CONSUMER_KEY,
                        consumer_secret=settings.TWITTER_CONSUMER_SECRET,
                        access_token_key=access_token_key,
                        access_token_secret=access_token_secret)
                    link = shorten_url(settings.domain + "sharek/" +
                                       request.POST.get("class_slug") + "/" +
                                       request.POST.get("article_slug") +
                                       "/comment/" + str(feedback[0].id) + "/")
                    message = 'لقد شاركت في كتابة #دستور_مصر بالتعليق على ' + get_object_or_404(
                        ArticleDetails, id=request.POST.get("article")
                    ).header.name.encode('utf-8') + "  " + link
                    api.PostUpdate(message)

            return HttpResponse(
                simplejson.dumps({
                    'date': str(feedback[0].date),
                    'id': feedback[0].id,
                    'suggestion': request.POST.get("suggestion")
                }))