コード例 #1
0
def add(request):
    if request.method == "POST":
        form = FeedbackForm(request.POST)

        if form.is_valid():
            form.instance.user = request.user
            if 'HTTP_REFERER' in request.META:
                form.instance.page = request.META['HTTP_REFERER']

            form.save()

            return HttpResponse('', mimetype="text/plain")
        else:
            logger.debug(form.errors)
            error_msg = []
            for field in form.errors:
                for error in form.errors[field]:
                    error_msg.append('%s: %s' %
                                     (form.fields[field].label, error))
            error_msg = '\n'.join(error_msg)

            return HttpResponseBadRequest(error_msg, mimetype="text/plain")
    else:
        return HttpResponseNotAllowed([
            "POST",
        ])
コード例 #2
0
ファイル: views.py プロジェクト: mkramb/errorify
def feedback_save(request):
    form = FeedbackForm(request.user, data=request.POST.copy() or None)

    if form.is_bound and form.is_valid():
        form.save(request.user) 

    return HttpResponse()
コード例 #3
0
def feedback(request):
    if request.method == 'POST' and request.is_ajax():
        f = FeedbackForm(request.POST)
        f.save()
        return HttpResponse()
    else:
        return HttpResponseBadRequest()
コード例 #4
0
ファイル: views.py プロジェクト: mkramb/errorify
def feedback_save(request):
    form = FeedbackForm(request.user, data=request.POST.copy() or None)

    if form.is_bound and form.is_valid():
        form.save(request.user)

    return HttpResponse()
コード例 #5
0
ファイル: views.py プロジェクト: nixilla/where-is-when-is
def feedback(request):

    form = FeedbackForm(request.POST or None)
    if form.is_valid():
        form.save()

        # TODO: Add message (django.contrib.messages)

        return redirect('/')

    return render(request, 'feedback.html', {'form': form})
コード例 #6
0
def feedback_view(request):
    if request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponse('ok')
        else:
            errors = {}
            for key, value in form.errors.items():
                errors[key] = value[0]
            return HttpResponse(json.dumps(errors))
コード例 #7
0
def send_feedback(request):
    if request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            form.save()
            return render(request, 'guestbook/frontend/thanks.html')
    else:
        form = FeedbackForm()

    return render(request, 'guestbook/frontend/send_feedback.html', {
        'form': form,
    })
コード例 #8
0
ファイル: views.py プロジェクト: VBelozyorov/libcms
def send_feedback(request):
    if request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            form.save()
            return render(request, 'guestbook/frontend/thanks.html')
    else:
        form = FeedbackForm()

    return render(request, 'guestbook/frontend/send_feedback.html', {
        'form': form,
    })
コード例 #9
0
ファイル: views.py プロジェクト: isergey/system
def add_feedback(request, conference_slug=''):
    if request.method == 'POST':
        form = FeedbackForm(request.POST)

        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('guestbook_index'))
    else:
        form = FeedbackForm()
    return render(request, 'guestbook/feedback_add.html',
                              {'form': form,
                               'module':'guestbook',})
コード例 #10
0
ファイル: views.py プロジェクト: Kirito1899/libcms
def edit_feedback(request, id):
    feedback = get_object_or_404(Feedback, id=id)
    if request.method == 'POST':
        form = FeedbackForm(request.POST, instance=feedback)
        if form.is_valid():
            form.save()
            return redirect('guestbook:administration:feedbacks_list')
    else:
        form = FeedbackForm(instance=feedback)

    return render(request, 'guestbook/administration/edit_feedback.html', {
        'form': form,
    })
コード例 #11
0
ファイル: views.py プロジェクト: isergey/system
def edit(request, message_id):
    feedback = get_object_or_404(Feedback, id=message_id)
    if request.method == 'POST':
        form = FeedbackForm(request.POST, instance=feedback)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('administration_guestbook_index'))
    else:
        form = FeedbackForm(model_to_dict(feedback),instance=feedback)
    return direct_to_template(request, 'guestbook/administration/edit_message.html',
                              {'form': form,
                               'feedback':feedback,
                               'active_module': 'guestbook'})
コード例 #12
0
ファイル: views.py プロジェクト: VBelozyorov/libcms
def edit_feedback(request, id):
    feedback = get_object_or_404(Feedback, id=id)
    if request.method == 'POST':
        form = FeedbackForm(request.POST, instance=feedback)
        if form.is_valid():
            form.save()
            return redirect('guestbook:administration:feedbacks_list')
    else:
        form = FeedbackForm(instance=feedback)

    return render(request, 'guestbook/administration/edit_feedback.html', {
        'form': form,
    })
コード例 #13
0
ファイル: views.py プロジェクト: Bauerr/geoq
def feedbackcreate(request):

    form = FeedbackForm(request.POST or None)
    topics = Topic.objects.all()

    if request.method == 'POST':
        if form.is_valid():
            form.save(commit=True)
            return HttpResponseRedirect(reverse('thanks'))
        else:
            return render(request, 'feedback.html', {'form': form, 'topics': topics })

    return render(request, 'feedback.html', {'form': FeedbackForm(), 'topics': topics})
コード例 #14
0
ファイル: views.py プロジェクト: joash/djangotemplate
def contact(request):
    """
    Feedback form
    """
    form = FeedbackForm(initial={'submitter': request.user})

    if request.method == 'POST':
        form = FeedbackForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            form.save()
            messages.error(request, 'Thank you', fail_silently=False)
        else:
            messages.error(request, 'Invalid', fail_silently=False)
            print form.errors

    return render(request, "contact.html", {'form': form, 'helper': FeedbackForm.helper})
コード例 #15
0
ファイル: views.py プロジェクト: IIIT-Delhi/findmystuff
def feedback(request):
    """
    sends the feedback modal.
    """
    logged_in = True

    # CHECKS:
    #   i) user is logged in
    #   ii) request is either ajax for requesting feedback modal
    #   iii) request is a POST request for submitting feedback
    # else error
    if (not request.user.is_authenticated()) or \
            (not request.is_ajax() and not request.method == "POST"):
        return HttpResponse("Please login and go to the main page.")

    form = FeedbackForm()
    if request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.user = request.user         # add user
            obj.save()
            messages.success(request, "Thank you for your valuable feedback.")
        return HttpResponseRedirect(reverse('home'))
    return render(request, 'feedback.html',{
        'form': form, 'logged_in': logged_in })
コード例 #16
0
def feedback(request):
    """
    sends the feedback modal.
    """
    logged_in = True

    # CHECKS:
    #   i) user is logged in
    #   ii) request is either ajax for requesting feedback modal
    #   iii) request is a POST request for submitting feedback
    # else error
    if (not request.user.is_authenticated()) or \
            (not request.is_ajax() and not request.method == "POST"):
        return HttpResponse("Please login and go to the main page.")

    form = FeedbackForm()
    if request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.user = request.user  # add user
            obj.save()
            messages.success(request, "Thank you for your valuable feedback.")
        return HttpResponseRedirect(reverse('home'))
    return render(request, 'feedback.html', {
        'form': form,
        'logged_in': logged_in
    })
コード例 #17
0
ファイル: views.py プロジェクト: kblauer/kinder-updates
def create(request):
    username = None
    group = 'teacher'
    
    if request.user.is_authenticated():
        username = request.user.username
        if request.user.has_perm('feedback.add_feedback'):
            group = 'parent'
            
    if request.POST:
        form = FeedbackForm(request.POST)
        if form.is_valid():
            # this saves the form submission data, but doesn't submit it to the server yet
            # It is needed so that we can set the parent ID on the model data before final submission
            fb = form.save(commit=False)
            fb.sentByParent = request.user
            fb.save()
            
            return HttpResponseRedirect('/feedback/parent_view/')
        
    else:
        form = FeedbackForm()
        
        args = {}
        args.update(csrf(request))
        
        args['form'] = form
        args['username'] = username
        args['group'] = group
        
        return render_to_response('create_feedback.html', args)
コード例 #18
0
ファイル: views.py プロジェクト: isergey/libcms
def index(request):
    feedbacks_page = get_page(request, Feedback.objects.filter(publicated=True).order_by('-add_date'))

    count_feedback = len(feedbacks_page)

    if request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            form.save()
            return render(request, 'guestbook/frontend/thanks.html')
    else:
        form = FeedbackForm()

    return render(request, 'guestbook/frontend/index.html', {
        'feedbacks_page': feedbacks_page,
        'form': form,
        'count_feedback': count_feedback
    })
コード例 #19
0
ファイル: views.py プロジェクト: zhipeng0117/geoq
def feedbackcreate(request):

    form = FeedbackForm(request.POST or None)
    topics = Topic.objects.all()

    if request.method == 'POST':
        if form.is_valid():
            form.save(commit=True)
            return HttpResponseRedirect(reverse('thanks'))
        else:
            return render(request, 'feedback.html', {
                'form': form,
                'topics': topics
            })

    return render(request, 'feedback.html', {
        'form': FeedbackForm(),
        'topics': topics
    })
コード例 #20
0
ファイル: views.py プロジェクト: open-build/TolaWork_Dev
def contact(request):
    """
    Feedback form
    """
    form = FeedbackForm(initial={'submitter': request.user})

    if request.method == 'POST':
        form = FeedbackForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            form.save()
            messages.error(request, 'Thank you', fail_silently=False)
        else:
            messages.error(request, 'Invalid', fail_silently=False)
            print form.errors

    return render(request, "contact.html", {
        'form': form,
        'helper': FeedbackForm.helper
    })
コード例 #21
0
ファイル: views.py プロジェクト: mcdermott-scholars/mcdermott
def applicant_profile(request, event_name, name):
    try:
        applicant = Applicant.objects.get(norm_name=normalize_name(name),
                                          event__name=event_name)
    except Applicant.DoesNotExist:
        raise Http404('Applicant does not exist.')
    try:
        event = Event.objects.get(name=event_name)
    except Event.DoesNotExist:
        raise Http404('Event does not exist')
    try:
        feedback = Feedback.objects.get(applicant=applicant,
                                        scholar=request.user.mcuser)
    except Feedback.DoesNotExist:
        feedback = Feedback()
        feedback.applicant = applicant
        feedback.scholar = request.user.mcuser
    if request.method == 'POST':
        form = FeedbackForm(request.POST, instance=feedback)
        if (form.is_valid()):
            form.save()
            if request.is_ajax():
                return JsonResponse({'msg': 'saved successfully'})
            return redirect('feedback:index', event_name)
    else:
        form = FeedbackForm(instance=feedback)
    all_feedback = Feedback.objects.filter(applicant=applicant)
    is_interviewer = request.user.mcuser in event.interviewers.all()
    is_assigned = Assignment.objects.filter(scholar=request.user.mcuser,
                                            applicant=applicant).exists()

    context = {
        'feedback': all_feedback,
        'applicant': applicant,
        'form': form,
        'state': get_state(),
        'event_name': event_name,
        'survey_link': event.survey_link,
        'is_interviewer': is_interviewer and is_assigned,
        'favorited': favorited(request.user.mcuser, applicant)
    }
    return render(request, 'feedback/applicant.html', context)
コード例 #22
0
def index(request):
    feedbacks_page = get_page(
        request,
        Feedback.objects.filter(publicated=True).order_by('-add_date'))

    count_feedback = len(feedbacks_page)

    if request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            form.save()
            return render(request, 'guestbook/frontend/thanks.html')
    else:
        form = FeedbackForm()

    return render(
        request, 'guestbook/frontend/index.html', {
            'feedbacks_page': feedbacks_page,
            'form': form,
            'count_feedback': count_feedback
        })
コード例 #23
0
ファイル: views.py プロジェクト: mcdermott-scholars/mcdermott
def applicant_profile(request, event_name, name):
  try:
    applicant = Applicant.objects.get(norm_name=normalize_name(name), event__name=event_name)
  except Applicant.DoesNotExist:
    raise Http404('Applicant does not exist.')
  try:
    event = Event.objects.get(name=event_name)
  except Event.DoesNotExist:
    raise Http404('Event does not exist')
  try:
    feedback = Feedback.objects.get(applicant=applicant, scholar=request.user.mcuser)
  except Feedback.DoesNotExist:
    feedback = Feedback()
    feedback.applicant = applicant
    feedback.scholar = request.user.mcuser
  if request.method == 'POST':
    form = FeedbackForm(request.POST, instance=feedback)
    if (form.is_valid()):
      form.save()
      if request.is_ajax():
        return JsonResponse({'msg': 'saved successfully'})
      return redirect('feedback:index', event_name)
  else:
    form = FeedbackForm(instance=feedback)
  all_feedback = Feedback.objects.filter(applicant=applicant)
  is_interviewer = request.user.mcuser in event.interviewers.all()
  is_assigned = Assignment.objects.filter(scholar=request.user.mcuser, applicant=applicant).exists()

  context = {
      'feedback': all_feedback,
      'applicant': applicant,
      'form': form,
      'state': get_state(),
      'event_name': event_name,
      'survey_link': event.survey_link,
      'is_interviewer': is_interviewer and is_assigned,
      'favorited': favorited(request.user.mcuser, applicant)
      }
  return render(request, 'feedback/applicant.html', context)
コード例 #24
0
ファイル: views.py プロジェクト: truongsinh/tykes
def add(request):
	if request.method == "POST":
		form = FeedbackForm(request.POST)
		
		if form.is_valid():
			if request.user.is_authenticated(): form.instance.user = request.user
			else: form.instance.user = None
			if 'HTTP_REFERER' in request.META:
				form.instance.context = request.META['HTTP_REFERER']
			form.save()
			return HttpResponse('', mimetype="text/plain")
		else:
			logger.debug(form.errors)
			error_msg = []
			for field in form.errors:
				for error in form.errors[field]:
					error_msg.append('%s: %s' % (form.fields[field].label, error))
			error_msg = '\n'.join(error_msg)
			
			return HttpResponseBadRequest(error_msg, mimetype="text/plain")
	else:
		return HttpResponseNotAllowed(["POST",])
コード例 #25
0
ファイル: views.py プロジェクト: zacharyvoase/django-retracer
def feedback(request):
    if request.method == 'GET':
        request.stash_referrer()
        # Display the form.
        return django.http.HttpResponse()
    elif request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            feedback = form.save()
            # Redirect to stashed location, or index.
            return request.unstash_location_with_default('index')
        else:
            # Display the form, with errors.
            return django.http.HttpResponseBadRequest()
    return django.http.HttpResponseNotAllowed(['GET', 'POST'])
コード例 #26
0
def add(request):
    if request.method == "POST":
        form = FeedbackForm(request.POST)

        if form.is_valid():
            if isinstance(request.user, User):
                form.instance.user = request.user
            if "HTTP_REFERER" in request.META:
                form.instance.page = request.META["HTTP_REFERER"]

            form.save()

            mail_from = getattr(settings, "FEEDBACK_SEND_MAIL_FROM", False)
            mail_to = getattr(settings, "FEEDBACK_SEND_MAIL_TO", False)
            if not mail_from and settings.ADMINS:
                mail_from = settings.ADMINS[0][1]
            if not mail_to and settings.ADMINS:
                mail_to = settings.ADMINS[0][1]
            if getattr(settings, "FEEDBACK_SEND_MAIL", False) and mail_from and mail_to:
                site_name = Site.objects.get_current().name
                send_mail(
                    "Feedback from %s" % site_name, "New Feedback message", mail_from, [mail_to], fail_silently=False
                )

            return HttpResponse("", mimetype="text/plain")
        else:
            logger.debug(form.errors)
            error_msg = []
            for field in form.errors:
                for error in form.errors[field]:
                    error_msg.append("%s: %s" % (form.fields[field].label, error))
            error_msg = "\n".join(error_msg)

            return HttpResponseBadRequest(error_msg, mimetype="text/plain")
    else:
        return HttpResponseNotAllowed(["POST"])
コード例 #27
0
def feedback_save(request):
    id = request.GET.get('id')

    if id == None:
        form = FeedbackForm(request.POST)
    else:
        instance = get_object_or_404(Feedback, pk=id)
        form = FeedbackForm(request.POST, instance=instance)

    try:
        if form.is_valid():
            instance = form.save()
            return JSONResponse({'id': instance.id})
        else:
            return JSONError(utils.dump_form_errors(form))
    except Exception, e:
        return JSONError(unicode(e))
コード例 #28
0
def submit_feedback(request):
    if request.method == 'GET':
        return render_to_response('feedback/feedback_form.html', 
            {'form': FeedbackForm()},
            context_instance=RequestContext(request))

    elif request.method == 'POST':
        form = FeedbackForm(request.POST)

        if form.is_valid():
            feedback = form.save(commit=False)
            feedback.is_spam = spam.is_spam(request, feedback.name, feedback.comment)
            feedback.save()
            return render_to_response('feedback/feedback_success.html',context_instance=RequestContext(request))

        return render_to_response('feedback/feedback_form.html',
                {'form':form},
                context_instance=RequestContext(request))
コード例 #29
0
ファイル: views.py プロジェクト: vault/bugit
def feedback_main(request):
    success = False
    if 'success' in request.GET:
        success = True

    if request.method == 'GET':
        form = FeedbackForm()
    elif request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            feedback = form.save(commit=False)
            feedback.sender = request.user
            feedback.save()
            furl = reverse('feedback') + '?success=1'
            return HttpResponseRedirect(furl)

    context = get_context(request, {'form':form, 'success':success})
    return render_to_response('feedback/feedback.html', context, context_instance=RequestContext(request))
コード例 #30
0
ファイル: views.py プロジェクト: dosberg/Feedback
def feedback_request(request):
    user = request.user

    class RequiredFormSet(BaseFormSet):
        def __init__(self, *args, **kwargs):
            super(RequiredFormSet, self).__init__(*args, **kwargs)
            for form in self.forms:
                form.empty_permitted = False

    QuestionFormSet = formset_factory(QuestionForm, max_num=10, formset=RequiredFormSet)
    if request.method == 'POST': 

        request_user = Request(user=request.user)
        request_form = FeedbackForm(request.POST, instance=request_user) # A form bound to the POST data
      
        # Create a formset from the submitted data
        question_formset = QuestionFormSet(request.POST, request.FILES)

        if request_form.is_valid() and question_formset.is_valid():
            request = request_form.save()
          
            for form in question_formset.forms:

                question = form.save(commit=False)
                question.request = request
                question.save()
              
            ''' 

            TODO: make this work 
            messages.success(request, 'Your request for feedback was sent to {{ email address }}!')
           
            '''
            return redirect('dashboard')
    else:
        request_form = FeedbackForm()
        question_formset = QuestionFormSet()

    return render_to_response('request.html', {
        'request_form': request_form,
        'question_formset': question_formset,
        'user': user,
    }, RequestContext(request))
コード例 #31
0
ファイル: views.py プロジェクト: vault/bugit
def feedback_main(request):
    success = False
    if 'success' in request.GET:
        success = True

    if request.method == 'GET':
        form = FeedbackForm()
    elif request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            feedback = form.save(commit=False)
            feedback.sender = request.user
            feedback.save()
            furl = reverse('feedback') + '?success=1'
            return HttpResponseRedirect(furl)

    context = get_context(request, {'form': form, 'success': success})
    return render_to_response('feedback/feedback.html',
                              context,
                              context_instance=RequestContext(request))
コード例 #32
0
ファイル: views.py プロジェクト: mwotil/nuaza
def rate_user(request, product_slug, template_name="pdcts/rate_user.html"):
	page_title = "Rate User"
	if request.method =='POST':
		form = FeedbackForm (request.POST)
		p = get_object_or_404(Product, slug=product_slug)

		check = Feedback.objects.filter(user=request.user, product=p)
		own_check = Feedback.objects.filter(user=p.user)

		if form.is_valid():

			if check or own_check:
				chck = "You can only rate this user once for this Product" 
				own_chck = "You can't rate yourself" 
				form = FeedbackForm()

			else:

				rate = form.save(commit=False)
				rate.user = request.user
				rate.product = p
				rate.save()
			
				reputation = User_Reputation.objects.filter(user = p.user)

				if reputation:
					r = User_Reputation.objects.get(user = p.user)

					alpha = rate.rating

					beta = 1 - alpha
					repute = r.reputation
					entity_alpha = r.entity_alpha
					entity_beta =  r.entity_beta
					votes = r.votes
					entity_alpha += alpha
					entity_beta += beta
					votes += 1
					entity_reputation = (entity_alpha/(entity_alpha + entity_beta))

					new_repute = (repute + entity_reputation)/2

					r.reputation = new_repute
					r.votes = votes
					r.entity_alpha = entity_alpha
					r.entity_beta = entity_beta
					r.save()

				


				else:
					r = User_Reputation()
					r.user = p.user
					r.reputation = 0.5
					r.entity_alpha = 0.5
					r.entity_beta = 0.5
					r.votes = 0
					r.save()


			


				return HttpResponseRedirect('/home/')
	

	else:
		form = FeedbackForm()
	return render_to_response(template_name, locals(), context_instance = RequestContext(request))
コード例 #33
0
ファイル: views.py プロジェクト: ariedov/The-Stars-Project
def post_message(request):
    form = FeedbackForm(data=request.POST or None)
    if form.is_valid():
        form.save()
        return dict(status=_(u"Спасибо"), errors=u"")
    return dict(status=_(u"Ошибка"), errors=form.errors.as_ul())
コード例 #34
0
ファイル: views.py プロジェクト: mwotil/nuaza
def rate_user(request, product_slug, template_name="pdcts/rate_user.html"):
    page_title = "Rate User"
    if request.method == 'POST':
        form = FeedbackForm(request.POST)
        p = get_object_or_404(Product, slug=product_slug)

        check = Feedback.objects.filter(user=request.user, product=p)
        own_check = Feedback.objects.filter(user=p.user)

        if form.is_valid():

            if check or own_check:
                chck = "You can only rate this user once for this Product"
                own_chck = "You can't rate yourself"
                form = FeedbackForm()

            else:

                rate = form.save(commit=False)
                rate.user = request.user
                rate.product = p
                rate.save()

                reputation = User_Reputation.objects.filter(user=p.user)

                if reputation:
                    r = User_Reputation.objects.get(user=p.user)

                    alpha = rate.rating

                    beta = 1 - alpha
                    repute = r.reputation
                    entity_alpha = r.entity_alpha
                    entity_beta = r.entity_beta
                    votes = r.votes
                    entity_alpha += alpha
                    entity_beta += beta
                    votes += 1
                    entity_reputation = (entity_alpha /
                                         (entity_alpha + entity_beta))

                    new_repute = (repute + entity_reputation) / 2

                    r.reputation = new_repute
                    r.votes = votes
                    r.entity_alpha = entity_alpha
                    r.entity_beta = entity_beta
                    r.save()

                else:
                    r = User_Reputation()
                    r.user = p.user
                    r.reputation = 0.5
                    r.entity_alpha = 0.5
                    r.entity_beta = 0.5
                    r.votes = 0
                    r.save()

                return HttpResponseRedirect('/home/')

    else:
        form = FeedbackForm()
    return render_to_response(template_name,
                              locals(),
                              context_instance=RequestContext(request))