diff --git a/public_records_portal/db_helpers.py b/public_records_portal/db_helpers.py index 35fefadd1..7e660856f 100644 --- a/public_records_portal/db_helpers.py +++ b/public_records_portal/db_helpers.py @@ -31,9 +31,9 @@ def id_counter(): currentRequestId = id_generator.next() -# @export "get_subscriber" def get_subscriber(request_id, user_id=None): # Returns the subscriber for a given request by user ID + app.logger.info("def get_subscriber") if request_id and user_id: return Subscriber.query.filter_by(user_id=user_id).filter_by( request_id=request_id).first() @@ -42,23 +42,23 @@ def get_subscriber(request_id, user_id=None): return None -# @export "get_count" def get_count(obj_type): + app.logger.info("def get_count") return db.session.query(func.count(eval(obj_type).id)).scalar() -# @export "get_obj" def get_obj(obj_type, obj_id): """ Query the database for an object via its class/type (defined in models.py) and ID and return the object. """ + app.logger.info("def get_obj") if not obj_id: return None return eval(obj_type).query.get(obj_id) -# @export "get_objs" def get_objs(obj_type): """ Query the database for all objects of a certain class/type (defined in models.py) and return queryset. """ # There has to be a better way of doing this + app.logger.info("def get_objs") if obj_type == "User": return User.query.all() elif obj_type == "Request": @@ -76,8 +76,8 @@ def get_objs(obj_type): return None -# @export "get_avg_response_time" def get_avg_response_time(department): + app.logger.info("def get_avg_response_time") app.logger.info( "\n\nCalculating average response time for department: %s" % department) d = Department.query.filter_by(name=department).first() @@ -100,17 +100,17 @@ def get_avg_response_time(department): return None -# @export "get_request_by_owner" def get_request_by_owner(owner_id): """ Return the request that a particular owner belongs to """ + app.logger.info("def get_request_by_owner") if not owner_id: return None return Owner.query.get(owner_id).request -# @export "get_owners_by_user_id" def get_owners_by_user_id(user_id): """ Return the queryset of owners for a particular user. (A user can be associated with multiple owners).""" + app.logger.info("def get_owners_by_user_id") if not user_id: return None return Owner.query.filter_by(user_id=user_id) @@ -118,27 +118,25 @@ def get_owners_by_user_id(user_id): def get_contact_by_dept(dept): """ Return the contact for a given department. """ + app.logger.info("def get_contact_by_dept") d = Department.query.filter(Department.name == dept).first() if d and d.primary_contact: return d.primary_contact.email return None -### @export "get_backup_by_dept" def get_backup_by_dept(dept): """ Return the backup for a given department. """ + app.logger.info("def get_backup_by_dept") d = Department.query.filter(Department.name == dept).first() if d and d.backup_contact: return d.backup_contact.email return None -### @export "put_obj" - - -# @export "put_obj" def put_obj(obj): """ Add and commit the object to the database. Return true if successful. """ + app.logger.info("def put_obj") if obj: db.session.add(obj) db.session.commit() @@ -147,9 +145,9 @@ def put_obj(obj): return False -# @export "get_attribute" def get_attribute(attribute, obj_id=None, obj_type=None, obj=None): """ Obtain the object by obj_id and obj_type if obj is not provided, and return the specified attribute for that object. """ + app.logger.info("def get_attribute") if obj_id and obj_type: obj = get_obj(obj_type, obj_id) if obj: @@ -160,9 +158,9 @@ def get_attribute(attribute, obj_id=None, obj_type=None, obj=None): return None -# @export "update_obj" def update_obj(attribute, val, obj_type=None, obj_id=None, obj=None): """ Obtain the object by obj_id and obj_type if obj is not provided, and update the specified attribute for that object. Return true if successful. """ + app.logger.info("def update_obj") app.logger.info( "\n\nUpdating attribute: %s with value: %s for obj_type: %s, obj_id: %s, obj: %s" % ( attribute, val, obj_type, obj_id, obj)) @@ -179,20 +177,20 @@ def update_obj(attribute, val, obj_type=None, obj_id=None, obj=None): return False -# @export "create_QA" def create_QA(request_id, question, user_id): """ Create a QA object and return the ID. """ + app.logger.info("def create_QA") qa = QA(request_id=request_id, question=question, user_id=user_id) db.session.add(qa) db.session.commit() return qa.id -# @export "create_request" def create_request(id=id, agency=None, summary=None, text=None, user_id=None, offline_submission_type=None, date_received=None): """ Create a Request object and return the ID. """ + app.logger.info("def create_request") agency_id = Department.query.filter_by(name=agency).first().id req = Request(id=id, agency=agency_id, summary=summary, text=text, creator_id=user_id, offline_submission_type=offline_submission_type, date_received=date_received) @@ -202,9 +200,9 @@ def create_request(id=id, agency=None, summary=None, text=None, user_id=None, return req.id -# @export "create_subscriber" def create_subscriber(request_id, user_id): """ Create a Subscriber object and return the ID. """ + app.logger.info("def create_subscriber") subscriber = Subscriber.query.filter_by( request_id=request_id, user_id=user_id).first() if not subscriber: @@ -215,9 +213,9 @@ def create_subscriber(request_id, user_id): return subscriber.id, False -# @export "create_note" def create_note(request_id, text, user_id, privacy): """ Create a Note object and return the ID. """ + app.logger.info("def create_note") try: note = Note(request_id=request_id, text=text, user_id=user_id, privacy=privacy) @@ -230,9 +228,9 @@ def create_note(request_id, text, user_id, privacy): return None -# @export "create_record" def create_record(request_id, user_id, description, doc_id=None, filename=None, access=None, url=None, privacy=True): + app.logger.info("def create_record") try: record = Record(doc_id=doc_id, request_id=request_id, user_id=user_id, description=description, filename=filename, url=url, @@ -246,13 +244,14 @@ def create_record(request_id, user_id, description, doc_id=None, filename=None, def remove_obj(obj_type, obj_id): + app.logger.info("def remove_obj") obj = get_obj(obj_type, obj_id) db.session.delete(obj) db.session.commit() -# @export "create_answer" def create_answer(qa_id, subscriber_id, answer): + app.logger.info("def create_answer") qa = get_obj("QA", qa_id) if not qa: app.logger.info("\n\nQA with id: %s does not exist" % (qa_id)) @@ -266,18 +265,17 @@ def create_answer(qa_id, subscriber_id, answer): # Following three functions are for integration with Mozilla Persona -# @export "get_user" def get_user(kwargs): + app.logger.info("def get_user") return User.query.filter(User.email == kwargs.get('email')).filter( User.is_staff == True).first() -# @export "get_user_by_id" def get_user_by_id(id): + app.logger.info("def get_user_by_id") return User.query.get(id) -### @export "authenticate_login" def authenticate_login(email, password): """ @@ -288,9 +286,10 @@ def authenticate_login(email, password): :return: The user object, if the user is authenticated, otherwise None :rtype: User object """ + app.logger.info("def authenticate_login") if app.config['USE_LDAP'] == 'True': app.logger.info("Use LDAP: %s" % app.config['USE_LDAP']) - # # Setup the LDAP Options + # Setup the LDAP Options if app.config['LDAP_USE_TLS']: # Sets up TLS for LDAP connection ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, @@ -344,10 +343,11 @@ def authenticate_login(email, password): return user return None + def create_or_return_user(email=None, alias=None, first_name=None, last_name=None, phone=None, fax=None, address1=None, address2=None, city=None, state=None, zipcode=None, department=None, contact_for=None, backup_for=None, not_id=False, is_staff=None, password=None, role=None): - app.logger.info("\n\nCreating or returning user...") + app.logger.info("def create_or_return_user") try: if phone is not None: phone = str(phone.country_code) + str(phone.national_number) @@ -407,9 +407,9 @@ def create_or_return_user(email=None, alias=None, first_name=None, last_name=Non return user.id -# @export "create_user" def create_user(email=None, alias=None, first_name=None, last_name=None, phone=None, fax=None, address1=None, address2=None, city=None, state=None, zipcode=None, department=None, contact_for=None, backup_for=None, password=None, is_staff=None, role=None): + app.logger.info("def create_user") user = User(email=email, alias=alias, first_name=first_name, last_name=last_name, phone=phone, fax=fax, address1=address1, address2=address2, city=city, state=state, zipcode=zipcode, department=department, contact_for=contact_for, @@ -422,9 +422,9 @@ def create_user(email=None, alias=None, first_name=None, last_name=None, phone=N return user -# @export "update_user" def update_user(user, alias=None, first_name=None, last_name=None, phone=None, fax=None, address1=None, address2=None, city=None, state=None, zipcode=None, department=None, contact_for=None, backup_for=None, is_staff=None, role=None): + app.logger.info("def update_user") if alias: user.alias = alias if first_name: @@ -472,10 +472,10 @@ def update_user(user, alias=None, first_name=None, last_name=None, phone=None, f return user -# @export "create_owner" def create_owner(request_id, reason, email=None, user_id=None): """ Adds a staff member to the request without assigning them as current owner. (i.e. "participant") Useful for multidepartmental requests.""" + app.logger.info("def create_owner") if not user_id: user_id = create_or_return_user(email=email) participant = Owner(request_id=request_id, user_id=user_id, reason=reason) @@ -485,8 +485,8 @@ def create_owner(request_id, reason, email=None, user_id=None): return participant.id -# @export "change_request_status" def change_request_status(request_id, status): + app.logger.info("def change_request_status") req = get_obj("Request", request_id) req.prev_status = req.status req.status = status @@ -505,18 +505,18 @@ def change_request_status(request_id, status): db.session.commit() -# @export "find_request" def find_request(text): + app.logger.info("def find_request") req = Request.query.filter_by(summary=text).first() if req: return req return None -# @export "add_staff_participant" def add_staff_participant(request_id, is_point_person=False, email=None, user_id=None, reason=None): """ Creates an owner for the request if it doesn't exist, and returns the owner ID and True if a new one was created. Returns the owner ID and False if existing.""" + app.logger.info("def add_staff_participant") is_new = True if not user_id: user_id = create_or_return_user(email=email) @@ -550,8 +550,8 @@ def add_staff_participant(request_id, is_point_person=False, email=None, return participant.id, is_new -# @export "remove_staff_participant" def remove_staff_participant(owner_id, reason=None): + app.logger.info("def remove_staff_participant") participant = Owner.query.get(owner_id) participant.active = False participant.date_updated = datetime.now().isoformat() @@ -564,9 +564,9 @@ def remove_staff_participant(owner_id, reason=None): return owner_id -# @export "update_subscriber" def update_subscriber(request_id, alias, phone): """ Update a subscriber for a given request with the name and phone number provided. """ + app.logger.info("def update_subscriber") user_id = create_or_return_user(alias=alias, phone=phone) r = Request.query.get(request_id) sub = r.subscribers[0] @@ -578,8 +578,8 @@ def update_subscriber(request_id, alias, phone): request_id, alias, phone)) -### @export "set_random_password" def set_random_password(email): + app.logger.info("def set_random_password") user = User.query.filter(User.email == func.lower(email)).first() # Must be staff or admin to reset password if user and (user.is_staff == True or user.is_admin() == True): diff --git a/public_records_portal/notifications.py b/public_records_portal/notifications.py index 82248a2a6..1b18f0f77 100644 --- a/public_records_portal/notifications.py +++ b/public_records_portal/notifications.py @@ -39,6 +39,7 @@ def generate_prr_emails( ): # 'text=None' is used additional information. # 'text2=None' is used if there are more variable text passed into email such as with 'close this request' and being offered multiple reasons + app.logger.info("def generate_prr_emails") if 'user_id' not in notification_content: notification_content['user_id']=None app.logger.info(''' @@ -304,7 +305,7 @@ def send_prr_email( unfollow_link=None, attached_file=None ): - + app.logger.info("def send_prr_email") app.logger.info(''' Attempting to send an e-mail to %s with subject %s, referencing page %s and template %s''' @@ -346,7 +347,7 @@ def send_email( cc_everyone=False, attached_file=None, ): - + app.logger.info("def send_email") mail = Mail(app) plaintext = '' @@ -401,6 +402,7 @@ def send_email( def due_date(date_obj, extended=None, format=True): + app.logger.info("def due_date") days_to_fulfill = 10 if extended == True: days_to_fulfill = days_to_fulfill + 14 @@ -415,6 +417,7 @@ def due_date(date_obj, extended=None, format=True): def is_overdue(date_obj, extended=None): + app.logger.info("def is_overdue") current_date = datetime.now() due = due_date(date_obj=date_obj, extended=extended, format=False) if current_date >= due: @@ -423,6 +426,7 @@ def is_overdue(date_obj, extended=None): def get_email_info(notification_type): + app.logger.info("def get_email_info") email_json = open(os.path.join(app.root_path, 'static/json/emails.json')) json_data = json.load(email_json) @@ -430,6 +434,7 @@ def get_email_info(notification_type): def notify_due(): + app.logger.info("def notify_due") requests = get_objs('Request') email_json = open(os.path.join(app.root_path, 'static/json/emails.json')) @@ -467,6 +472,7 @@ def notify_due(): def get_staff_recipients(request): + app.logger.info("def get_staff_recipients") recipients = [] owner_email = request.point_person().user.email if owner_email: @@ -491,7 +497,7 @@ def get_staff_recipients(request): def should_notify(user_email): """ Looks up the user in do_not_email.json and returns False if found. """ - + app.logger.info("def should_notify") do_not_email = open(os.path.join(app.root_path, 'static/json/do_not_email.json')) json_data = json.load(do_not_email) @@ -505,7 +511,7 @@ def should_notify(user_email): def format_date(obj): """ Take a datetime object and return it in format Jun 12, 2013 """ - + app.logger.info("def format_date") if not obj: return None return helpers.localize(obj).strftime('%b %d, %Y') diff --git a/public_records_portal/prr.py b/public_records_portal/prr.py index 7f938d54c..0c48e7abe 100644 --- a/public_records_portal/prr.py +++ b/public_records_portal/prr.py @@ -47,7 +47,7 @@ def add_public_note(request_id, text): - app.logger.info("Add Public Note") + app.logger.info("def add_public_note") return 1 @@ -56,6 +56,7 @@ def nonportal_request(request_body): # department and the user creating a notification # query with all the fields + app.logger.info("def nonportal_request") notification_content = {} notification_content['department'] = \ Department.query.filter_by(name=request_body['request_agency' @@ -104,6 +105,7 @@ def nonportal_request(request_body): ### @export "add_resource" def add_resource(resource, request_body, current_user_id=None): + app.logger.info("def add_resource") notification_content = {} fields = request_body department_name = \ @@ -208,6 +210,7 @@ def add_resource(resource, request_body, current_user_id=None): ### @export "update_resource" def update_resource(resource, request_body): + app.logger.info("def update_resource") fields = request_body notification_content = {} if 'owner' in resource: @@ -299,7 +302,7 @@ def request_extension( Uses add_resource from prr.py and takes extension date from field retrived from that function. Returns note with new date after adding delta. """ - + app.logger.info("def request_extension") req = Request.query.get(request_id) req.extension(days_after, due_date) user = User.query.get(user_id) @@ -385,6 +388,7 @@ def add_pdf( passed_spam_filter=False, privacy=1, ): + app.logger.info("def add_pdf") if 'template_' in text: template_num = text.split('_')[1] template_name = 'standard_response_' + template_num + '.html' @@ -435,6 +439,7 @@ def add_letter( request_id, text, user_id=None): + app.logger.info("def add_letter") letters_json = open(os.path.join(app.root_path, 'static/json/letters.json')) letters_data = json.load(letters_json) @@ -538,6 +543,7 @@ def add_letter( def generate_denial_page(document): + app.logger.info("def generate_denial_page") document.add_page_break() paragraph = document.add_paragraph() paragraph_format = paragraph.paragraph_format @@ -712,9 +718,7 @@ def upload_record( ): """ Creates a record with upload/download attributes """ - app.logger.info(''' - -Begins Upload_record method''') + app.logger.info("def upload_record") notification_content = {} try: @@ -791,6 +795,7 @@ def add_offline_record( privacy=True, ): """ Creates a record with offline attributes """ + app.logger.info("def add_offline_record") notification_content = {} notification_content['description'] = description notification_content['department_name'] = department_name @@ -819,6 +824,7 @@ def add_link( privacy=True, ): """ Creates a record with link attributes """ + app.logger.info("def add_link") notification_content = {} record_id = create_record(url=url, request_id=request_id, user_id=user_id, description=description, @@ -863,6 +869,7 @@ def make_request( ): """ Make the request. At minimum you need to communicate which record(s) you want, probably with some text.""" + app.logger.info("def make_request") notification_content = {} try: is_partner_agency = agency_codes[agency] @@ -950,6 +957,7 @@ def make_request( ### @export "add_subscriber" def add_subscriber(request_id, email): + app.logger.info("def add_subscriber") notification_content = {} user_id = create_or_return_user(email=email) notification_content['user_id'] = create_or_return_user(email=email) @@ -972,7 +980,7 @@ def ask_a_question( department_name=None, ): """ City staff can ask a question about a request they are confused about.""" - + app.logger.info("def ask_a_question") notification_content = {} req = get_obj('Request', request_id) qa_id = create_QA(request_id=request_id, question=question, @@ -1000,7 +1008,7 @@ def answer_a_question( passed_spam_filter=False, ): """ A requester can answer a question city staff asked them about their request.""" - + app.logger.info("def answer_a_question") if not answer or answer == '' or not passed_spam_filter: return False else: @@ -1017,6 +1025,7 @@ def answer_a_question( ### @export "open_request" def open_request(request_id): + app.logger.info("def open_request") change_request_status(request_id, 'Open') @@ -1024,6 +1033,7 @@ def open_request(request_id): def assign_owner(request_id, reason=None, email=None): """ Called any time a new owner is assigned. This will overwrite the current owner.""" + app.logger.info("def assign_owner") notification_content = {} req = get_obj('Request', request_id) past_owner_id = None @@ -1071,6 +1081,7 @@ def assign_owner(request_id, reason=None, email=None): ### @export "get_request_data_chronologically" def get_request_data_chronologically(req): + app.logger.info("def get_request_data_chronologically") public = False if current_user.is_anonymous: public = True @@ -1093,6 +1104,7 @@ def get_request_data_chronologically(req): ### @export "get_responses_chronologically" def get_responses_chronologically(req): + app.logger.info("def get_responses_chronologically") responses = [] if not req: return responses @@ -1123,7 +1135,7 @@ def get_responses_chronologically(req): def set_directory_fields(): # Set basic user data - + app.logger.info("def set_directory_fields") if 'STAFF_URL' in app.config: # This gets run at regular internals via db_users.py in order to keep the staff user list up to date. Before users are added/updated, ALL users get reset to 'inactive', and then only the ones in the current CSV are set to active. @@ -1190,6 +1202,7 @@ def set_directory_fields(): def set_department_contact(department_name, attribute_name, user_id): department = Department.query.filter(Department.name == department_name).first() + app.logger.info("def set_department_contact") user_obj = get_user_by_id(user_id) user_email = user_obj.email app.logger.info(''' @@ -1209,6 +1222,7 @@ def close_request( user_id=None, request_body=None, ): + app.logger.info("def close_request") req = get_obj('Request', request_id) change_request_status(request_id, 'Closed') notification_content = {} @@ -1267,9 +1281,9 @@ def close_request( def change_privacy_setting(request_id, privacy, field): + app.logger.info("def change_privacy_setting") req = get_obj('Request', request_id) if field == 'title': - # Set the title to private update_obj(attribute='titlePrivate', val=privacy, obj_type='Request', obj_id=req.id) @@ -1283,5 +1297,6 @@ def change_privacy_setting(request_id, privacy, field): def change_record_privacy(record_id, privacy): + app.logger.info("def change_record_privacy") record = get_obj("Record", record_id) update_obj(attribute="privacy", val=privacy, obj_type="Record", obj_id=record.id) diff --git a/public_records_portal/upload_helpers.py b/public_records_portal/upload_helpers.py index a78bc2bc1..7de4210a5 100644 --- a/public_records_portal/upload_helpers.py +++ b/public_records_portal/upload_helpers.py @@ -26,6 +26,7 @@ def should_upload(): + app.logger.info("def should_upload") if app.config['ENVIRONMENT'] != 'LOCAL' or app.config['UPLOAD_DOCS'] == 'True': return True return False @@ -38,6 +39,7 @@ def upload_multiple_files(documents, request_id): :param request_id: FOIL Request ID Number :return: None """ + app.logger.info("def upload_multiple_files") for document in documents: upload_file(document=document, request_id=request_id) @@ -51,6 +53,7 @@ def upload_file(document, request_id, privacy=0x1): :param privacy: Privacy value for the uploaded document :return: (Boolean, String, String) """ + app.logger.info("def upload_file") if not should_upload(): # Should the file be uploaded app.logger.info("Upload functionality has been disabled\n\n") @@ -93,6 +96,7 @@ def scan_file(document, file_length): :param file_length: Size of document to be scanned :return: Boolean """ + app.logger.info("def scan_file") app.logger.info("Scanning File: %s" % secure_filename(document.filename)) # Create Socket @@ -193,6 +197,7 @@ def scan_file(document, file_length): def upload_file_locally(document, filename, privacy): + app.logger.info("def upload_file_locally") app.logger.info("\n\nuploading file locally") app.logger.info("\n\n%s" % (document)) @@ -208,5 +213,6 @@ def upload_file_locally(document, filename, privacy): ### @export "allowed_file" def allowed_file(filename): + app.logger.info("def allowed_file") ext = filename.rsplit('.', 1)[1] return ext in ALLOWED_EXTENSIONS \ No newline at end of file diff --git a/public_records_portal/views.py b/public_records_portal/views.py index 20727bcfc..2e279c424 100644 --- a/public_records_portal/views.py +++ b/public_records_portal/views.py @@ -61,6 +61,7 @@ @app.before_first_request def create_user(): + app.logger.info("def create_user") db.create_all() #@app.before_request @@ -69,12 +70,14 @@ def create_user(): @app.before_request def csrf_protect(): + app.logger.info("def csrf_protect") if request.method == "POST": token = session.pop("_csrf_token", None) if not token or token != request.form.get('_csrf_token'): return access_denied(403) def generate_csrf_token(): + app.logger.info("def generate_csrf_token") if '_csrf_token' not in session: session['_csrf_token'] = str(uuid4()) app.logger.info('CSRF Token: %s' % session['_csrf_token']) @@ -84,6 +87,7 @@ def generate_csrf_token(): # Submitting a new request @app.route("/new", methods=["GET", "POST"]) def new_request(passed_recaptcha=False, data=None): + app.logger.info("def new_request") category = { 'Business': [ "Department of Consumer Affairs", @@ -443,12 +447,14 @@ def new_request(passed_recaptcha=False, data=None): @app.route("/faq") def faq(): + app.logger.info("def faq") return render_template("faq.html") @app.route("/export") @login_required def to_csv(): + app.logger.info("def to_csv") filename = request.form.get('filename', 'records.txt') return Response(csv_export.export(), mimetype='text/plain', @@ -459,6 +465,7 @@ def to_csv(): @app.route("/", methods=["GET", "POST"]) def index(): + app.logger.info("def index") if current_user.is_anonymous == False: return redirect(url_for('display_all_requests')) else: @@ -468,11 +475,13 @@ def index(): @app.route("/landing") def landing(): + app.logger.info("def landing") return render_template('landing.html') @login_manager.unauthorized_handler def unauthorized(): + app.logger.info("def unauthorized") app.logger.info("\n\nuser is unauthorized.") return render_template("alpha.html") @@ -483,6 +492,7 @@ def unauthorized(): def explain_all_actions(): + app.logger.info("def explain_all_actions") action_json = open(os.path.join(app.root_path, 'static/json/actions.json')) json_data = json.load(action_json) actions = [] @@ -496,6 +506,7 @@ def explain_all_actions(): @app.route("//request/") def show_request_for_x(audience, request_id): + app.logger.info("def show_request_for_x") proper_request_id = re.match("FOIL-\d{4}-\d{3}-\d{5}", request_id) if proper_request_id: if "city" in audience: @@ -511,6 +522,7 @@ def show_request_for_x(audience, request_id): @login_required @requires_roles('Portal Administrator', 'Agency Administrator', 'Agency FOIL Personnel', 'Agency Helpers') def show_request_for_city(request_id): + app.logger.info("def show_request_for_city") req = get_obj("Request", request_id) app.logger.info("Current User Role: %s" % current_user.role) if current_user.role == 'Portal Administrator': @@ -531,6 +543,7 @@ def show_request_for_city(request_id): @app.route("/response/") def show_response(request_id): + app.logger.info("def show_response") req = get_obj("Request", request_id) if not req: return render_template('error.html', message="A request with ID %s does not exist." % request_id) @@ -539,6 +552,7 @@ def show_response(request_id): @app.route("/track", methods=["GET", "POST"]) def track(request_id=None): + app.logger.info("def track") if request.method == 'POST': if not re.match("FOIL-\d{4}-\d{3}-\d{5}", request.form["request_id"]): request_id = request.form['request_id'] @@ -557,6 +571,7 @@ def track(request_id=None): @app.route("/unfollow//") def unfollow(request_id, email): + app.logger.info("def unfollow") success = False user_id = create_or_return_user(email.lower()) subscriber = get_subscriber(request_id=request_id, user_id=user_id) @@ -571,6 +586,7 @@ def unfollow(request_id, email): @app.route("/request/") def show_request(request_id, template="manage_request_public.html", errors=None, form=None, file=None): + app.logger.info("def show_request") req = get_obj("Request", request_id) if not req: return page_not_found(494) @@ -632,6 +648,7 @@ def show_request(request_id, template="manage_request_public.html", errors=None, @app.route("/api/departments") def departments_to_json(): + app.logger.info("def departments_to_json") departments = models.Department.query.all() agency_data = [] for d in departments: @@ -646,6 +663,7 @@ def docs(): @app.route("/edit/request/") @login_required def edit_case(request_id): + app.logger.info("def edit_case") req = get_obj("Request", request_id) return render_template("edit_case.html", req=req) @@ -653,6 +671,7 @@ def edit_case(request_id): @app.route("/add_a_", methods=["GET", "POST"]) @login_required def add_a_resource(resource): + app.logger.info("def add_a_resource") req = request.form errors = {} if request.method == 'POST': @@ -697,6 +716,7 @@ def add_a_resource(resource): @app.route("/public_add_a_", methods=["GET", "POST"]) def public_add_a_resource(resource, passed_recaptcha=False, data=None): + app.logger.info("def public_add_a_resource") if (data or request.method == 'POST') and ('note' in resource or 'subscriber' in resource): if not data: data = request.form.copy() @@ -717,6 +737,7 @@ def public_add_a_resource(resource, passed_recaptcha=False, data=None): @app.route("/update_a_", methods=["GET", "POST"]) def update_a_resource(resource, passed_recaptcha=False, data=None): + app.logger.info("def update_a_resource") if (data or request.method == 'POST'): req = request.form if not data: @@ -737,6 +758,7 @@ def update_a_resource(resource, passed_recaptcha=False, data=None): @app.route("/acknowledge_request", methods=["GET", "POST"]) def acknowledge_request(resource, passed_recaptcha=False, data=None): + app.logger.info("def acknowledge_request") if (data or request.method == 'POST'): if not data: data = request.form.copy() @@ -756,6 +778,7 @@ def acknowledge_request(resource, passed_recaptcha=False, data=None): @app.route("/close", methods=["GET", "POST"]) @login_required def close(request_id=None): + app.logger.info("def close") if request.method == 'POST': template = 'closed.html' request_id = request.form['request_id'] @@ -771,6 +794,7 @@ def close(request_id=None): def filter_agency(departments_selected, results): + app.logger.info("def filter_agency") if departments_selected and 'All departments' not in departments_selected: app.logger.info("\n\nagency filters:%s." % departments_selected) department_ids = [] @@ -788,6 +812,7 @@ def filter_agency(departments_selected, results): def filter_search_term(search_input, results): + app.logger.info("def filter_search_term") if search_input: app.logger.info("Searching for '%s'." % search_input) search_terms = search_input.strip().split( @@ -804,6 +829,7 @@ def filter_search_term(search_input, results): def filter_request_id(request_id_search, results): + app.logger.info("def filter_request_id") if request_id_search: app.logger.info("Searching for matching request_id '%s'." % filter_request_id) request_id_search = request_id_search.strip() # Get rid of leading and trailing spaces @@ -813,6 +839,7 @@ def filter_request_id(request_id_search, results): def get_filter_value(filters_map, filter_name, is_list=False, is_boolean=False): + app.logger.info("def get_filter_value") if filter_name in filters_map: val = filters_map[filter_name] if filter_name == 'agency' and val: @@ -827,6 +854,7 @@ def get_filter_value(filters_map, filter_name, is_list=False, is_boolean=False): def is_supported_browser(): + app.logger.info("def is_supported_browser") browser = request.user_agent.browser version = request.user_agent.version and int(request.user_agent.version.split('.')[0]) platform = request.user_agent.platform @@ -849,22 +877,26 @@ def is_supported_browser(): @app.route("/view_requests", methods=["GET"]) def display_all_requests(): + app.logger.info("def display_all_requests") return no_backbone_requests() @app.route("/view_requests_backbone") def backbone_requests(): + app.logger.info("def backbone_requests") return render_template("all_requests.html", departments=db.session.query(models.Department).all(), total_requests_count=get_count("Request")) @app.route("/view_requests_no_backbone") def no_backbone_requests(): + app.logger.info("def no_backbone_requests") return fetch_requests() @app.route("/requests", methods=["GET"]) def fetch_requests(output_results_only=False, filters_map=None, date_format='%Y-%m-%d', checkbox_value='on'): + app.logger.info("def fetch_requests") user_id = get_user_id() # Sets the search parameters. They are a dictionary that either came in through: @@ -1028,6 +1060,7 @@ def json_requests(): Supports limit, search, and page parameters and returns json with an object that has a list of results in the 'objects' field. """ + app.logger.info("def json_requests") objects, num_results, more_results, start_index, end_index = fetch_requests(output_results_only=True, filters_map=request.args, date_format='%m/%d/%Y', @@ -1044,6 +1077,7 @@ def json_requests(): def prepare_request_fields(results): + app.logger.info("def prepare_requests_fields") return map(lambda r: { "id": r.id, \ "summary": helpers.clean_text(r.summary), \ @@ -1061,6 +1095,7 @@ def prepare_request_fields(results): def filter_department(departments_selected, results): + app.logger.info("def filter_department") if departments_selected and 'All Agencies' not in departments_selected: app.logger.info("\n\nagency filters:%s." % departments_selected) department_ids = [] @@ -1081,6 +1116,7 @@ def get_results_by_filters(departments_selected, is_open, is_closed, due_soon, o sort_column, sort_direction, search_term, min_due_date, max_due_date, min_date_received, max_date_received, requester_name, page_number, user_id, date_format, checkbox_value, request_id_search): + app.logger.info("def get_results_by_filters") # Initialize query results = db.session.query(models.Request) @@ -1176,6 +1212,7 @@ def get_results_by_filters(departments_selected, is_open, is_closed, due_soon, o @app.route("/tutorial") def tutorial_initial(): + app.logger.info("def tutorial_intial") user_id = get_user_id() app.logger.info("\n\nTutorial accessed by user: %s." % user_id) return render_template('tutorial_01.html') @@ -1183,6 +1220,7 @@ def tutorial_initial(): @app.route("/tutorial/") def tutorial(tutorial_id): + app.logger.info("def tutorial") user_id = get_user_id() tutorial_string_id = tutorial_id.split("_")[0] app.logger.info("\n\nTutorial accessed by user: %s." % user_id) @@ -1191,6 +1229,7 @@ def tutorial(tutorial_id): @app.route("/city/tutorial/") def tutorial_agency(tutorial_id): + app.logger.info("def tutorial_agency") if current_user.is_authenticated: user_id = get_user_id() tutorial_string_id = tutorial_id.split("_")[0] @@ -1202,6 +1241,7 @@ def tutorial_agency(tutorial_id): @app.route("/city/tutorial") def tutorial_agency_initial(): + app.logger.info("def tutorial_agency_initial") if current_user.is_authenticated: user_id = get_user_id() app.logger.info("\n\nTutorial accessed by user: %s." % user_id) @@ -1212,6 +1252,7 @@ def tutorial_agency_initial(): @app.route("/about") def about(): + app.logger.info("def about") return render_template('about.html') @@ -1223,6 +1264,7 @@ def about(): @app.route("/logout") @login_required def logout(): + app.logger.info("def logout") logout_user() session.regenerate() #session.clear() @@ -1238,6 +1280,7 @@ def logout(): def get_user_id(): + app.logger.info("def get_user_id") if current_user.is_authenticated: return current_user.id return None @@ -1248,6 +1291,7 @@ def get_user_id(): @app.route("/is_public_record", methods=["POST"]) def is_public_record(): + app.logger.info("def is_public_record") request_text = request.form['request_text'] not_records_filepath = os.path.join(app.root_path, 'static/json/notcityrecords.json') not_records_json = open(not_records_filepath) @@ -1263,6 +1307,7 @@ def is_public_record(): def get_redirect_target(): """ Taken from http://flask.pocoo.org/snippets/62/ """ + app.logger.info("def get_redirect_target") for target in request.values.get('next'), request.referrer: if not target: continue @@ -1272,6 +1317,7 @@ def get_redirect_target(): def is_safe_url(target): """ Taken from http://flask.pocoo.org/snippets/62/ """ + app.logger.info("def is_safe_url") ref_url = urlparse(request.host_url) test_url = urlparse(urljoin(request.host_url, target)) return test_url.scheme in ('http', 'https') and \ @@ -1280,6 +1326,7 @@ def is_safe_url(target): @app.route("/recaptcha_", methods=["GET", "POST"]) def recaptcha_templatetype(templatetype): + app.logger.info("def recaptcha_templatetype") if request.method == 'POST': template = "recaptcha_" + templatetype + ".html" response = captcha.submit( @@ -1306,6 +1353,7 @@ def recaptcha_templatetype(templatetype): def well_known_status(): ''' ''' + app.logger.info("def well_known_status") response = { 'status': 'ok', 'updated': int(time()), @@ -1340,6 +1388,7 @@ def well_known_status(): @app.route("/register", methods=['GET', 'POST']) def register(): + app.logger.info("def register") form = LoginForm() errors = [] if request.method == 'POST': @@ -1354,6 +1403,7 @@ def register(): @app.route("/edit_user_info", methods=['GET', 'POST']) @login_required def edit_user_info(): + app.logger.info("def edit_user_info") form = EditUserForm(request.form, obj=current_user) errors = [] if request.method == 'POST': @@ -1366,6 +1416,7 @@ def edit_user_info(): @app.route("/login", methods=['GET', 'POST']) def login(): + app.logger.info("def login") form = LoginForm() errors = [] if request.method == 'POST': @@ -1410,21 +1461,20 @@ def login(): @app.route("/attachments/", methods=["GET"]) def get_attachments(resource): - app.logger.info("\n\ngetting attachment file") - + app.logger.info("def get_attachments") return send_from_directory(app.config["UPLOAD_FOLDER"], resource, as_attachment=True) @app.route("/pdfs/", methods=["GET"]) def get_pdfs(resource): - app.logger.info("\n\ngetting pdf file") + app.logger.info("def get_pdfs") return send_from_directory(app.config["PDF_FOLDER"], resource, as_attachment=True) @app.route("/api/report////", methods=["GET"]) def get_report_jsons(calendar_filter, report_type, agency_filter, staff_filter): - app.logger.info("\n\ngenerating report data") + app.logger.info("def get_report_jsons") if not report_type: response = { @@ -1634,6 +1684,7 @@ def get_report_jsons(calendar_filter, report_type, agency_filter, staff_filter): @app.route("/report") def report(): + app.logger.info("def report") users = models.User.query.all() users = models.User.query.order_by(models.User.alias.asc()).all() departments_all = models.Department.query.all() @@ -1651,6 +1702,7 @@ def report(): @app.route("/submit", methods=["POST"]) def submit(): + app.logger.info("def submit") if recaptcha.verify(): pass else: @@ -1659,6 +1711,7 @@ def submit(): @app.route("/changeprivacy", methods=["POST", "GET"]) def change_privacy(): + app.logger.info("def change_privacy") req = get_obj("Request", request.form['request_id']) privacy = request.form['privacy setting'] field = request.form['fieldtype'] @@ -1670,6 +1723,7 @@ def change_privacy(): @app.route("/switchRecordPrivacy", methods=["POST", "GET"]) def switch_record_privacy(): + app.logger.info("def switch_record_privacy") record = get_obj("Record", request.form['record_id']) privacy = request.form['privacy_setting'] app.logger.info( @@ -1682,12 +1736,14 @@ def switch_record_privacy(): @app.route("/changecategory", methods=["POST", "GET"]) def change_category(): + app.logger.info("def change_category") category = request.form['category'] return redirect(render_template('new_request.html')) @app.route("/") def any_page(page): + app.logger.info("def any_page") try: return render_template('%s.html' % (page)) except: @@ -1696,8 +1752,8 @@ def any_page(page): @app.route('/contact', methods=['GET', 'POST']) def contact(): + app.logger.info("def contact") form = ContactForm() - if request.method == 'POST': name = form.name.data email = form.email.data @@ -1734,44 +1790,53 @@ def contact(): @app.errorhandler(400) def bad_request(e): + app.logger.info("def bad_request") return render_template("400.html"), 400 @app.errorhandler(401) def unauthorized(e): + app.logger.info("def unauthorized") return render_template("401.html"), 401 @app.errorhandler(403) def access_denied(e): + app.logger.info("def access_denied") return redirect(url_for('login')) @app.errorhandler(404) def page_not_found(e): + app.logger.info("def page_not_found") return render_template("404.html"), 404 @app.errorhandler(405) def method_not_allowed(e): + app.logger.info("def method_not_allowed") return render_template("405.html"), 405 @app.errorhandler(500) def internal_server_error(e): + app.logger.info("def internal_server_error") return render_template("500.html"), 500 @app.errorhandler(501) def unexplained_error(e): + app.logger.info("def unexplained_error") return render_template("501.html"), 501 @app.errorhandler(502) def bad_gateway(e): + app.logger.info("def bad_gateway") render_template("500.html"), 502 @app.errorhandler(503) def service_unavailable(e): + app.logger.info("def service_unavailable") render_template("500.html"), 503