Beispiel #1
0
def update_resource(resource, request_body):
    fields = request_body
    if "owner" in resource:
        if "reason_unassigned" in fields:
            return remove_staff_participant(owner_id=fields['owner_id'],
                                            reason=fields['reason_unassigned'])
        else:
            change_request_status(int(fields['request_id']), "Rerouted")
            return assign_owner(int(fields['request_id']),
                                fields['owner_reason'], fields['owner_email'])
    elif "reopen" in resource:
        change_request_status(int(fields['request_id']), "Reopened")
        return fields['request_id']
    elif "request_text" in resource:
        update_obj(attribute="text",
                   val=fields['request_text'],
                   obj_type="Request",
                   obj_id=fields['request_id'])
    elif "note_text" in resource:
        update_obj(attribute="text",
                   val=fields['note_text'],
                   obj_type="Note",
                   obj_id=fields['response_id'])
        # Need to store note text somewhere else (or just do delete here as well)
    elif "note_delete" in resource:
        # Need to store note somewhere else
        remove_obj("Note", int(fields['response_id']))
    elif "record_delete" in resource:
        remove_obj("Record", int(fields['record_id']))
        # Need to store record somewhere else and prompt them to delete from Scribd as well, if they'd like
    else:
        return False
Beispiel #2
0
def close_request(request_id, reason = "", user_id = None):
	req = get_obj("Request", request_id)
	change_request_status(request_id, "Closed")
	# Create a note to capture closed information:
	create_note(request_id, reason, user_id)
	generate_prr_emails(request_id = request_id, notification_type = "Request closed")
	add_staff_participant(request_id = request_id, user_id = user_id)
Beispiel #3
0
def add_link(request_id, url, description, user_id):
	""" Creates a record with link attributes """
	record_id = create_record(url = url, request_id = request_id, user_id = user_id, description = description)
	if record_id:
		change_request_status(request_id, "A response has been added.")
		generate_prr_emails(request_id = request_id, notification_type = "City response added")
		add_staff_participant(request_id = request_id, user_id = user_id)
		return record_id
	return False
Beispiel #4
0
def add_offline_record(request_id, description, access, user_id):
	""" Creates a record with offline attributes """
	record_id = create_record(request_id = request_id, user_id = user_id, access = access, description = description) # To create an offline record, we need to know the request ID to which it will be added, the user ID for the person adding the record, how it can be accessed, and a description/title of the record.
	if record_id:
		change_request_status(request_id, "A response has been added.")
		generate_prr_emails(request_id = request_id, notification_type = "City response added")
		add_staff_participant(request_id = request_id, user_id = user_id)
		return record_id
	return False
Beispiel #5
0
def ask_a_question(request_id, user_id, question):
	""" City staff can ask a question about a request they are confused about."""
	req = get_obj("Request", request_id)
	qa_id = create_QA(request_id = request_id, question = question, user_id = user_id)
	if qa_id:
		change_request_status(request_id, "Pending")
		requester = req.requester()
		if requester:
			generate_prr_emails(request_id, notification_type = "Question asked", user_id = requester.user_id)
		add_staff_participant(request_id = request_id, user_id = user_id)
		return qa_id
	return False
Beispiel #6
0
def add_note(request_id, text, user_id = None, passed_spam_filter = False):
	if not text or text == "" or (not passed_spam_filter):
		return False
	note_id = create_note(request_id = request_id, text = text, user_id = user_id)
	if note_id:
		change_request_status(request_id, "A response has been added.")
		if user_id:
			add_staff_participant(request_id = request_id, user_id = user_id)
			generate_prr_emails(request_id = request_id, notification_type = "City response added")
		else:
			generate_prr_emails(request_id = request_id, notification_type = "Public note added")
		return note_id
	return False
Beispiel #7
0
def upload_record(request_id, description, user_id, document = None):
	""" Creates a record with upload/download attributes """
	try:
		doc_id, filename = scribd_helpers.upload_file(document = document, request_id = request_id)
	except:
		return "The upload timed out, please try again."
	if doc_id == False:
		return "Extension type '%s' is not allowed." % filename
	else:
		if str(doc_id).isdigit():
			record_id = create_record(doc_id = doc_id, request_id = request_id, user_id = user_id, description = description, filename = filename, url = app.config['HOST_URL'] + doc_id)
			change_request_status(request_id, "A response has been added.")
			generate_prr_emails(request_id = request_id, notification_type = "City response added")
			add_staff_participant(request_id = request_id, user_id = user_id)
			return record_id
	return "There was an issue with your upload."
Beispiel #8
0
def update_resource(resource, request_body):
	fields = request_body
	if "owner" in resource:
		if "reason_unassigned" in fields:
			return remove_staff_participant(owner_id = fields['owner_id'], reason = fields['reason_unassigned'])
		else:
			change_request_status(int(fields['request_id']), "Rerouted")
			return assign_owner(int(fields['request_id']), fields['owner_reason'], fields['owner_email'])
	elif "reopen" in resource:
		change_request_status(int(fields['request_id']), "Reopened")
		return fields['request_id']
	elif "request_text" in resource:
		update_obj(attribute = "text", val = fields['request_text'], obj_type = "Request", obj_id = fields['request_id'])
	elif "note_text" in resource:
		update_obj(attribute = "text", val = fields['note_text'], obj_type = "Note", obj_id = fields['response_id'])
	elif "note_delete" in resource:
		remove_obj("Note", int(fields['response_id']))
	elif "record_delete" in resource:
		remove_obj("Record", int(fields['record_id']))
	else:
		return False
Beispiel #9
0
def upload_record(request_id, description, user_id, document=None):
    """ Creates a record with upload/download attributes """
    try:
        doc_id, filename = scribd_helpers.upload_file(document=document,
                                                      request_id=request_id)
    except:
        return "The upload timed out, please try again."
    if doc_id == False:
        return "Extension type '%s' is not allowed." % filename
    else:
        if str(doc_id).isdigit():
            record_id = create_record(doc_id=doc_id,
                                      request_id=request_id,
                                      user_id=user_id,
                                      description=description,
                                      filename=filename,
                                      url=app.config['HOST_URL'] + doc_id)
            change_request_status(request_id, "A response has been added.")
            generate_prr_emails(request_id=request_id,
                                notification_type="City response added")
            add_staff_participant(request_id=request_id, user_id=user_id)
            return record_id
    return "There was an issue with your upload."
Beispiel #10
0
def update_resource(resource, request_body):
	fields = request_body
	if "owner" in resource:
		if "reason_unassigned" in fields:
			return remove_staff_participant(owner_id = fields['owner_id'], reason = fields['reason_unassigned'])
		else:
			change_request_status(int(fields['request_id']), "Rerouted")
			return assign_owner(int(fields['request_id']), fields['owner_reason'], fields['owner_email'])
	elif "reopen" in resource:
		change_request_status(int(fields['request_id']), "Reopened")
		return fields['request_id']
	elif "request_text" in resource:
		update_obj(attribute = "text", val = fields['request_text'], obj_type = "Request", obj_id = fields['request_id'])
	elif "note_text" in resource:
		update_obj(attribute = "text", val = fields['note_text'], obj_type = "Note", obj_id = fields['response_id'])
		# Need to store note text somewhere else (or just do delete here as well)
	elif "note_delete" in resource:
		# Need to store note somewhere else
		remove_obj("Note", int(fields['response_id']))
	elif "record_delete" in resource:
		remove_obj("Record", int(fields['record_id']))
		# Need to store record somewhere else and prompt them to delete from Scribd as well, if they'd like
	else:
		return False
Beispiel #11
0
def close_request_spam(user_id, request_id, reason = "This is spam"):
	req = get_obj("Request", request_id)
	change_request_status(request_id, "Closed")
	# Create a note to capture closed information:
	create_note(request_id, reason, user_id)
	add_staff_participant(request_id = request_id, user_id = user_id)
Beispiel #12
0
def open_request(request_id):
	change_request_status(request_id, "Open")