def post_feedback(id): project = Project.query.get_or_404(id) form = FeedbackForm() if form.validate(): issue = Document(form.summary.data, form.description.data) feedback = Feedback() feedback.project = project feedback.id = Feedback.get_id_from_doc(issue, project=project) existing_feedback = Feedback.query.get(feedback.id) if existing_feedback: feedback = existing_feedback if form.selected_recommendation.data: feedback.selected_recommendation = \ form.selected_recommendation.data if form.confirmed_recommendation.data: feedback.confirmed_recommendation = \ form.confirmed_recommendation.data db.session.add(feedback) db.session.commit() return jsonify(result="success") return jsonify(result="error", errors=form.errors), 400
def feedback(self): """Provide a feedback for a status. Overrides the older feedback if there was any. """ req = json.loads(self.request.body) try: qid = int(req.get('qid', '')) sid = int(req.get('sid', '')) score = int(req.get('score', '')) if score < -1 or score > 1: self.abort(400, detail='Invalid score.') uid = self.user_session['user_id'] q = Query.get_by_id(qid) if q is None: raise ValueError() f = Feedback.gql('WHERE uid = :1 AND qid = :2 AND sid = :3', uid, qid, sid).get() if f is None: f = Feedback(uid=uid, qid=qid, sid=sid) f.score = score f.put() self.write({'message': 'success'}) except ValueError: self.abort(400, detail='Please specify valid query ID and status ID.')
def post(self, request): form = self.form if form.is_valid(): feedback = Feedback(message=form.cleaned_data["message"][:2000]) feedback.save() return render_to_response("feedback_thanks.html", locals(), context_instance=RequestContext(request)) else: return HttpResponseBadRequest("Invalid form")
def feedback(request): _user = request.user notes = request.POST.get("notes", None) if not notes: return Jsonify({"status":False, "error":1101, "error_message":"信息不足, 请重新输入。"}) fdback = Feedback(notes=notes, user_id=_user['uid'], state=0) fdback.save() return Jsonify({"status":True, "feedback":model_to_dict(fdback), "error":"", "error_message":""})
def submit(request, page, message): """ Save a new feedback message in the database. """ submitter = request.user if submitter.is_anonymous(): submitter = None feedback = Feedback(page=page, message=message, submitter=submitter, ip=request.META.get('REMOTE_ADDR', '0.0.0.0')) feedback.put() return HttpResponseRedirect(page)
def feedback(): feed = request.form['feedback'] user = request.form['user'] field = request.form['field'] senti = sentiment(feed) u = Feedback(user=user, feed=feed, field=field, rating=senti) u.save() return json.dumps([{'status': 'done'}])
def feedback(request, result_id): try: rate_text = request.POST['rate-text'] rate_score = request.POST['score'] result = Result.objects.get(pk=result_id) feedback = Feedback(rating=rate_score, text=rate_text, result=result) feedback.save() # TODO arikg: handle smaller exception except Exception: return redirect('/result/%s/' % result_id, { 'error_message': "Please fill in the rating and text", }) return redirect('/thanks')
def post(self, request): form = self.form if form.is_valid(): base_template = BASE_TEMPLATE feedback = Feedback( message=form.cleaned_data['message'][:2000], url=form.cleaned_data['referrer']) feedback.save() return render_to_response( "feedback_thanks.html", locals(), context_instance=RequestContext(request)) else: return HttpResponseBadRequest("Invalid form")
def contact(request): if request.method == 'POST': c={} form = ContactForm(request.POST) if form.is_valid(): feedback = Feedback() try: feedback.name = form.cleaned_data["con_name"] feedback.email = form.cleaned_data["con_emailid"] try: feedback.mobile = str(form.cleaned_data["con_mobile"]) except: feedback.mobile = "" #if feedback.mobile is None: # feedback.mobile = 0 feedback.value = form.cleaned_data["con_text"] feedback.save() c.update({"success":True}) except: print sys.exc_info()[1] return HttpResponse('Error in sending feedback'+str(vars(feedback))+str(sys.exc_info()[0])) c.update(csrf(request)) return render_to_response('contact.html',c) else: c={} c.update({"form":form}) c.update(csrf(request)) return render_to_response('contact.html',c) c={} c.update(csrf(request)) return render_to_response('contact.html',c)
def submit(request, page, message): """ Save a new feedback message in the database. """ # submitter = request.user # if submitter.is_anonymous(): submitter = None feedback = Feedback(page=page, message=message, submitter=submitter, ip=request.META.get('REMOTE_ADDR', '0.0.0.0')) feedback.put() if page == '/': page = '/feedback/' page += '?feedback=%d' % feedback.key().id() return HttpResponseRedirect(page)
def post(self, id): user = users.get_current_user() event = Event.get_by_id(int(id)) try: if self.request.get('rating'): feedback = Feedback( event = event, rating = int(self.request.get('rating')), comment = cgi.escape(self.request.get('comment'))) feedback.put() self.redirect('/event/%s-%s' % (event.key().id(), slugify(event.name))) else: raise ValueError('Please select a rating') except Exception: set_cookie(self.response.headers, 'formvalues', dict(self.request.POST)) self.redirect('/feedback/new/' + id)
def vote(request, id): """ Add a vote for a feedback message, but not twice from the same IP. """ referer = request.META.get('HTTP_REFERER', '/feedback/') redirect = HttpResponseRedirect(referer) # Check if the selected feedback exists. feedback = Feedback.get_by_id(int(id)) if feedback is None: logging.debug("Feedback '%s' not found." % id) return redirect # Check if this feedback was posted from the same IP. ip = request.META.get('REMOTE_ADDR', '0.0.0.0') if feedback.ip == ip: logging.debug("Feedback '%s' was posted from the same IP." % id) return redirect # Check if this IP has already voted for this feedback. already = Vote.all().filter('feedback', feedback).filter('ip', ip).count() if already: logging.debug("Feedback '%s' was already voted %d times from this IP." % (id, already)) return redirect # Register this vote to prevent double voting. vote = Vote(feedback=feedback, ip=ip) vote.put() # Increase the points for this feedback. feedback.points += 1 feedback.put() return redirect
def post(self, id): user = users.get_current_user() event = Event.get_by_id(int(id)) try: if self.request.get("rating"): feedback = Feedback( event=event, rating=int(self.request.get("rating")), comment=cgi.escape(self.request.get("comment")) ) feedback.put() log = HDLog(event=event, description="Posted feedback") log.put() self.redirect("/event/%s-%s" % (event.key().id(), slugify(event.name))) else: raise ValueError("Please select a rating") except Exception: set_cookie(self.response.headers, "formvalues", dict(self.request.POST)) self.redirect("/feedback/new/" + id)
def post(self): from recaptcha.client import captcha captcha_challenge_field = self.get_argument('recaptcha_challenge_field') captcha_response_field = self.get_argument('recaptcha_response_field') captcha_response = captcha.submit( captcha_challenge_field, captcha_response_field, configuration.RECAPTCHA_PRIVATE_KEY, self.request.remote_ip ) if captcha_response.is_valid: full_name = self.get_argument('name') email = self.get_argument('email') subject = self.get_argument('subject') content = self.get_argument('content') feedback = Feedback() feedback.full_name = full_name feedback.email = email feedback.subject = subject feedback.content = content feedback.put() self.redirect('/') else: error = captcha_response.error_code self.redirect('/contact/feedback?captcha_error=%s' % error)
def feedback(request): if request.method == 'POST': form = FeedbackForm(request.POST) if form.is_valid(): data = Feedback(name=form.cleaned_data['name'], email=form.cleaned_data['email'], comment=form.cleaned_data['comment']) data.save() message = "Thanks for the feedback" context = {'form':FeedbackForm(), 'message':message, 'count':request.session.get('count',0)} return render(request, 'feedback/feedback.html', context) else: # If data is not valid, reload page with error message = "Oops! Something went wrong!" context = {'form':FeedbackForm(), 'message':message, 'count':request.session.get('count',0)} return render(request, 'feedback/feedback.html', context) else: context = {'form':FeedbackForm(), 'count':request.session.get('count',0)} return render(request, 'feedback/feedback.html', context)
def get_already_voted(request): """ Don't show vote buttons if posted or voted from the same IP. """ ip = request.META.get('REMOTE_ADDR', '0.0.0.0') posted = [feedback.id() for feedback in Feedback.all(keys_only=True).filter('ip', ip)] voted = [vote.feedback_id() for vote in Vote.all().filter('ip', ip)] # logging.debug('posted=%s voted=%s' % (posted, voted)) return set(posted + voted)
def add(request): """Gather feedback for a page, and if it is ok show a thanks message and link back to the page.""" submit_was_success = False return_to_url = None # If it is a post request try to create the feedback if request.method == 'POST': form = FeedbackForm( request.POST ) if form.is_valid(): feedback = Feedback() feedback.url = form.cleaned_data['url'] feedback.email = form.cleaned_data['email'] feedback.comment = form.cleaned_data['comment'] # if there is any content in the honeypot field then label this comment as spammy if form.cleaned_data['website']: feedback.status = 'spammy' # if the comment starts with an html tag it is probably spam if re.search('\A\s*<\w+>', form.cleaned_data['comment']): feedback.status = 'spammy' if request.user.is_authenticated(): feedback.user = request.user feedback.save() submit_was_success = True return_to_url = feedback.url or None else: # use GET to grab the url if set form = FeedbackForm(initial=request.GET) return render_to_response( 'feedback/add.html', { 'form': form, 'submit_was_success': submit_was_success, 'return_to_url': return_to_url, }, context_instance=RequestContext(request) )
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)
def add_feedback(username): """Render add feedback form on GET request and handle submit feedback form on POST request""" if 'username' not in session or username != session['username']: flash('you do not have permission to do that', 'warning') return redirect('/') form = AddFeedback() if form.validate_on_submit(): title = form.title.data content = form.content.data new_fb = Feedback(title=title, content=content, username=username) db.session.add(new_fb) db.session.commit() flash('feedback submitted', 'info') return redirect(f'/users/{username}') return render_template('feedback.html', form=form)
def add_feedback(username): """add feedback to a user""" if "username" not in session or username != session["username"]: raise Unauthorized() form = FeedbackForm() if form.validate_on_submit(): title = form.title.data content = form.content.data feedback = Feedback(title=title, content=content, username=username) db.session.add(feedback) db.session.commit() return redirect(f'/users/{feedback.username}') else: return render_template('feedback/new.html', form=form)
def post(self): full_name = self.get_argument('full_name') email = self.get_argument('email') phone_number = self.get_argument('phone_number') subject = self.get_argument('subject') comment = self.get_argument('comment') from models import Feedback feedback = Feedback() feedback.full_name = full_name feedback.email = email feedback.phone_number = phone_number feedback.subject = subject feedback.comment = comment feedback.put() self.redirect("/")
def add_feedback(username): if 'username' not in session: flash("Please login first!", "danger") return redirect('/') form = FeedbackForm() if form.validate_on_submit(): title = form.title.data content = form.content.data fb = Feedback(title=title, content=content, username=session["username"]) db.session.add(fb) db.session.commit() flash('Feedback Added!', "success") return redirect(f'/users/{username}') return render_template('add_feedback.html', form=form)
def add_feedback(username): if 'user_id' not in session: flash('Please login first') return redirect('/login') user = User.query.get(username) form = FeedbackForm() if form.validate_on_submit(): title = form.title.data content = form.content.data username = user.username fb = Feedback(title=title, content=content, username=username) db.session.add(fb) db.session.commit() flash(f'New post: {title} by {username}') return redirect(f'/users/{username}') return render_template('add-feedback.html', form=form)
def add_feedback(username): if session.get('username') == username: form = FeedbackForm() if form.validate_on_submit(): title = form.title.data content = form.content.data feedback = Feedback(title=title, content=content, username=username) db.session.add(feedback) db.session.commit() return redirect(f'/users/{username}') else: return render_template('feedback/new.html', form=form) else: return redirect('/')
def add_feedback(username): if is_authorized(username): form = AddFeedback() if form.validate_on_submit(): new_feedback = Feedback( title=form.title.data, content=form.content.data, username=username) db.session.add(new_feedback) db.session.commit() return redirect(f'/users/{username}') else: return render_template('add_feedback_form.html', form=form, username=username) else: flash("You must be logged in to view!") return redirect('/login')
def add_feedback(username): if 'username' not in session: flash("Please login first", "danger") return redirect('/') form = FeedbackForm() if form.validate_on_submit(): title = form.title.data content = form.content.data new_feedback = Feedback(title=title, content=content, username=session['username']) db.session.add(new_feedback) db.session.commit() flash('Feedback added', "success") return redirect(f"/user/{username}") return render_template("add_feedback.html", form=form)
def create_feedback(user_id): content = request.json feedback = Feedback() feedback.userID = str(content['userID']) feedback.date = str(content['date']) feedback.startTime = str(content['startTime']) feedback.feedback = str(content['feedback']) BaseObject.check_and_save(feedback) result = dict({"success": "yes"}) return jsonify(result)
def feedback_posts(username): form = FeedbackForm() if form.validate_on_submit(): title = form.title.data content = form.content.data new_feedback = Feedback(title = title, content = content, username = username) db.session.add(new_feedback) db.session.commit() return redirect(f'/users/{username}') else: if 'username' not in session: return redirect('/login') return render_template('feedback.html', form = form)
def new_feedback(username): if "username" not in session or username != session['username']: flash("Sorry, you are not allowed to perform this action!", 'danger') form = FeedbackForm() if form.validate_on_submit(): title = form.title.data content = form.content.data feedback = Feedback(title=title, content=content, username=username) db.session.add(feedback) db.session.commit() flash(f"Your feedback {feedback.title} has been successfully added!", 'success') return redirect(f"/users/{feedback.username}") else: return render_template('new_feedback.html', form=form)
def user_add_feedback(username): if "username" not in session: flash("Please login first!", "danger") return redirect('/login') form = FeedbackForm() if form.validate_on_submit(): title = form.title.data content = form.content.data new_feedback = Feedback(title=title, content=content, username=username) db.session.add(new_feedback) db.session.commit() return redirect(f'/users/{username}') else: return render_template('add_feedback.html', form=form)
def index(): title = 'Home' form = FeedbackForm() pnt = Paintings.query.with_entities(Paintings.name, Paintings.painting_photo).filter_by(artist_id=1) scp = Paintings.query.with_entities(Paintings.name, Paintings.painting_photo).filter_by(artist_id=2) paintings = dict(pnt.all()) sculptures = dict(scp.all()) if request.method == 'POST': if form.validate() == False: return render_template('index.html',title = title, paintings = paintings, sculptures = sculptures, form = form) else: feedback = Feedback(form.name.data, form.email.data, form.subject.data, form.comment.data) db.session.add(feedback) db.session.commit() flash("Form submitted successfully!", "success") return redirect(url_for('index')) return render_template('index.html',title = title, paintings = paintings, sculptures = sculptures, form = form)
def add_feedback(username): feedback_form = Add_Feedback() user = User.query.filter_by(username=username).first() if feedback_form.validate_on_submit() and session['user_id'] == user.id: title = feedback_form.title.data content = feedback_form.content.data user_id = user.id new_feedback = Feedback(title=title, content=content, user_id=user_id) db.session.add(new_feedback) db.session.commit() return redirect(f'/users/{username}') elif session['user_id'] == user.id: return render_template("add_feedback.html", feedback_form=feedback_form) else: return "You cannot add feedback for this account"
def show_secret(): if "user_id" not in session: flash("Please login first!") return redirect('/') form = FeedbackForm() all_feedback = Feedback.query.all() if form.validate_on_submit(): title = form.title.data content = form.content.data new_feedback = Feedback(title=title, content=content, username=session['user_id']) db.session.add(new_feedback) db.session.commit() flash('Feedback Accepted!') return redirect('/secret') return render_template('secret.html', form=form, feedback=all_feedback)
def form_feedback(username): user = User.query.filter_by(username=username).first() if user: form = FeedbackForm() if form.validate_on_submit(): feedback = Feedback(title=form.title.data, content=form.content.data, username=user.username) db.session.add(feedback) db.session.commit() return redirect(f"/users/{username}") return render_template("feedback.html", user=user, form=form) else: flash("Thou must be logged in to do that.") return redirect("/"), 401
def add_feedback(username): """Render and handle form to add feedback""" user = User.query.get(username) if 'username' not in session or username != session['username']: raise Unauthorized() else: form = FeedbackForm() if form.validate_on_submit(): title = form.title.data content = form.content.data username = user.username feedback = Feedback(title=title, content=content, username=username) db.session.add(feedback) db.session.commit() return redirect(f"/users/{username}") return render_template("feedback/new.html", form=form, user=user)
def add_feedback(username): form = FeedbackForm() if "username" not in session: flash('You are not authorized to do this', 'danger') return redirect(f'/users/{username}') if form.validate_on_submit(): title = form.title.data content = form.content.data feedback = Feedback(title=title, content=content, username=username) db.session.add(feedback) db.session.commit() return redirect(f'/users/{username}') else: return render_template('feedback_form.html', form=form)
def add_feedback(username): """Adding a feedback""" user = User.query.get_or_404(username) form = FeedbackForm() if form.validate_on_submit(): feedback = Feedback(username=username, title=form.title.data, content=form.content.data) db.session.add(feedback) db.session.commit() return redirect(url_for("show_user", username=username)) return render_template('feedback.html', user=user, form=form)
def add_feedback(user_id): username = user_id if 'user_id' not in session: return redirect('/login') else: form = FeedbackForm() if form.validate_on_submit(): title = request.form["title"] content = request.form["content"] new_feedback = Feedback(title=title, content=content, username=username) print(new_feedback.content) db.session.add(new_feedback) db.session.commit() return redirect(f'/users/{username}') else: user = User.query.get_or_404(user_id) return render_template('add_post.html', user=user, form=form)
def feedback_form(username): form = FeedbackForm() if form.validate_on_submit(): title = request.form.get('title') content = request.form.get('content') feedback = Feedback(title=title, content=content, username=username) db.session.add(feedback) db.session.commit() flash('Feedback posted!') return redirect(f'/users/{username}') elif session.get('user') == username: return render_template('feedback_form.html', form=form) else: return redirect('/register')
def add_feedback(username): if "username" not in session or session['username'] != username: return redirect('/login') form = FeedbackForm() if form.validate_on_submit(): title = form.title.data content = form.content.data try: feedback = Feedback(title=title, content=content, username=username) db.session.add(feedback) db.session.commit() return redirect(f'/users/{username}') except: return render_template('add_feedback.html', form=form) return render_template('add_feedback.html', form=form)
def new_feedback(username): """User to add feedback""" if "username" in session: form = FeedbackForm() if form.validate_on_submit(): title = form.title.data content = form.content.data feed = Feedback(title=title, content=content, username=username) db.session.add(feed) db.session.commit() return redirect(f"/users/{feed.username}") else: return render_template("feedback.html", form=form)
def add(): if "username" not in session: flash("Please login first") return redirect('/') form = FeedbackForm() if form.validate_on_submit(): title = form.title.data content = form.content.data newFeed = Feedback(title=title, content=content, username=session['username']) db.session.add(newFeed) db.session.commit() flash("Feedback posted", "success") return redirect('/feeds') return render_template("add_feeds.html", form=form)
def feedback(): if 'email' not in session: return redirect(url_for('login')) form = FeedbackForm() if request.method == 'POST': if form.validate() == False: return render_template("feedback.html", form=form) else: newfeedback = Feedback(form.first_name.data, form.email.data, form.comments.data) db.session.add(newfeedback) db.session.commit() return redirect(url_for('home')) elif request.method == 'GET': return render_template("feedback.html", form=form)
def delete(request, id): """ Delete a feedback message if the current user is staff, or it was posted from the same IP. """ referer = request.META.get('HTTP_REFERER', '/feedback/') redirect = HttpResponseRedirect(referer) feedback = Feedback.get_by_id(int(id)) if feedback is None: logging.debug("Feedback '%s' not found." % id) return redirect if feedback.ip == request.META.get('REMOTE_ADDR', '0.0.0.0'): logging.debug("Feedback '%s' deleted by same IP." % id) feedback.delete() elif request.user.is_staff: logging.debug("Feedback '%s' deleted by staff member." % id) feedback.delete() return redirect
def post_feedback_form_route(username): """Feedback form POST route""" form = FeedbackForm() if form.validate_on_submit(): title = form.title.data content = form.content.data if 'username' in session: user_feedback = Feedback(title=title, content=content, username=username) db.session.add(user_feedback) db.session.commit() return redirect(f'/users/{username}') return redirect('/login')
def new_feedback(username): """Show and handle form for adding feedback""" if "username" not in session or username != session['username']: raise Unauthorized() form = FeedbackForm() if form.validate_on_submit(): title = form.title.data content = form.content.data feedback = Feedback(title=title, content=content, username=username) db.session.add(feedback) db.session.commit() return redirect(f"/users/{feedback.username}") else: return render_template("add_feedback.html", form=form)
def add_feedback(username): if "username" not in session or username != session['username']: raise Unauthorized() form = FeedbackForm() if form.validate_on_submit(): title = form.title.data content = form.content.data feedback = Feedback(title=title, content=content, username=username) db.session.add(feedback) db.session.commit() return redirect(f"/users/{feedback.username}") return render_template('add_feedback.html', form=form)
def add_new_feedback(username): if 'user_id' not in session: flash('You have to login/register first', 'warning') return redirect('/login') form = NewFeedbackForm() user = User.query.filter_by(username=username).first() if form.validate_on_submit(): title = form.title.data feedback = form.feedback.data new_feedback = Feedback(title=title, content=feedback, username=username) db.session.add(new_feedback) db.session.commit() return redirect(f'/users/{user.username}') return render_template('create_feedback.html', form=form)
def add_feedback(username): form = FeedbackForm() if 'username' not in session: flash("You must be logged in to add feedback", "danger") return redirect("/login") if form.validate_on_submit(): title = form.title.data content = form.content.data feedback = Feedback(title=title, content=content, username=username) db.session.add(feedback) db.session.commit() flash("Added feedback!", "success") return redirect(f"/users/{username}") else: return render_template("feedback.html", form=form, url=f'/users/{username}/feedback/add', verb="Add")
def add_feedback(username): if "user_id" not in session: flash("Sorry, Please Login First") return redirect('/login') user = User.query.get_or_404(username) form = FeedbackForm() if user.username == session['user_id']: if form.validate_on_submit(): title = form.title.data content = form.content.data new_feedback = Feedback(title=title, content=content, user=user) db.session.add(new_feedback) db.session.commit() return redirect(f'/users/{user.username}') return render_template('feedback_form.j2', form=form, user=user) else: flash("You don't have access to that") return redirect('/')
def feedback(req): if req.method == 'GET': p = {'excellian': req.user.get_profile(), 'is_feedback': True, 'feedback': Feedback.objects.all().order_by('-message_date')} p.update(csrf(req)) return render_to_response(TEMPLATE_PATH + "feedback.html", p, context_instance=RequestContext(req)) elif req.method == 'POST': feedback = Feedback() feedback.excellian = req.user.get_profile() feedback.message = req.POST.get('message', '').strip() feedback.slug = _slugit(Feedback, feedback.message) if feedback.message == '': return _jsonResponse('Please enter a feedback message.') feedback.save() messages.add_message(req, messages.INFO, 'Feedback received. Thanks!') return _jsonResponse({'redirect': '/feedback/'})
def post_feedback(request, subject, text): logger.debug("Ajax request received for feedback.") success = False if request.user.is_authenticated(): user = request.user logger.info("Submitting feedback for "+str(user)) fb = Feedback() fb.user = user fb.subject = subject fb.text = text fb.save() success = True return simplejson.dumps({'success':success})
def view_project(id): project = Project.query.get_or_404(id) form = IssueForm() feedback_form = FeedbackForm() predictions = [] model_path = os.path.join(app.config['MODEL_FOLDER'], '%s/svm.pkl' % id) trained = project.train_status != TS.NOT_TRAINED \ and os.path.isfile(model_path) summary_or_description = form.summary.data or form.description.data if trained and form.validate_on_submit() and summary_or_description: issue = Document(form.summary.data, form.description.data) model = joblib.load(model_path) try: predictions = model.predict(issue, n=10) except ValueError: flash("There is too little information provided. " "You need to add more text to the description or summary.", "error") feedback_form.summary.data = form.summary.data feedback_form.description.data = form.description.data existing_feedback = Feedback.query.get( Feedback.get_id_from_doc(issue, project=project)) if existing_feedback: feedback_form.confirmed_recommendation.data = \ existing_feedback.confirmed_recommendation if request.method == "POST" and not summary_or_description: err_msg = "Summary or description must not be empty." form.summary.errors.append(err_msg) form.description.errors.append(err_msg) fscore = tests.fscore(project.precision, project.recall) return render_template("project/view.html", project=project, fscore=fscore, form=form, predictions=predictions, trained=trained, feedback_form=feedback_form)
def index(request): """ Handle post requests or list recent feedback messages. """ # Check if this is a post request with new feedback. feedback_form = FeedbackForm(request.POST or None) if feedback_form.is_valid(): return submit(request, page=feedback_form.cleaned_data['page'], message=feedback_form.cleaned_data['message']) # Check if this is a post request to vote on a message. vote_form = VoteForm(request.POST or None) if vote_form.is_valid(): return vote(request, vote_form.cleaned_data['vote']) # Check if this is a post request to delete a message. delete_form = DeleteForm(request.POST or None) if delete_form.is_valid(): return delete(request, delete_form.cleaned_data['delete']) # Otherwise, display recent feedback. feedback_list = Feedback.all() feedback_list.order('-points').order('-submitted') already_voted = get_already_voted(request) return render_to_response(request, 'feedback/index.html', locals())
def render_feedback(request): # get system status systemStatus = SystemStatus() systemStatus.get() c = RequestContext(request, {"version": systemStatus.version, "is_message": False, "feedback": True}) c.update(csrf(request)) # save bug/feature in session if "Save" clicked if request.method == "POST": if "add" in request.POST: issue = Feedback() issue.type = request.POST["type"] issue.description = request.POST["description"] issue.status = "pending" issue.save() c.update({"is_message": True}) # get all bugs and features bug_list = Feedback.objects.filter(type = "bug").order_by("-status") feature_list = Feedback.objects.filter(type = "feature").order_by("-status") c.update({"bug_list": bug_list, "feature_list": feature_list}) return render_to_response("feedback.html", c)
def add(request): """Gather feedback for a page, and if it is ok show a thanks message and link back to the page.""" submit_was_success = False return_to_url = None # If it is a post request try to create the feedback if request.method == 'POST': form = FeedbackForm( request.POST ) if form.is_valid(): feedback = Feedback() feedback.url = form.cleaned_data['url'] feedback.comment = form.cleaned_data['comment'] if request.user.is_authenticated(): feedback.user = request.user feedback.save() submit_was_success = True return_to_url = feedback.url or None else: # use GET to grab the url if set form = FeedbackForm(initial=request.GET) return render_to_response( 'feedback/add.html', { 'form': form, 'submit_was_success': submit_was_success, 'return_to_url': return_to_url, }, context_instance=RequestContext(request) )
def scores(self): """Retrieves previously provided feedback for a query.""" qid = int(self.request.get('qid')) uid = self.user_session['user_id'] fs = Feedback.gql('WHERE uid = :1 AND qid = :2', uid, qid).fetch() self.write({'items': [f.to_dict() for f in fs]})
def response_msg(request): raw_str = smart_str(request.raw_post_data) print raw_str msg = parse_xml(ET.fromstring(raw_str)) msg_type = msg.get('MsgType', '') from_user_name = msg.get('FromUserName') to_user_name = msg.get('ToUserName') content = '' print('MsgType ' + msg_type) if msg_type == 'event': event_type = msg.get('Event', '') print('new event: ' + event_type) if event_type == 'subscribe': content = '欢迎关注要记账\n1.创建账本\n2.增加记录\n3.查询\n4.导出账单\n5.帮助\n6.删除账号并清空数据\n7.反馈' return get_reply_xml(from_user_name, to_user_name, content) elif msg_type == 'text': content = msg.get('Content', '') print('content: ' + content) if mc.get(from_user_name + 'del') == '22': if content == 'c' or content == 'C': record_stamp = mc.get(from_user_name + 'ds') u1 = User.objects.get(user=from_user_name) pb = PayBooks.objects.filter(user=u1, stamp=record_stamp) pb[0].delete() content = '撤销成功' return get_reply_xml(from_user_name, to_user_name, content) # if op_sql.revoke_insert(from_user_name): # content = '撤销成功' # else: # content = '撤销失败' # mc.delete(from_user_name + 'del') # return reply_server(from_user_name, to_user_name, content) if mc.get(from_user_name) == '1': print(mc.get(from_user_name) + ' name') u1 = User.objects.filter(user=from_user_name) if len(u1) == 0: print('create user but not exist') u1 = User(user=from_user_name, pwd=content) u1.save() content = '创建成功,此密码可以用来提取账单,如果你不幸忘记密码,请在反馈中联系[要记账]' mc.delete(from_user_name) else: print('create user failed exist') content = '创建失败,用户已经创建过密码' mc.delete(from_user_name) return get_reply_xml(from_user_name, to_user_name, content) # if op_sql.create(from_user_name, content): # content = '创建成功,此密码未来可以提取账单到电脑' # logging.debug(content + ' enter if op_sql') # mc.delete(from_user_name) # else: # content = '创建失败,用户已经创建过密码' # mc.delete(from_user_name) elif mc.get(from_user_name) == '2': print(mc.get(from_user_name) + ' enter 2 content' + content) #logging.debug('show content : ' + content) tmp = content.split(' ') if not is_number(tmp[0]): content = '输入有误\n!格式不正确\n!金额不能为负数\n!用空格分隔\n请重新输入' return get_reply_xml(from_user_name, to_user_name, content) if len(tmp) == 2 and float(tmp[0]) > 0: user_tmp = User.objects.filter(user=from_user_name) if len(user_tmp) != 0: record_time = time.strftime('%m%d%H%M%S') pb = PayBooks(user=user_tmp[0], money=tmp[0], month=time.strftime('%m'), year=time.strftime('%Y'), remark=tmp[1], stamp=record_time ) pb.save() content = '数据记录成功\n在3分钟内回复c\n可以撤销刚才数据' mc.delete(from_user_name) mc.set(from_user_name + 'ds', record_time, 300) # if user want to revoke the previous opration mc.set(from_user_name + 'del', '22', 180) else: print('insert error money format') content = '数据记录失败,格式不对吧?还是没创建账户?' mc.delete(from_user_name) # if op_sql.insert(from_user_name, tmp[0], tmp[1]): # logging.debug('insert enter') # content = '数据记录成功\n在3分钟内回复c\n可以撤销刚才数据' # mc.delete(from_user_name) # # if user want to revoke the previous opration # mc.set(from_user_name + 'del', '22', 180) # else: # logging.debug('insert error money') # content = '数据记录失败,格式不对吧?还是没创建账户?' # mc.delete(from_user_name) else: content = '输入有误\n!格式不正确\n!金额不能为负数\n!用空格分隔\n请重新输入' return get_reply_xml(from_user_name, to_user_name, content) elif mc.get(from_user_name) == '3': '''高级查询 1 单参数,当前年月份 12 2014 指定月份与年份,第二个数字大于3位数 1 2 区间查询两个数字都是2位数,当前年 2 5 2013 2014 4参数,指定区间月份年 ''' print('enter search') arg = content.split(" ") check = True u1 = User.objects.get(user=from_user_name) current_year = time.strftime('%Y') result = '' for c in arg: check = check and c.isdigit() if check: if len(arg) <= 2 and len(arg) != 0: if len(arg) == 2: if int(arg[1]) > 1000: current_year = arg[1] else: m1 = arg[0] m2 = arg[1] if int(arg[0]) > int(arg[1]): m1 = arg[1] m2 = arg[0] pb = PayBooks.objects.filter(user=u1, month__gte=m1, month__lte=m2, year=current_year) result = current_year + "年\n" + "月列表: \n月份\t\t总额\n" for i in range(int(m1), int(m2) + 1): result += str(i) + '\t\t' + "{}".format( pb.filter(month=i).aggregate(Sum('money')).values()[0]) + "\n" result += "总计: " + "{}".format(pb.aggregate(Sum('money')).values()[0]) content = "查询结果: \n" + result mc.delete(from_user_name) return get_reply_xml(from_user_name, to_user_name, content) pb = PayBooks.objects.filter(user=u1, month=int(arg[0]), year=current_year) result = current_year + "年\n" + arg[0] + "月列表: \n日期\t金额\t备注\n" sum_money = Decimal("0.00") for p in pb: day = p.stamp result += "{}".format(day[2]+day[3]) + "\t\t" + "{}".format(p.money) + "\t" \ + "{}".format(p.remark.encode('utf8')) + "\n" sum_money += p.money result += "总计: " + "{}".format(sum_money) content = "查询结果: \n" + result mc.delete(from_user_name) return get_reply_xml(from_user_name, to_user_name, content) elif len(arg) == 4: m1 = arg[0] m2 = arg[1] y1 = arg[2] y2 = arg[3] if int(arg[2]) > int(arg[3]): m1 = arg[1] m2 = arg[0] y1 = arg[3] y2 = arg[2] pb = PayBooks.objects.filter(user=u1, year__gte=y1, year__lte=y2) sum_total = Decimal('0.00') if y1 != y2: sum_start = pb.filter(month__gte=m1, year=y1).aggregate(Sum('money')).values()[0] sum_end = pb.filter(month__lte=m2, year=y2).aggregate(Sum('money')).values()[0] for i in range(int(y1) + 1, int(y2)): sum_temp = pb.filter(year=i).aggregate(Sum('money')).values()[0] if sum_temp is not None: sum_total += sum_temp if sum_start is not None: sum_total += sum_start if sum_end is not None: sum_total += sum_start else: sum_total = pb.aggregate(Sum('money')).values()[0] result = y1 + '年 ' + m1 + '月到 ' + y2 + '年 ' + m2 + '月\n' result += "总计: " + "{}".format(sum_total) content = "查询结果: \n" + result mc.delete(from_user_name) return get_reply_xml(from_user_name, to_user_name, content) else: content = '输入格式错误' else: content = '输入格式错误' return get_reply_xml(from_user_name, to_user_name, content) elif mc.get(from_user_name) == '4': content = '建设中' mc.delete(from_user_name) return get_reply_xml(from_user_name, to_user_name, content) # logging.debug('enter 4') # if content.isdigit(): # result = op_sql.search(from_user_name, content) # else: # content = '输入有误\n请重新输入' # return reply_server(from_user_name, to_user_name, content) # re = content + "月列表: \n金额\t\t备注" # result = op_sql.show_month_list(from_user_name, content) # re += result # mc.delete(from_user_name) # return reply_server(from_user_name, to_user_name, re) elif mc.get(from_user_name) == '6': print('enter delete 6') if content == 'Y' or content == 'y': u1 = User.objects.filter(user=from_user_name) u1.delete() content = '删除成功\n你为节省我的空间出了一份力,谢谢~' else: content = '操作无效' mc.delete(from_user_name) return get_reply_xml(from_user_name, to_user_name, content) elif mc.get(from_user_name) == '7': print('enter 7') u1 = User.objects.get(user=from_user_name) fb = Feedback(user=u1, feed_back=unicode(content, 'utf8'), feedBack_date=datetime.date.today()) fb.save() content = '谢谢您的反馈,我会及时跟进滴' mc.delete(from_user_name) return get_reply_xml(from_user_name, to_user_name, content) if content == '1': content = '请设置您的初始密码' mc.set(from_user_name, '1', 180) elif content == '2': content = '插入数据格式为 金额 备注 \n 例如: \n500 书籍\n请输入数据\n用一个空格隔开\n==' mc.set(from_user_name, '2', 180) elif content == '3': content = '输入月份\n#普通查询#\n直接输入月份\n示例: 1\n#高级查询#\n' content += '①指定月份与年份(2014年12月):\n12 2014\n' \ '②当前年1月到2月份:\n1 2\n' \ '③2013年2月到2014年5月:\n2 5 2013 2014' mc.set(from_user_name, '3', 180) elif content == '4': content = '为了能正确的下载请用非微信自带浏览器打开\n如果你不幸忘记密码,请在反馈中联系[要记账]\n\n' \ '导出账单:<a href=\'http://yaojizhang.sinaapp.com/export-csv/' + from_user_name + '\'>导出</a>' # mc.set(from_user_name, '4', 180) elif content == '5': content = '①首先要创建账本,输入您设置的密码,该密码以后用来提取数据.\n②您可以输入消费信息啦\n' elif content == '6': content = '回复Y确认' mc.set(from_user_name, '6', 180) elif content == '7': content = '把您的建议和意见以及疑问都写下来吧~' mc.set(from_user_name, '7', 180) else: content = '[要记账]猜你要这个吧\n\n1.创建账本\n2.增加记录\n3.查询\n4.导出账单\n5.帮助\n6.删除账号并清空数据\n7.反馈' return get_reply_xml(msg.get('FromUserName'), msg.get('ToUserName'), content)
def get(self): feedbacks = Feedback.get() self.finish()
def post(self): grade = self.get_argument("grade", "") suggest = utf8(self.get_argument("suggest", "")) result = {"feedback_id": Feedback.add(self.current_user, grade, suggest)} self.finish(result)