def make_request(text, email = None, user_id = None, phone = None, alias = None, department = None, passed_recaptcha = False, offline_submission_type = None, date_received = None): """ Make the request. At minimum you need to communicate which record(s) you want, probably with some text.""" if (app.config['ENVIRONMENT'] == 'PRODUCTION') and (not passed_recaptcha) and is_spam(text): return None, False request_id = find_request(text) if request_id: # Same request already exists return request_id, False assigned_to_email = app.config['DEFAULT_OWNER_EMAIL'] assigned_to_reason = app.config['DEFAULT_OWNER_REASON'] if department: app.logger.info("\n\nDepartment chosen: %s" %department) prr_email = db_helpers.get_contact_by_dept(department) if prr_email: assigned_to_email = prr_email assigned_to_reason = "PRR Liaison for %s" %(department) else: app.logger.info("%s is not a valid department" %(department)) department = None request_id = create_request(text = text, user_id = user_id, department = department, offline_submission_type = offline_submission_type, date_received = date_received) # Actually create the Request object new_owner_id = assign_owner(request_id = request_id, reason = assigned_to_reason, email = assigned_to_email) # Assign someone to the request open_request(request_id) # Set the status of the incoming request to "Open" if email or alias or phone: subscriber_user_id = create_or_return_user(email = email, alias = alias, phone = phone) subscriber_id, is_new_subscriber = create_subscriber(request_id = request_id, user_id = subscriber_user_id) if subscriber_id: generate_prr_emails(request_id, notification_type = "Request made", user_id = subscriber_user_id) # Send them an e-mail notification return request_id, True
def new_request(passed_recaptcha = False, data = None): if data or request.method == 'POST': if not data and not passed_recaptcha: data = request.form.copy() email = data['request_email'] request_text = data['request_text'] if request_text == "": return render_template('error.html', message = "You cannot submit an empty request.") if email == "" and 'ignore_email' not in data and not passed_recaptcha: return render_template('missing_email.html', form = data, user_id = get_user_id()) if check_for_spam and is_spam(request_text) and not passed_recaptcha: return render_template('recaptcha.html', form = data, message = "Hmm, your request looks like spam. To submit your request, type the numbers or letters you see in the field below.", public_key = app.config['RECAPTCHA_PUBLIC_KEY']) alias = None phone = None if 'request_alias' in data: alias = data['request_alias'] if 'request_phone' in data: phone = data['request_phone'] request_id, is_new = make_request(text = request_text, email = email, user_id = get_user_id(), alias = alias, phone = phone, passed_recaptcha = passed_recaptcha, department = data['request_department']) if is_new: return redirect(url_for('show_request_for_x', request_id = request_id, audience = 'new')) if not request_id: return render_template('error.html', message = "Your request looks a lot like spam.") app.logger.info("\n\nDuplicate request entered: %s" % request_text) return render_template('error.html', message = "Your request is the same as /request/%s" % request_id) else: doc_types = os.path.exists(os.path.join(app.root_path, 'static/json/doctypes.json')) return render_template('new_request.html', doc_types = doc_types, user_id = get_user_id())
def update_a_resource(resource, passed_recaptcha=False, data=None): if (data or request.method == 'POST'): if not data: data = request.form.copy() if 'qa' in resource: if not passed_recaptcha and is_spam( comment=data['answer_text'], user_ip=request.remote_addr, user_agent=request.headers.get('User-Agent')): return render_template( 'recaptcha_answer.html', form=data, message= "Hmm, your answer looks like spam. To submit your answer, type the numbers or letters you see in the fiel dbelow." ) prr.answer_a_question(qa_id=int(data['qa_id']), answer=data['answer_text'], passed_spam_filter=True) else: update_resource(resource, data) if current_user.is_anonymous() == False: return redirect( url_for('show_request_for_city', request_id=request.form['request_id'])) else: return redirect( url_for('show_request', request_id=request.form['request_id'])) return render_template( 'error.html', message="You can only update requests from a request page!")
def make_request( text, email=None, assigned_to_name=None, assigned_to_email=None, assigned_to_reason=None, user_id=None, phone=None, alias=None, department=None, ): """ Make the request. At minimum you need to communicate which record(s) you want, probably with some text.""" if is_spam(text): return None, False request_id = find_request(text) if request_id: # Same request already exists return request_id, False request_id = create_request(text=text, user_id=user_id, department=department) # Actually create the Request object new_owner_id = assign_owner( request_id=request_id, reason=assigned_to_reason, email=assigned_to_email ) # Assign someone to the request open_request(request_id) # Set the status of the incoming request to "Open" if email or phone or alias: # If the user provided an e-mail address, add them as a subscriber to the request. subscriber_user_id = create_or_return_user(email=email, alias=alias, phone=phone) subscriber_id, is_new_subscriber = create_subscriber(request_id=request_id, user_id=subscriber_user_id) if subscriber_id: generate_prr_emails( request_id, notification_type="Request made", user_id=subscriber_user_id ) # Send them an e-mail notification return request_id, True
def public_add_a_resource(resource, passed_recaptcha=False, data=None): if (data or request.method == 'POST') and ('note' in resource or 'subscriber' in resource): if not data: data = request.form.copy() if 'note' in resource: if not passed_recaptcha and is_spam( comment=data['note_text'], user_ip=request.remote_addr, user_agent=request.headers.get('User-Agent')): return render_template( 'recaptcha_note.html', form=data, message= "Hmm, your note looks like spam. To submit your note, type the numbers or letters you see in the field below." ) resource_id = prr.add_note(request_id=data['request_id'], text=data['note_text'], passed_spam_filter=True) else: resource_id = prr.add_resource(resource=resource, request_body=data, current_user_id=None) if type(resource_id) == int: request_id = data['request_id'] audience = 'public' if 'subscriber' in resource: audience = 'follower' return redirect( url_for('show_request_for_x', audience=audience, request_id=request_id)) return render_template('error.html')
def new_request(): if request.method == 'POST': email = request.form['request_email'] request_text = request.form['request_text'] if is_spam(request_text): return render_template('error.html', message = "Your request looks a lot like spam. If you believe you're seeing this message in error, let us know through the feedback tab.") # <img src = 'http://31.media.tumblr.com/tumblr_lijp30si761qc9z7yo1_500.gif'>") if email == "" and 'ignore_email' not in request.form: return render_template('missing_email.html', form = request.form, user_id = get_user_id()) if request_text == "": return render_template('error.html', message = "You cannot submit an empty request.") alias = None phone = None if 'request_alias' in request.form: alias = request.form['request_alias'] if 'request_phone' in request.form: phone = request.form['request_phone'] assigned_to_email = app.config['DEFAULT_OWNER_EMAIL'] assigned_to_reason = app.config['DEFAULT_OWNER_REASON'] department = request.form['request_department'] if department: prr_email = departments.get_prr_liaison(department) if prr_email: assigned_to_email = prr_email assigned_to_reason = "PRR Liaison for %s" %(department) else: print "%s is not a valid department" %(department) request_id, is_new = make_request(text = request_text, email = email, assigned_to_email = assigned_to_email, assigned_to_reason = assigned_to_reason, user_id = get_user_id(), alias = alias, phone = phone) if is_new: return redirect(url_for('show_request_for_x', request_id = request_id, audience = 'new')) if not request_id: return render_template('error.html', message = "Your request looks a lot like spam.") return render_template('error.html', message = "Your request is the same as /request/%s" % request_id) else: return render_template('new_request.html', user_id = get_user_id())
def new_request(passed_recaptcha = False, data = None): if data or request.method == 'POST': if not data and not passed_recaptcha: data = request.form.copy() email = data['request_email'] request_text = data['request_text'] if request_text == "": return render_template('error.html', message = "You cannot submit an empty request.") if email == "" and 'ignore_email' not in data and not passed_recaptcha: return render_template('missing_email.html', form = data) if not passed_recaptcha and (is_spam(comment = request_text, user_ip = request.remote_addr, user_agent = request.headers.get('User-Agent'))): return render_template('recaptcha_request.html', form = data, message = "Hmm, your request looks like spam. To submit your request, type the numbers or letters you see in the field below.") alias = None phone = None offline_submission_type = None date_received = None department = None if 'request_department' in data: department = data['request_department'] if 'request_alias' in data: alias = data['request_alias'] if 'request_phone' in data: phone = data['request_phone'] if 'format_received' in data: offline_submission_type = data['format_received'] if 'date_received' in data: # From the jQuery datepicker date_received = data['date_received'] if date_received != "": try: date_received = datetime.strptime(date_received, '%m/%d/%Y') except ValueError: return render_template('error.html', message = "Please use the datepicker to select a date.") if date_received.date() > date.today(): return render_template('error.html', message = "Please choose a request receipt date that is no later than today.") tz = pytz.timezone(app.config['TIMEZONE']) offset = tz.utcoffset(datetime.now()) offset = (offset.days * 86400 + offset.seconds) / 3600 date_received = date_received - timedelta(hours = offset) # This is somewhat of a hack, but we need to get this back in UTC time but still treat it as a 'naive' datetime object request_id, is_new = make_request(text = request_text, email = email, alias = alias, phone = phone, passed_spam_filter = True, department = department, offline_submission_type = offline_submission_type, date_received = date_received) if is_new: return redirect(url_for('show_request_for_x', request_id = request_id, audience = 'new')) if not request_id: return render_template('error.html', message = "Your request looks a lot like spam.") app.logger.info("\n\nDuplicate request entered: %s" % request_text) return render_template('error.html', message = "Your request is the same as /request/%s" % request_id) else: departments = None routing_available = False if 'LIAISONS_URL' in app.config: routing_available = True departments = db.session.query(models.Department).all() if current_user.is_authenticated(): return render_template('offline_request.html', routing_available = routing_available, departments = departments) else: return render_template('new_request.html', routing_available = routing_available, departments = departments)
def new_request(passed_recaptcha=False, data=None): if data or request.method == 'POST': if not data and not passed_recaptcha: data = request.form.copy() email = data['request_email'] request_text = data['request_text'] if request_text == "": return render_template( 'error.html', message="You cannot submit an empty request.") if email == "" and 'ignore_email' not in data and not passed_recaptcha: return render_template('missing_email.html', form=data, user_id=get_user_id()) if (app.config['ENVIRONMENT'] == 'PRODUCTION' ) and is_spam(request_text) and not passed_recaptcha: return render_template( 'recaptcha.html', form=data, message= "Hmm, your request looks like spam. To submit your request, type the numbers or letters you see in the field below.", public_key=app.config['RECAPTCHA_PUBLIC_KEY']) alias = None phone = None if 'request_alias' in data: alias = data['request_alias'] if 'request_phone' in data: phone = data['request_phone'] request_id, is_new = make_request(text=request_text, email=email, user_id=get_user_id(), alias=alias, phone=phone, passed_recaptcha=passed_recaptcha) if is_new: return redirect( url_for('show_request_for_x', request_id=request_id, audience='new')) if not request_id: return render_template( 'error.html', message="Your request looks a lot like spam.") return render_template( 'error.html', message="Your request is the same as /request/%s" % request_id) else: doc_types = os.path.exists( os.path.join(app.root_path, 'static/json/doctypes.json')) return render_template('new_request.html', doc_types=doc_types, user_id=get_user_id())
def update_a_resource(resource, passed_recaptcha = False, data = None): if (data or request.method == 'POST'): if not data: data = request.form.copy() if 'qa' in resource: if not passed_recaptcha and is_spam(comment = data['answer_text'], user_ip = request.remote_addr, user_agent = request.headers.get('User-Agent')): return render_template('recaptcha_answer.html', form = data, message = "Hmm, your answer looks like spam. To submit your answer, type the numbers or letters you see in the fiel dbelow.") prr.answer_a_question(qa_id = int(data['qa_id']), answer = data['answer_text'], passed_spam_filter = True) else: update_resource(resource, data) if current_user.is_anonymous() == False: return redirect(url_for('show_request_for_city', request_id = request.form['request_id'])) else: return redirect(url_for('show_request', request_id = request.form['request_id'])) return render_template('error.html', message = "You can only update requests from a request page!")
def new_request(passed_recaptcha = False, data = None): user_id = get_user_id() if data or request.method == 'POST': if not data and not passed_recaptcha: data = request.form.copy() email = data['request_email'] request_text = data['request_text'] if request_text == "": return render_template('error.html', message = "You cannot submit an empty request.") if email == "" and 'ignore_email' not in data and not passed_recaptcha: return render_template('missing_email.html', form = data, user_id = get_user_id()) if check_for_spam and is_spam(request_text) and not passed_recaptcha: return render_template('recaptcha.html', form = data, message = "Hmm, your request looks like spam. To submit your request, type the numbers or letters you see in the field below.", public_key = app.config['RECAPTCHA_PUBLIC_KEY']) alias = None phone = None offline_submission_type = None date_received = None if 'request_alias' in data: alias = data['request_alias'] if 'request_phone' in data: phone = data['request_phone'] if 'format_received' in data: offline_submission_type = data['format_received'] if 'date_received' in data: # From the jQuery datepicker date_received = data['date_received'] if date_received != "": try: date_received = datetime.strptime(date_received, '%m/%d/%Y') date_received = date_received + timedelta(hours = 7) # This is somewhat of a hack, but we need to get this back in UTC (+7 hours offset from Pacific Time) time but still treat it as a 'naive' datetime object except ValueError: return render_template('error.html', message = "Please use the datepicker to select a date.") app.logger.info("\n\n Date received: %s" % date_received) request_id, is_new = make_request(text = request_text, email = email, user_id = user_id, alias = alias, phone = phone, passed_recaptcha = passed_recaptcha, department = data['request_department'], offline_submission_type = offline_submission_type, date_received = date_received) if is_new: return redirect(url_for('show_request_for_x', request_id = request_id, audience = 'new')) if not request_id: return render_template('error.html', message = "Your request looks a lot like spam.") app.logger.info("\n\nDuplicate request entered: %s" % request_text) return render_template('error.html', message = "Your request is the same as /request/%s" % request_id) else: routing_available = False if 'LIAISONS_URL' in app.config: routing_available = True if user_id: return render_template('offline_request.html', routing_available = routing_available, user_id = user_id) else: return render_template('new_request.html', routing_available = routing_available, user_id = user_id)
def make_request(text, email = None, assigned_to_name = None, assigned_to_email = None, assigned_to_reason = None, user_id = None, phone = None, alias = None, department = None, passed_recaptcha = False): """ Make the request. At minimum you need to communicate which record(s) you want, probably with some text.""" if (not passed_recaptcha) and is_spam(text): return None, False request_id = find_request(text) if request_id: # Same request already exists return request_id, False request_id = create_request(text = text, user_id = user_id, department = department) # Actually create the Request object new_owner_id = assign_owner(request_id = request_id, reason = assigned_to_reason, email = assigned_to_email) # Assign someone to the request open_request(request_id) # Set the status of the incoming request to "Open" if email or phone or alias: # If the user provided an e-mail address, add them as a subscriber to the request. subscriber_user_id = create_or_return_user(email = email, alias = alias, phone = phone) subscriber_id, is_new_subscriber = create_subscriber(request_id = request_id, user_id = subscriber_user_id) if subscriber_id: generate_prr_emails(request_id, notification_type = "Request made", user_id = subscriber_user_id) # Send them an e-mail notification return request_id, True
def public_add_a_resource(resource, passed_recaptcha = False, data = None): if (data or request.method == 'POST') and ('note' in resource or 'subscriber' in resource): if not data: data = request.form.copy() if 'note' in resource: if not passed_recaptcha and is_spam(comment = data['note_text'], user_ip = request.remote_addr, user_agent = request.headers.get('User-Agent')): return render_template('recaptcha_note.html', form = data, message = "Hmm, your note looks like spam. To submit your note, type the numbers or letters you see in the field below.") resource_id = prr.add_note(request_id = data['request_id'], text = data['note_text'], passed_spam_filter = True) else: resource_id = prr.add_resource(resource = resource, request_body = data, current_user_id = None) if type(resource_id) == int: request_id = data['request_id'] audience = 'public' if 'subscriber' in resource: audience = 'follower' return redirect(url_for('show_request_for_x', audience=audience, request_id = request_id)) return render_template('error.html')
def make_request(text, email=None, user_id=None, phone=None, alias=None, department=None, passed_recaptcha=False): """ Make the request. At minimum you need to communicate which record(s) you want, probably with some text.""" if (app.config['ENVIRONMENT'] == 'PRODUCTION') and (not passed_recaptcha) and is_spam(text): return None, False request_id = find_request(text) if request_id: # Same request already exists return request_id, False assigned_to_email = app.config['DEFAULT_OWNER_EMAIL'] assigned_to_reason = app.config['DEFAULT_OWNER_REASON'] if department: prr_email = db_helpers.get_contact_by_dept(department) if prr_email: assigned_to_email = prr_email assigned_to_reason = "PRR Liaison for %s" % (department) else: print "%s is not a valid department" % (department) department = None request_id = create_request( text=text, user_id=user_id, department=department) # Actually create the Request object new_owner_id = assign_owner( request_id=request_id, reason=assigned_to_reason, email=assigned_to_email) # Assign someone to the request open_request( request_id) # Set the status of the incoming request to "Open" if email or phone or alias: # If the user provided an e-mail address, add them as a subscriber to the request. subscriber_user_id = create_or_return_user(email=email, alias=alias, phone=phone) subscriber_id, is_new_subscriber = create_subscriber( request_id=request_id, user_id=subscriber_user_id) if subscriber_id: generate_prr_emails( request_id, notification_type="Request made", user_id=subscriber_user_id) # Send them an e-mail notification return request_id, True
def new_request(passed_recaptcha=False, data=None): if data or request.method == "POST": if not data and not passed_recaptcha: data = request.form.copy() email = data["request_email"] request_text = data["request_text"] if request_text == "": return render_template("error.html", message="You cannot submit an empty request.") if email == "" and "ignore_email" not in data and not passed_recaptcha: return render_template("missing_email.html", form=data, user_id=get_user_id()) if (app.config["ENVIRONMENT"] == "PRODUCTION") and is_spam(request_text) and not passed_recaptcha: return render_template( "recaptcha.html", form=data, message="Hmm, your request looks like spam. To submit your request, type the numbers or letters you see in the field below.", public_key=app.config["RECAPTCHA_PUBLIC_KEY"], ) alias = None phone = None if "request_alias" in data: alias = data["request_alias"] if "request_phone" in data: phone = data["request_phone"] request_id, is_new = make_request( text=request_text, email=email, user_id=get_user_id(), alias=alias, phone=phone, passed_recaptcha=passed_recaptcha, ) if is_new: return redirect(url_for("show_request_for_x", request_id=request_id, audience="new")) if not request_id: return render_template("error.html", message="Your request looks a lot like spam.") return render_template("error.html", message="Your request is the same as /request/%s" % request_id) else: doc_types = os.path.exists(os.path.join(app.root_path, "static/json/doctypes.json")) return render_template("new_request.html", doc_types=doc_types, user_id=get_user_id())
def new_request(passed_recaptcha = False, data = None): if request.method == 'POST' or data: if not passed_recaptcha: data = request.form.copy() email = data['request_email'] request_text = data['request_text'] if request_text == "": return render_template('error.html', message = "You cannot submit an empty request.") if email == "" and 'ignore_email' not in data and not passed_recaptcha: return render_template('missing_email.html', form = data, user_id = get_user_id()) if is_spam(request_text) and not passed_recaptcha: return render_template('recaptcha.html', form = data, message = "Hmm, your request looks like spam. To submit your request, type the numbers or letters you see in the field below.", public_key = app.config['RECAPTCHA_PUBLIC_KEY']) alias = None phone = None if 'request_alias' in data: alias = data['request_alias'] if 'request_phone' in data: phone = data['request_phone'] assigned_to_email = app.config['DEFAULT_OWNER_EMAIL'] assigned_to_reason = app.config['DEFAULT_OWNER_REASON'] department = data['request_department'] if department: prr_email = db_helpers.get_contact_by_dept(department) if prr_email: assigned_to_email = prr_email assigned_to_reason = "PRR Liaison for %s" %(department) else: print "%s is not a valid department" %(department) department = None request_id, is_new = make_request(text = request_text, email = email, assigned_to_email = assigned_to_email, assigned_to_reason = assigned_to_reason, user_id = get_user_id(), alias = alias, phone = phone, department = department, passed_recaptcha = passed_recaptcha) if is_new: return redirect(url_for('show_request_for_x', request_id = request_id, audience = 'new')) if not request_id: return render_template('error.html', message = "Your request looks a lot like spam.") return render_template('error.html', message = "Your request is the same as /request/%s" % request_id) else: doc_types = os.path.exists(os.path.join(app.root_path, 'static/json/doctypes.json')) return render_template('new_request.html', doc_types = doc_types, user_id = get_user_id())
def new_request(passed_recaptcha=False, data=None): if data or request.method == 'POST': if not data and not passed_recaptcha: data = request.form.copy() email = data['request_email'] request_text = data['request_text'] if request_text == "": return render_template( 'error.html', message="You cannot submit an empty request.") if email == "" and 'ignore_email' not in data and not passed_recaptcha: return render_template('missing_email.html', form=data) if not passed_recaptcha and (is_spam( comment=request_text, user_ip=request.remote_addr, user_agent=request.headers.get('User-Agent'))): return render_template( 'recaptcha_request.html', form=data, message= "Hmm, your request looks like spam. To submit your request, type the numbers or letters you see in the field below." ) alias = None phone = None offline_submission_type = None date_received = None department = None if 'request_department' in data: department = data['request_department'] if 'request_alias' in data: alias = data['request_alias'] if 'request_phone' in data: phone = data['request_phone'] if 'format_received' in data: offline_submission_type = data['format_received'] if 'date_received' in data: # From the jQuery datepicker date_received = data['date_received'] if date_received != "": try: date_received = datetime.strptime(date_received, '%m/%d/%Y') except ValueError: return render_template( 'error.html', message="Please use the datepicker to select a date.") if date_received.date() > date.today(): return render_template( 'error.html', message= "Please choose a request receipt date that is no later than today." ) tz = pytz.timezone(app.config['TIMEZONE']) offset = tz.utcoffset(datetime.now()) offset = (offset.days * 86400 + offset.seconds) / 3600 date_received = date_received - timedelta( hours=offset ) # This is somewhat of a hack, but we need to get this back in UTC time but still treat it as a 'naive' datetime object request_id, is_new = make_request( text=request_text, email=email, alias=alias, phone=phone, passed_spam_filter=True, department=department, offline_submission_type=offline_submission_type, date_received=date_received) if is_new: return redirect( url_for('show_request_for_x', request_id=request_id, audience='new')) if not request_id: return render_template( 'error.html', message="Your request looks a lot like spam.") app.logger.info("\n\nDuplicate request entered: %s" % request_text) return render_template( 'error.html', message="Your request is the same as /request/%s" % request_id) else: departments = None routing_available = False if 'LIAISONS_URL' in app.config: routing_available = True departments = db.session.query(models.Department).all() if current_user.is_authenticated(): return render_template('offline_request.html', routing_available=routing_available, departments=departments) else: return render_template('new_request.html', routing_available=routing_available, departments=departments)