Esempio n. 1
0
def ajax_feedback(request):
    data = request.POST.copy()

    res = {
        'status': 'NODATA',
        'errors': None,
    }

    feedback_form = FeedbackForm(data=data)
    if feedback_form.is_bound:
        if feedback_form.is_valid():
            feedback = feedback_form.save(commit=False)
            feedback.site = sites_models.Site.objects.get_current()
            if request.user.id:
                feedback.user = request.user
            feedback.save()

            res = {
                'status': 'OK',
                'errors': None,
            }

        else:
            res = {
                'status': 'NOK',
                'errors': feedback_form.errors,
            }

    return HttpResponse(simplejson.dumps(res), content_type='text/json')
Esempio n. 2
0
def create(request):
    error = ''
    if request.method == 'POST':
        yesterday = timezone.now() - timezone.timedelta(minutes=1)
        if Feedback.objects.filter(user=request.user, creation_time__gt=yesterday).exists():
            raise PermissionDenied()
        form = FeedbackForm(request.POST, request.FILES)
        if form.is_valid():
            feedback = form.save(commit=False)
            feedback.user = request.user
            feedback.save()
            email = EmailMessage(
                subject=feedback.title,
                body=feedback.description,
                to=[a[1] for a in MANAGERS],
                reply_to=[feedback.user.email]
            )
            if request.FILES:
                path_to_file = os.path.join(MEDIA_ROOT, feedback.attachment.name)
                email.attach_file(path_to_file)
            email.send()
            return redirect('success')
        else:
            error = 'Incorrect form!!'

    else:
        form = FeedbackForm()
    context = {
        'form': form,
        'error': error
    }
    return render(request, "feedback/create.html", context)
Esempio n. 3
0
def index(request):

    if request.method == 'POST':

        f = FeedbackForm(data=request.POST)
        if f.is_valid():
            f.instance.create_date = datetime.datetime.now()
            f.save()

            mail_template = MailTemplate.objects.get(code__exact='FEEDBACK')
            body = mail_template.body.replace('###hostname###', request.get_host())
            body = body.replace('###email###', f.instance.email)
            body = body.replace('###user_name###', f.instance.user_name)
            body = body.replace('###subject###', f.instance.subject.title)
            body = body.replace('###body###', f.instance.body)
            body = body.replace('###is_answer_needed###', u'Да' if f.instance.is_answer_needed else u'Нет')

            email = EmailMessage(
                mail_template.subject,
                body,
                mail_template.from_email,
                [mail_template.admin_email, ],
                [mail_template.copy_emails, ],
                headers={'Reply-To': mail_template.from_email, 'From': mail_template.from_name}
            )

            email.content_subtype = "html"
            email.send()
            messages.add_message(request, messages.SUCCESS, _("Message sent successfully!"))
            return redirect('feedback_success')

    else:
        f = FeedbackForm()

    return render(request, 'feedback/index.html', {'form': f})
Esempio n. 4
0
def submitFeedback(request):
    if request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            user = request.user
            feedback_message = form.cleaned_data['feedback_message']

            feedback = Feedback.objects.create(
                user=user, feedback_message=feedback_message)

            feedback_message_email = "From: %s <%s>\nFeedback:\n\n%s" % (
                user.get_full_name(), user.email, feedback_message)
            send_mail(
                'Student Explorer Feedback (%s, id: %s)' %
                (user.email, feedback.id),
                feedback_message_email,
                settings.FEEDBACK_EMAIL,
                (settings.FEEDBACK_EMAIL, ),
                fail_silently=False,
            )
            messages.add_message(request, messages.SUCCESS,
                                 'Thank you for submitting your feedback!')
            return HttpResponseRedirect('/')
    else:
        form = FeedbackForm()

    return render(request, 'feedback/feedback.html', {'form': form})
Esempio n. 5
0
def feedback(request):
	"""
	Add feedback
	"""
	
	if request.method == 'POST':
		
		form = FeedbackForm(request.POST)
		if form.is_valid():
			
			new_fb = form.save(commit=False)
			new_fb.user_agent = request.META['HTTP_USER_AGENT']
			new_fb.save()

			#admin = User.objects.filter(pk=settings.ADMINS)

			# Send an email to the admin letting them know that feedback was submitted
			subject = render_to_string('feedback/email_subject.txt')
			message = render_to_string('feedback/email_body.txt',
									   { 'feedback': form.cleaned_data['feedback'], 'user_agent':request.META['HTTP_USER_AGENT']})
			recipients = [settings.ADMINS]
			send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, recipients)

			return HttpResponseRedirect('/feedback-thanks/')
	
	else:
		
		form = FeedbackForm()

	return render_to_response('feedback/feedback_form.html', {
		'form':form,
	}, context_instance=RequestContext(request))
Esempio n. 6
0
def index(request):
	form = FeedbackForm()
	msg = None

	if request.method=='POST':	
		form = FeedbackForm(request.POST)		
		
		if form.is_valid():
			name = form.cleaned_data['name']
			email = form.cleaned_data['email']
			feedback = form.cleaned_data['feedback']
			#save to database and email to group
			new_obj = form.save(commit=False)
			new_obj.date_sub = datetime.now()	
			new_obj.save()
			form.save_m2m()	
			subject = '[Website Feedback] Feedback from %s'%(name)
			html_content = 'Hello Team.<br /> Following is a feedback on EDC website from <strong>%s</strong>. Concerned authority should reply to this feedback at <strong>%s</strong> as soon as possible. <br /><br /><span style="border:2px;border-style:solid;width:800px;display:block;"><p style="margin-left:20px;">%s</p></span><hr /><span style="color:grey;">You have received this message because the Website feedbacks have been programmed to be sent automatically to the EDC group. If you do not want to receive feedbacks on group, please hire another python programmer. </span><br /><br />Regards,<br/>Webmaster'%(name,email,feedback)
			from_email = '*****@*****.**'
			mail = EmailMessage(subject, html_content, "*****@*****.**", ["*****@*****.**"])
			mail.content_subtype = "html"  # Main content is now text/html
			mail.send()
			msg = 'Your feedback was recorded successfully. Thanks much! We shall get back to you soon.'

	return render_to_response('feedback/feedback.html',{'name':'Feedback','list':menu,'form':form,'msg':msg},context_instance=RequestContext(request)) 	
 def post(self, request, *args, **kwargs):
     form = FeedbackForm(request.POST)
     if form.is_valid():
         return self.form_valid(form)
     else:
         # Form isn't valid, return generic 400
         return http.HttpResponseBadRequest()
Esempio n. 8
0
def getFeedback(request, templateName):
    if request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            clean = form.cleaned_data
            if request.user.is_authenticated():
                no = request.user.last_name
            else:
                no = '匿名'
            Feedback.objects.create(
                netid = no,
                content = clean['content'],
                campus = clean['campus'],
                name = clean['name'],
                phone = clean['phone'],
                email = clean['email'],
                )
        else:
            print form.errors
            return HttpResponseRedirect('/feedback/')
    else:
        form = FeedbackForm()
    return render_to_response(templateName, {
        'form' : form,
        }, context_instance = RequestContext(request))
Esempio n. 9
0
 def post(self, request):
     cek_session(request)
     elder = None
     if request.session.get('active_elder') is not None and request.session[
             'active_elder'] != 0:
         elder = Elder.objects.get(pk=request.session.get('active_elder'))
     elders = Elder.get_cared_elder(user=CareGiver.objects.get(
         user=request.user))
     feedback = Feedback.objects.filter(owner=request.user)
     form = FeedbackForm(request.POST)
     if form.is_valid():
         new = form.save(commit=False)
         new.status = 's'
         new.owner = request.user
         new.save()
         feedback = Feedback.objects.filter(owner=request.user)
         return render(
             request, 'feedback.html', {
                 'elders': elders,
                 'success': 'Feedback berhasil ditambahkan',
                 'active_elder': elder,
                 'feedback': feedback
             })
     else:
         return render(
             request, 'feedback.html', {
                 'elders': elders,
                 'error': form.errors,
                 'active_elder': elder,
                 'feedback': feedback
             })
Esempio n. 10
0
def ajax_feedback(request):
    data = request.POST.copy()

    res = {
        'status': 'NODATA',
        'errors': None,
    }

    feedback_form = FeedbackForm(data=data)
    if feedback_form.is_bound:
        if feedback_form.is_valid():
            feedback = feedback_form.save(commit=False)
            feedback.site = sites_models.Site.objects.get_current()
            if request.user.id:
                feedback.user = request.user
            feedback.save()

            res = {
                'status': 'OK',
                'errors': None,
            }

        else:
            res = {
                'status': 'NOK',
                'errors': feedback_form.errors,
            }

    return HttpResponse(simplejson.dumps(res), content_type='text/json')
Esempio n. 11
0
def leave_feedback(request, template_name='feedback/feedback_form.html'):
    if request.method == "GET":
        nexturl = request.GET.get('next')
    else:
        nexturl = request.POST.get('next')

    if request.user.is_authenticated():
        form = FeedbackForm(request.POST or None)
    else:
        form = AnonymousFeedbackForm(request.POST or None)
    if form.is_valid():
        feedback = form.save(commit=False)
        if request.user.is_anonymous():
            feedback.user = None
        else:
            feedback.user = request.user
        feedback.save()
        messages.add_message(request, messages.SUCCESS,
                             'Your feedback was submitted.')
        return HttpResponseRedirect(nexturl)

    return render_to_response(
                                template_name, 
                                {
                                'feedback_form': form,
                                'next': nexturl
                                },
                                context_instance=RequestContext(request))
Esempio n. 12
0
    def test_form(self):
        form_file_data = dict()
        form_data = dict(
            description='Test description',
        )

        form = FeedbackForm(form_data, form_file_data)
        self.assertTrue(form.is_valid())
Esempio n. 13
0
def leave_feedback(request, template_name='feedback/feedback_form.html'):
    '''
	Generate and manage the form for feedback, and ulterior AJAX exchanges
    Only respond to Ajax call.
    Will return Http404 in case of non-xhr request
    
	Parameters
	----------
	request : HttpRequest
		user request sent by browser
	template_url : string
		Url of the template to use for rendering 

	'''
    if request.is_ajax():

        # Create Form
        if request.user.is_authenticated():
            form = FeedbackForm(request.POST or None)
        elif getattr(settings, 'ALLOW_ANONYMOUS_FEEDBACK', False):
            form = AnonymousFeedbackForm(request.POST or None)
        else:
            raise Http404

        # POST
        if request.method == 'POST':
            if form.is_valid():
                feedback = form.save(commit=False)
                if request.user.is_anonymous():
                    feedback.user = None
                else:
                    feedback.user = request.user
                try:
                    feedback.context_url = request.META['HTTP_REFERER']
                    feedback.browser = request.META['HTTP_USER_AGENT']
                except KeyError:
                    pass
                feedback.save()
                data = {
                    'success':
                    _('Your feedback has been sent to us! Thanks a lot.')
                }
            else:
                data = {
                    'success':
                    False,
                    'errors':
                    dict([(k, [unicode(e) for e in v])
                          for k, v in form.errors.items()])
                }
            return JSONResponse(request, data)
        else:
            context = {
                'feedback_form': form,
            }
            return render(request, template_name, context)
    else:
        raise Http404
Esempio n. 14
0
def leave_feedback(request, template_name='feedback/feedback_form.html'):
    form = FeedbackForm(request.POST or None)
    if form.is_valid():
        feedback = form.save(commit=False)
        feedback.user = request.user
        feedback.save()
        request.user.message_set.create(message=_("Your feedback has been saved successfully."))
        return HttpResponseRedirect(request.POST.get('next', request.META.get('HTTP_REFERER', '/')))
    return render_to_response(template_name, {'feedback_form': form}, context_instance=RequestContext(request))
Esempio n. 15
0
 def post(self, request, *args, **kwargs):
     form = FeedbackForm(request.POST)
     result = {"success":False,"message":"Something in the form submission failed, we're looking into it"}
     if form.is_valid():
         feedback = form.save(commit=False)
         feedback.user = request.user
         feedback.save()
         
         result = {"success":True,"message":"Thank You"}
     return HttpResponse(simplejson.dumps(result), mimetype='application/json') 
Esempio n. 16
0
def leave_feedback(request, template_name='feedback/feedback_form.html'):
    form = FeedbackForm(request.POST or None, initial={
        'next': getattr(settings, 'FEEDBACK_REDIRECT_URL', request.get_full_path())
    })
    if form.is_valid():
        feedback = form.save(commit=False)
        feedback.user = request.user
        feedback.save()
        messages.success(request, _("Your feedback has been saved successfully."))
        return HttpResponseRedirect(form.cleaned_data.get('next', request.META.get('HTTP_REFERER', '/')))
    return render_to_response(template_name, {'feedback_form': form}, context_instance=RequestContext(request))
Esempio n. 17
0
def submit_bug(request):
  # if the request is a POST request
  if request.method == 'POST':
    form = FeedbackForm(request.POST)
    if form.is_valid():
      form.save()
      return HttpResponseRedirect('/bugs/merci')

  # if the request is a GET request
  else:
    form = FeedbackForm()
  return render(request, "feedback/submit.html", { 'form' : form })
Esempio n. 18
0
def leave_feedback(request):
    if request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            feedback = form.save()
            
            if feedback.user:
                request.user.message_set.create(message="Your feedback has been saved successfully.")
            return HttpResponseRedirect(request.POST.get('next', request.META.get('HTTP_REFERER', '/')))
    else:
        form = FeedbackForm(request.GET)
    return render_to_response('feedback/feedback_form.html', {'form': form}, context_instance=RequestContext(request))
Esempio n. 19
0
def feedback_ajax(request):
    form = FeedbackForm(request.POST)
    if form.is_valid():
        email = form.cleaned_data['email']
        message = form.cleaned_data['message']
        Feedback(email=email, message=message, type="gen", status=1).save()
        return {
            'status': 201,
            'message': _('Success! Thanks for taking the time to write.')}
    else:
        return {
            'status': 400,
            'message': _(u"Not valid data")}
Esempio n. 20
0
def leave_feedback(request, template_name='feedback/feedback_form.html'):
    """
    returns a feedback form if GET and validates,saves it if POST
    redirects back after save
    """
    form = FeedbackForm(request.POST or None)
    if form.is_valid():
        feedback = form.save(commit=False)
        feedback.save()
        messages.add_message(request, messages.SUCCESS, "Your feedback was submitted.")
        #redirecting back
        return HttpResponseRedirect(request.POST.get('next', request.META.get('HTTP_REFERER', '/')))
    return render_to_response(template_name, {'feedback_form': form}, context_instance=RequestContext(request))
Esempio n. 21
0
def leave_feedback(request, template_name='feedback/feedback_form.html'):
    form = FeedbackForm(request.POST or None)
    if form.is_valid():
        feedback = form.save(commit=False)
        feedback.user = request.user
        feedback.site = sites_models.Site.objects.get_current()
        feedback.save()
        request.user.message_set.create(
            message=_("Your feedback has been saved successfully."))
        return HttpResponseRedirect(
            request.POST.get('next', request.META.get('HTTP_REFERER', '/')))
    return render_to_response(template_name, {'feedback_form': form},
                              context_instance=RequestContext(request))
Esempio n. 22
0
def contacts(request):
    c = get_common_context(request)
    c.update({'content': Page.get('contacts', c['lang'])['content']})
    if request.method == 'GET':
        c.update({'form': FeedbackForm()})
    elif request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            form.save()
            form = FeedbackForm()
            c['feedback_ok'] = True
        c.update({'form': form})
    return render_to_response('contacts.html', c, context_instance=RequestContext(request))
Esempio n. 23
0
def contacts(request):
    c = get_common_context(request)
    c.update({"p": Page.get_by_slug("contacts")})
    if request.method == "GET":
        c.update({"form": FeedbackForm()})
        return render_to_response("contacts.html", c, context_instance=RequestContext(request))
    elif request.method == "POST":
        form = FeedbackForm(request.POST)
        if form.is_valid():
            form.save()
            form = FeedbackForm()
        c.update({"form": form})
        return render_to_response("contacts.html", c, context_instance=RequestContext(request))
Esempio n. 24
0
def leave_feedback(request, message='Thanks for your feedback!', message_level=messages.SUCCESS):
    form = FeedbackForm(request.POST or None)
    if form.is_valid():
        feedback = form.save(commit=False)
        feedback.page = request.POST.get('next', request.META.get('HTTP_REFERER', '/'))
        if request.user.is_authenticated():
            feedback.user = request.user
            messages.add_message(request, message_level, message)
        feedback.save()
        if settings.FEEDBACK_SENDS_EMAIL:
            feedback.send_feedback_email()
        return HttpResponseRedirect(feedback.page)
    return render_to_response('feedback/feedback_form.html', {'form': form}, context_instance=RequestContext(request))
Esempio n. 25
0
def show_feedback_form(request):
    if request.POST:
        form = FeedbackForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('success_post.html')

    else:
        form = FeedbackForm()

    context = RequestContext(request)
    context.update({'active_menu':'feedback'})
    return render_to_response('submit_feedback.html', {'form':form}, context_instance=context)
Esempio n. 26
0
def leave_feedback(request, template_name='feedback/feedback_form.html'):
	'''
	Generate and manage the form for feedback, and ulterior AJAX exchanges
    Only respond to Ajax call.
    Will return Http404 in case of non-xhr request
    
	Parameters
	----------
	request : HttpRequest
		user request sent by browser
	template_url : string
		Url of the template to use for rendering 

	'''
	if request.is_ajax():

		# Create Form
		if request.user.is_authenticated():
			form = FeedbackForm(request.POST or None)
		elif getattr(settings, 'ALLOW_ANONYMOUS_FEEDBACK', False):
			form = AnonymousFeedbackForm(request.POST or None)
		else:
			raise Http404

		# POST
		if request.method == 'POST':
			if form.is_valid():
				feedback = form.save(commit=False)
				if request.user.is_anonymous():
					feedback.user = None
				else:
					feedback.user = request.user
				try:
					feedback.context_url = request.META['HTTP_REFERER']
					feedback.browser = request.META['HTTP_USER_AGENT']
				except KeyError:
					pass
				feedback.save()
				data = {'success': _('Your feedback has been sent to us! Thanks a lot.')}
			else:
				data = {
                'success': False,
                'errors': dict([(k, [unicode(e) for e in v]) for k,v in form.errors.items()])}
			return JSONResponse(request, data)
		else :
			context = {
				'feedback_form':form,
			}
			return render(request, template_name, context)
	else :
		raise Http404
Esempio n. 27
0
def show_feedback_form(request):
    if request.POST:
        form = FeedbackForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('success_post.html')

    else:
        form = FeedbackForm()

    context = RequestContext(request)
    context.update({'active_menu': 'feedback'})
    return render_to_response('submit_feedback.html', {'form': form},
                              context_instance=context)
Esempio n. 28
0
    def test_form_no_description(self):
        form_file_data = dict(
            screenshot=SimpleUploadedFile('screenshot.png', b' '),
            blackbox=SimpleUploadedFile('blackbox.tar', b' '),
            system_logs=SimpleUploadedFile('system_logs.zip', b' '),
            attached_file=SimpleUploadedFile('attach.zip', b' '),
        )
        form_data = dict(
            email='*****@*****.**',
            page_url='http://url.com/',
        )

        form = FeedbackForm(form_data, form_file_data)
        self.assertFalse(form.is_valid())
Esempio n. 29
0
def feedback(request):
    if request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            message = form.cleaned_data['message']
            Feedback(email=email, message=message, type="gen", status=1).save()
            return HttpResponseRedirect(reverse('feedback_completed'))
            return render_to_response('feedback_completed.html', {}, request)
    else:
        form = FeedbackForm()

    return render_to_response('feedback.html', {
        'form': form}, request)
Esempio n. 30
0
    def test_form_no_description(self):
        form_file_data = dict(
            screenshot=SimpleUploadedFile('screenshot.png', b' '),
            blackbox=SimpleUploadedFile('blackbox.tar', b' '),
            system_logs=SimpleUploadedFile('system_logs.zip', b' '),
            attached_file=SimpleUploadedFile('attach.zip', b' '),
        )
        form_data = dict(
            email='*****@*****.**',
            page_url='http://url.com/',
        )

        form = FeedbackForm(form_data, form_file_data)
        self.assertFalse(form.is_valid())
Esempio n. 31
0
def feedback(request):
    items = Feedback.objects.all()
    if request.method == "POST":
        form = FeedbackForm(request.POST)
        if form.is_valid():
            item = form.save(commit=False)
            item.save()
    else:
        form = FeedbackForm()
    return render(request, 'feedback/feedback.html', {
        'items': items,
        'form': form,
        'title': 'Feedback',
    })
Esempio n. 32
0
def leave_feedback(request, template_name='feedback/feedback_form.html'):
    if request.user.is_authenticated():
        form = FeedbackForm(request.POST or None)
    else:
        form = AnonymousFeedbackForm(request.POST or None)
    if form.is_valid():
        feedback = form.save(commit=False)
        if request.user.is_anonymous():
            feedback.user = None
        else:
            feedback.user = request.user
        feedback.save()
        messages.add_message(request, messages.SUCCESS, "Your feedback was submitted.")
        return HttpResponseRedirect(request.POST.get('next', request.META.get('HTTP_REFERER', '/')))
    return render_to_response(template_name, {'feedback_form': form}, context_instance=RequestContext(request))
Esempio n. 33
0
File: views.py Progetto: kpx13/vv
def contacts(request):
    c = get_common_context(request)
    c['title'] = u'Контакты'
    c['content'] = Page.get_by_slug('contacts').content 
    
    form = FeedbackForm()
    if request.method == 'POST':
        if request.POST['action'] == 'feedback':
            form = FeedbackForm(request.POST)
            if form.is_valid():
                form.save()
                c['form_send'] = True        
    c['form'] = form
    
    return render_to_response('contacts.html', c, context_instance=RequestContext(request))
Esempio n. 34
0
def contacts(request):
    reset_catalog(request)
    c = get_common_context(request)
    if request.method == 'GET':
        c['form'] = FeedbackForm()
    else:
        form = FeedbackForm(request.POST)
        if form.is_valid():
            form.save()
            form = FeedbackForm()
            c['msg_sent'] = u'Ваш отзыв отправлен. Спасибо.'
        else:
            c['request_form'] = form
        c['form'] = form
    return render_to_response('contacts.html', c, context_instance=RequestContext(request))
Esempio n. 35
0
def list_feedbacks(request):
	if request.method == 'POST':
		form = FeedbackForm(request.POST)
		if form.is_valid():
			feedback = form.save(commit=False)
			feedback.author = request.user
			feedback.save()

	feedbacks = Feedback.objects.all().order_by('-published')
	feedback_list = []
	for feedback in feedbacks:
		feedback_list.append({'feedback':feedback, 'commentform': CommentForm(initial={'feedback':feedback})})

	new_feedback = FeedbackForm()

	return render('feedback/feedback_list.html', {'feedback':feedback_list, 'form':new_feedback}, request)
Esempio n. 36
0
    def post(self, request):
        data = {}
        feedback = Feedback(ip=get_client_ip(request))
        form = FeedbackForm(request.POST, request.FILES, instance=feedback)

        if form.is_valid():
            form.save();
            response = HttpResponse("1")
            message = ugettext("Your feedback is sent. "
                               "We will work on that as soon as possible.")
            response['messages'] = json.dumps({"success": [message]})
            return response

        data['form'] = form

        return TemplateResponse(request, self.template_name, data)
Esempio n. 37
0
File: views.py Progetto: kpx13/zb
def audiobook(request):
    c = get_common_context(request)
    c["text_6"] = TextBlock.get_by_id(6)

    form = FeedbackForm()
    if request.method == "POST":
        form = FeedbackForm(request.POST)
        if form.is_valid():
            f = form.save(commit=False)
            f.type = u"Получение аудиокниги"
            f.save()
            c["form_send"] = True
            jc_send(f.name.encode("utf-8"), f.email.encode("utf-8"))
            f.send()
    c["form"] = form
    return render_to_response("audiobook.html", c, context_instance=RequestContext(request))
Esempio n. 38
0
    def post(self, request, *args, **kwargs):
        form = FeedbackForm(request.POST)
        result = {
            "success":
            False,
            "message":
            "Something in the form submission failed, we're looking into it"
        }
        if form.is_valid():
            feedback = form.save(commit=False)
            feedback.user = request.user
            feedback.save()

            result = {"success": True, "message": "Thank You"}
        return HttpResponse(simplejson.dumps(result),
                            mimetype='application/json')
Esempio n. 39
0
    def test_form(self):
        form_file_data = dict(
            screenshot=SimpleUploadedFile('screenshot.png',
                                          content=open(IMG_FILE, 'rb').read()),
            blackbox=SimpleUploadedFile('blackbox.tar', b' '),
            system_logs=SimpleUploadedFile('system_logs.zip', b' ' * 2),
            attached_file=SimpleUploadedFile('attach.zip', b' ' * 3),
        )
        form_data = dict(description='Test description', )

        form = FeedbackForm(form_data, form_file_data)
        self.assertTrue(form.is_valid())
        self.assertEqual(form.cleaned_data['screenshot_size'], 88)
        self.assertEqual(form.cleaned_data['blackbox_size'], 1)
        self.assertEqual(form.cleaned_data['system_logs_size'], 2)
        self.assertEqual(form.cleaned_data['attached_file_size'], 3)
Esempio n. 40
0
def leave_feedback(request, template_name='contacts.html'):
    contacts = FlatPage.objects.get(url=request.path)
    form = FeedbackForm(request.POST or None)
    if form.is_valid():
        feedback = form.save(commit=False)
        feedback.save()
        message = "Your feedback was submitted."
        cd = form.cleaned_data
        send_mail(
                '%s(%s)'%(cd['name'], cd['phone']),
                cd['message'],
                cd.get('email', '*****@*****.**'),
                ['*****@*****.**'])
        #redirecting back
        return HttpResponseRedirect(request.POST.get('next', request.META.get('HTTP_REFERER', '/')))
        # return render_to_response(template_name, {'next' : request.GET.get('next', '/'), 'feedback_form': FeedbackForm(None), 'mes':message}, context_instance=RequestContext(request))
    return render_to_response(template_name, {'feedback_form': form, 'contacts': contacts}, context_instance=RequestContext(request))
Esempio n. 41
0
    def test_form(self):
        form_file_data = dict(
            screenshot=SimpleUploadedFile('screenshot.png', content=open(IMG_FILE, 'rb').read()),
            blackbox=SimpleUploadedFile('blackbox.tar', b' '),
            system_logs=SimpleUploadedFile('system_logs.zip', b' '*2),
            attached_file=SimpleUploadedFile('attach.zip', b' '*3),
        )
        form_data = dict(
            description='Test description',
        )

        form = FeedbackForm(form_data, form_file_data)
        self.assertTrue(form.is_valid())
        self.assertEqual(form.cleaned_data['screenshot_size'], 88)
        self.assertEqual(form.cleaned_data['blackbox_size'], 1)
        self.assertEqual(form.cleaned_data['system_logs_size'], 2)
        self.assertEqual(form.cleaned_data['attached_file_size'], 3)
Esempio n. 42
0
def contacts(request):
    c = get_common_context(request)
    c.update({'p': Page.get_by_slug('contacts')})
    if request.method == 'GET':
        c.update({'form': FeedbackForm()})
        return render_to_response('contacts.html',
                                  c,
                                  context_instance=RequestContext(request))
    elif request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            form.save()
            form = FeedbackForm()
        c.update({'form': form})
        return render_to_response('contacts.html',
                                  c,
                                  context_instance=RequestContext(request))
Esempio n. 43
0
def submit_feedback(request):

    submitted = False

    feedback_form = FeedbackForm(data=request.POST)

    if request.method == 'POST':

        if feedback_form.is_valid():

            f = feedback_form.save(commit=False)
            f.save()
            submitted = True

    return render_to_response(
        'feedback/feedback.html',
        {'submitted':submitted,},
        RequestContext(request))
Esempio n. 44
0
def leave_feedback(request, template_name='feedback/feedback_form.html'):
    form = FeedbackForm(request.POST or None,
                        initial={
                            'next':
                            getattr(settings, 'FEEDBACK_REDIRECT_URL',
                                    request.get_full_path())
                        })
    if form.is_valid():
        feedback = form.save(commit=False)
        feedback.user = request.user
        feedback.save()
        messages.success(request,
                         _("Your feedback has been saved successfully."))
        return HttpResponseRedirect(
            form.cleaned_data.get('next',
                                  request.META.get('HTTP_REFERER', '/')))
    return render_to_response(template_name, {'feedback_form': form},
                              context_instance=RequestContext(request))
Esempio n. 45
0
def leave_feedback(request, template_name='feedback/feedback_form.html'):
    if request.user.is_authenticated():
        form = FeedbackForm(request.POST or None)
    else:
        form = AnonymousFeedbackForm(request.POST or None)
    if form.is_valid():
        feedback = form.save(commit=False)
        if request.user.is_anonymous():
            feedback.user = None
        else:
            feedback.user = request.user
        feedback.save()
        messages.add_message(request, messages.SUCCESS,
                             "Your feedback was submitted.")
        return HttpResponseRedirect(
            request.POST.get('next', request.META.get('HTTP_REFERER', '/')))
    return render_to_response(template_name, {'feedback_form': form},
                              context_instance=RequestContext(request))
Esempio n. 46
0
def feedback_view(request):
    if request.method == "POST":
        form = FeedbackForm(request.POST)
        if form.is_valid():
            form.save()
            messages.success(
                request,
                "Thanks for your feedback! {}".format(SIGNATURE))
            return redirect('feedback')
        else:
            messages.error(
                request,
                "Thanks, but your feedback couldn't be accepted "
                "due to errors. {}".format(SIGNATURE))
            pass  # fallthrough to render
    else:  # GET
        form = FeedbackForm()
    return render(request, 'feedback.html',
                  {'subject': settings.FEEDBACK_SUBJECT, 'form': form})
Esempio n. 47
0
def submit(request):
    if request.method == 'POST':
        f_form = FeedbackForm(request.POST)
        if f_form.is_valid():
            f_obj = f_form.save()
            send_mail(
                'Feedback Submitted',
                'Thanks for submitting your suggestion.',
                settings.DEFAULT_FROM_EMAIL,
                [f_obj.feedback_email],
            )
            return HttpResponse('Thanks for submitting your suggestion.')
        else:
            error_fields = f_form.errors.keys()
            for each_field in error_fields:
                f_form.fields[each_field].widget.attrs['class'] = 'textbox_error'
    else:
        f_form = FeedbackForm()
    return render_to_response('feedback_form.html', locals(), context_instance = RequestContext( request ))
Esempio n. 48
0
def index(request):

    if request.method == 'POST':

        f = FeedbackForm(user=request.user, data=request.POST)
        if f.is_valid():

            if request.user.is_authenticated():
                f.instance.user = request.user

            f.save()

            # отправляем письмо с данными учетной записи пользователю
            mail_template = MailTemplate.objects.get(
                code__exact='USERFEEDBACK')
            body = mail_template.body.replace('###hostname###',
                                              request.get_host())
            body = body.replace('###author_email###', f.instance.author_email)
            body = body.replace('###subject###', f.instance.subject)
            body = body.replace('###body###', f.instance.body)

            email = EmailMessage(mail_template.subject,
                                 body,
                                 mail_template.from_email, [
                                     mail_template.admin_email,
                                 ],
                                 mail_template.copy_emails.split(';'),
                                 headers={
                                     'Reply-To': mail_template.from_email,
                                     'From': mail_template.from_name
                                 })

            email.content_subtype = "html"
            email.send()
            messages.add_message(request, messages.SUCCESS,
                                 "Сообщение успешно отправлено!")
            return redirect('feedback_index')

    else:
        f = FeedbackForm()

    return render(request, 'feedback/index.html', {'form': f})
Esempio n. 49
0
def index(request):

    if request.method == 'POST':

        f = FeedbackForm(data=request.POST)
        if f.is_valid():
            f.instance.create_date = datetime.datetime.now()
            f.save()

            mail_template = MailTemplate.objects.get(code__exact='FEEDBACK')
            body = mail_template.body.replace('###hostname###',
                                              request.get_host())
            body = body.replace('###email###', f.instance.email)
            body = body.replace('###user_name###', f.instance.user_name)
            body = body.replace('###subject###', f.instance.subject.title)
            body = body.replace('###body###', f.instance.body)
            body = body.replace(
                '###is_answer_needed###',
                u'Да' if f.instance.is_answer_needed else u'Нет')

            email = EmailMessage(mail_template.subject,
                                 body,
                                 mail_template.from_email, [
                                     mail_template.admin_email,
                                 ], [
                                     mail_template.copy_emails,
                                 ],
                                 headers={
                                     'Reply-To': mail_template.from_email,
                                     'From': mail_template.from_name
                                 })

            email.content_subtype = "html"
            email.send()
            messages.add_message(request, messages.SUCCESS,
                                 _("Message sent successfully!"))
            return redirect('feedback_success')

    else:
        f = FeedbackForm()

    return render(request, 'feedback/index.html', {'form': f})
Esempio n. 50
0
 def post(self, request):
     context = {}
     form = FeedbackForm(request.POST)
     if form.is_valid():
         form.save()
         context['data'] = form.cleaned_data
         value = form.cleaned_data['gender']
         if value == 1:
             context['data']['gender'] = 'Мужской'
         else:
             context['data']['gender'] = 'Женский'
         value = form.cleaned_data['service']
         if value == 1:
             context['data']['service'] = "Покупка квартиры"
         elif value == 2:
             context['data']['service'] = "Работа персонала"
         elif value == 3:
             context['data']['service'] = "Использование сайта"
         elif value == 4:
             context['data']['service'] = "Прочее"
     return render(request, "feedback.html", context)
def feedback_process(request):
    User = get_object_or_404(Profile, pk=request.user.pk)
    contact_template = 'feedback/feedback_contact.html'
    # sucess_template = 'thanks.html'

    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = FeedbackForm(request.POST)

        # check whether it's valid:
        if form.is_valid():
            receiver_email = settings.EMAIL_HOST_USER
            subject = form.subject(User.role)
            message = form.cleaned_data['message']

            # handle email eceptions
            try:
                send_mail(subject, message, request.user.email, [receiver_email])
            except Exception as ex:
                data = messages.add_message(request, messages.ERROR,'An error occurred. {}'.format(str(ex)))
            else:
                feedback_form = form.save(commit=False)
                # feedback_form.receiver_email = receiver_email
                feedback_form.user = User
                feedback_form.save()
                data = messages.add_message(request, messages.INFO, 'Thanks for sending a feedback.')

            # render thank you message
            return  render(request, contact_template, {'message': data})

    # if a GET (or any other method) we'll create a blank form
    else:
        form = FeedbackForm(user=User.user)

    return render(request, contact_template, {'form': form})
Esempio n. 52
0
def feedback(request):
    """
    Страница с формой обратной связи
    """
    initial = {}
    if request.user.is_authenticated() and request.user.profile:
        initial = {
            'name': request.user.profile.name,
            'phone': request.user.profile.get_phone(),
            'email': request.user.email
        }

    feedback_form = FeedbackForm(request.POST or None, initial=initial)
    feedback_form_sending = False

    if request.method == 'POST' and request.POST.get('action') == FeedbackForm.action_text and feedback_form.is_valid():
        feedback_form.save()
        feedback_form = FeedbackForm()
        feedback_form_sending = True

    return {
        'feedback_form': feedback_form,
        'feedback_form_sending': feedback_form_sending,
    }
Esempio n. 53
0
    def test_form(self):
        form_file_data = dict()
        form_data = dict(description='Test description', )

        form = FeedbackForm(form_data, form_file_data)
        self.assertTrue(form.is_valid())
Esempio n. 54
0
def main(request):
    if request.user.is_authenticated():
        profile = request.user.get_profile()
        acc = Accounts.objects.filter(profile__id=profile.id).exclude(
            email=None)
        emails = [i.email for i in acc]
        emails = set(emails)
        current_site = DjangoSite.objects.get_current()
        feedback_msg = request.session.get('feedback_msg', '')

        request.session['feedback_msg'] = ''
        if request.POST:
            referer = request.session.get('ref')
            request.session['ref'] = ''
            form = FeedbackForm(request.POST)
            if form.is_valid():
                email = request.POST.get('emails')
                if not email:
                    email = form.cleaned_data['email']
                    create_account(profile, email, None, email=email)

                msg = form.cleaned_data['msg']
                msg = u'%s\n(Пользователь %s [Отправлено со страницы %s])' % (
                    msg, email, referer)
                # [email protected]
                # [email protected]
                if current_site.domain == 'kinoinfo.ru':
                    send_mail('Обратная связь kinoinfo.ru', msg, '',
                              ['*****@*****.**'])
                elif current_site.domain == 'kinoafisha.in.ua':
                    send_mail('Обратная связь kinoafisha.in.ua', msg, '',
                              ['*****@*****.**'])
                elif current_site.domain == 'umru.net':
                    send_mail('Обратная связь umru.net', msg, '',
                              ['*****@*****.**'])
                request.session['feedback_msg'] = u'Спасибо за сообщение!'

                return HttpResponseRedirect(reverse("feedback_main"))
        else:
            try:
                request.session['ref'] = request.META['HTTP_REFERER']
            except KeyError:
                pass
            form = FeedbackForm()

        if current_site.domain == 'kinoinfo.ru':
            template = 'feedback/feedback.html'
        elif current_site.domain == 'umru.net':
            template = 'feedback/umrunet_feedback.html'
        elif current_site.domain == 'kinoafisha.in.ua':
            template = 'feedback/kua_feedback.html'
        return render_to_response(template, {
            'form': form,
            'feedback_msg': feedback_msg,
            'feedback': 'feedback',
            'emails': emails
        },
                                  context_instance=RequestContext(request))

    else:
        return HttpResponseRedirect(reverse("main"))