def __init__(self, request, public):
		self.request = request
		self.id = request.id
		if public:
			self.status = get_status(request, "public")
		else:
			self.requester = get_attribute("alias", obj_id = get_requester(request.id), obj_type = "User")
			status_arr = get_status(request = request, audience = "city", include_due_date = True)
			if status_arr:
				self.status, self.due_date = status_arr[0], date(status_arr[1])
			else:
				self.status, self.due_date = None, None
		self.text = request.text
		if len(self.text) > 140:
			self.text = '%s...' % self.text[:140]
		if self.status == "open":
			self.color = "#2688AD"
		elif self.status == "closed":
			self.color = "#2a2b2b"
		elif self.status == "due soon":
			self.color = "#FB991B"
			self.text = '<span style="background-color: %s" class="label label-warning">%s</span> %s' %(self.color, self.status, self.text)
		elif self.status == "overdue":
			self.color = "#CA1A1A"
			self.text = '<span style="background-color: %s" class="label label-important">%s</span> %s' %(self.color, self.status, self.text)
		else:
			self.color=""
		self.status_icon = get_status_icon(self.status)
		self.point_of_contact, self.department = get_owner_data(request.id, attributes = ["alias", "department"])
		if request.department:
			self.department = request.department
		if public:
			self.display_text = "<td class='status' bgcolor='%s'><small><i class='%s'></i></small></td><td>%s</td><td>%s</td><td><div>%s</div></td><td>%s</td><td>%s</td><td style='display:none;'>%s</td>" %(self.color,self.status_icon,request.id, date(request.date_created), self.text, self.department, self.point_of_contact, request.text)
		else:
			self.display_text = "<td class='status' bgcolor='%s'><small><i class='%s'></i></small></td><td>%s</td><td>%s</td><td><div>%s</div></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td style='display:none;'>%s</td>" %(self.color,self.status_icon,request.id, date(request.date_created), self.text, self.department, self.point_of_contact, (self.due_date or "N/A"), self.requester or "Not given", request.text)
示例#2
0
def assign_owner(request_id, reason, email=None):
    """ Called any time a new owner is assigned. This will overwrite the current owner."""
    req = get_obj("Request", request_id)
    past_owner_id = None
    # If there is already an owner, unassign them:
    if req.point_person():
        past_owner_id = req.point_person().id
        past_owner = get_obj("Owner", req.point_person().id)
        update_obj(attribute="is_point_person", val=False, obj=past_owner)
    owner_id, is_new_owner = add_staff_participant(request_id=request_id,
                                                   reason=reason,
                                                   email=email,
                                                   is_point_person=True)
    if (past_owner_id == owner_id
        ):  # Already the current owner, so don't send any e-mails
        return owner_id

    app.logger.info("\n\nA new owner has been assigned: Owner: %s" % owner_id)
    new_owner = get_obj("Owner", owner_id)
    # Update the associated department on request
    update_obj(attribute="department_id",
               val=new_owner.user.department,
               obj=req)
    user_id = get_attribute(attribute="user_id",
                            obj_id=owner_id,
                            obj_type="Owner")
    # Send notifications
    if is_new_owner:
        generate_prr_emails(request_id=request_id,
                            notification_type="Request assigned",
                            user_id=user_id)
    return owner_id
示例#3
0
def add_resource(resource, request_body, current_user_id=None):
    fields = request_body
    if "extension" in resource:
        return request_extension(int(fields['request_id']),
                                 fields.getlist('extend_reason'),
                                 current_user_id)
    if "note" in resource:
        return add_note(request_id=int(fields['request_id']),
                        text=fields['note_text'],
                        user_id=current_user_id,
                        passed_spam_filter=True
                        )  # Bypass spam filter because they are logged in.
    elif "record" in resource:
        if fields['record_description'] == "":
            return "When uploading a record, please fill out the 'summary' field."
        if 'record_access' in fields and fields['record_access'] != "":
            return add_offline_record(int(fields['request_id']),
                                      fields['record_description'],
                                      fields['record_access'], current_user_id)
        elif 'link_url' in fields and fields['link_url'] != "":
            return add_link(request_id=int(fields['request_id']),
                            url=fields['link_url'],
                            description=fields['record_description'],
                            user_id=current_user_id)
        else:
            document = None
            try:
                document = request.files['record']
            except:
                app.logger.info("\n\nNo file passed in")
            return upload_record(request_id=int(fields['request_id']),
                                 document=document,
                                 description=fields['record_description'],
                                 user_id=current_user_id)
    elif "qa" in resource:
        return ask_a_question(request_id=int(fields['request_id']),
                              user_id=current_user_id,
                              question=fields['question_text'])
    elif "owner" in resource:
        participant_id, new = add_staff_participant(
            request_id=fields['request_id'],
            email=fields['owner_email'],
            reason=fields['owner_reason'])
        if new:
            generate_prr_emails(request_id=fields['request_id'],
                                notification_type="Staff participant added",
                                user_id=get_attribute("user_id",
                                                      obj_id=participant_id,
                                                      obj_type="Owner"))
        return participant_id
    elif "subscriber" in resource:
        return add_subscriber(request_id=fields['request_id'],
                              email=fields['follow_email'])
    else:
        return False
示例#4
0
 def __init__(self, request, public):
     self.request = request
     self.id = request.id
     if public:
         self.status = get_status(request, "public")
     else:
         self.requester = get_attribute("alias",
                                        obj_id=get_requester(request.id),
                                        obj_type="User")
         status_arr = get_status(request=request,
                                 audience="city",
                                 include_due_date=True)
         if status_arr:
             self.status, self.due_date = status_arr[0], date(status_arr[1])
         else:
             self.status, self.due_date = None, None
     self.text = request.text
     if len(self.text) > 140:
         self.text = '%s...' % self.text[:140]
     if self.status == "open":
         self.color = "#2688AD"
     elif self.status == "closed":
         self.color = "#2a2b2b"
     elif self.status == "due soon":
         self.color = "#FB991B"
         self.text = '<span style="background-color: %s" class="label label-warning">%s</span> %s' % (
             self.color, self.status, self.text)
     elif self.status == "overdue":
         self.color = "#CA1A1A"
         self.text = '<span style="background-color: %s" class="label label-important">%s</span> %s' % (
             self.color, self.status, self.text)
     else:
         self.color = ""
     self.status_icon = get_status_icon(self.status)
     self.point_of_contact, self.department = get_owner_data(
         request.id, attributes=["alias", "department"])
     if request.department:
         self.department = request.department
     if public:
         self.display_text = "<td class='status' bgcolor='%s'><small><i class='%s'></i></small></td><td>%s</td><td>%s</td><td><a href='/request/%s'><div>%s</div></a></td><td>%s</td><td>%s</td><td style='display:none;'>%s</td>" % (
             self.color, self.status_icon, request.id,
             date(request.date_created), request.id, self.text,
             self.department, self.point_of_contact, request.text)
     else:
         self.display_text = "<td class='status' bgcolor='%s'><small><i class='%s'></i></small></td><td>%s</td><td>%s</td><td><a href='city/request/%s'><div>%s</div></a></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td style='display:none;'>%s</td>" % (
             self.color, self.status_icon, request.id,
             date(request.date_created), request.id, self.text,
             self.department, self.point_of_contact,
             (self.due_date
              or "N/A"), self.requester or "Not given", request.text)
示例#5
0
def assign_owner(request_id, reason, email = None):
	""" Called any time a new owner is assigned. This will overwrite the current owner."""
	req = get_obj("Request", request_id)
	past_owner_id = None
	# If there is already an owner, unassign them:
	if req.point_person():
		past_owner_id = req.point_person().id
		past_owner = get_obj("Owner", req.point_person().id)
		update_obj(attribute = "is_point_person", val = False, obj = past_owner)
	owner_id, is_new_owner = add_staff_participant(request_id = request_id, reason = reason, email = email, is_point_person = True)
	if (past_owner_id == owner_id): # Already the current owner, so don't send any e-mails
		return owner_id

	app.logger.info("\n\nA new owner has been assigned: Owner: %s" % owner_id)
	new_owner = get_obj("Owner", owner_id)
	# Update the associated department on request
	update_obj(attribute = "department_id", val = new_owner.user.department_id, obj = req)
	user_id = get_attribute(attribute = "user_id", obj_id = owner_id, obj_type = "Owner")
	# Send notifications
	if is_new_owner:
		generate_prr_emails(request_id = request_id, notification_type = "Request assigned", user_id = user_id)
	return owner_id
示例#6
0
def add_resource(resource, request_body, current_user_id = None):
	fields = request_body
	if "extension" in resource:
		if not fields.getlist('extend_reason') and not fields.getlist('extend_reasons'):
			return "You must select a reason for the extension."
		return request_extension(int(fields['request_id']), fields.getlist('extend_reason'), current_user_id)
	if "note" in resource:
		return add_note(request_id = int(fields['request_id']), text = fields['note_text'], user_id = current_user_id, passed_spam_filter = True) # Bypass spam filter because they are logged in.
	elif "record" in resource:
		if fields['record_description'] == "":
			return "When uploading a record, please fill out the 'summary' field."
		if 'record_access' in fields and fields['record_access'] != "":
			return add_offline_record(int(fields['request_id']), fields['record_description'], fields['record_access'], current_user_id)
		elif 'link_url' in fields and fields['link_url'] != "":
			return add_link(request_id = int(fields['request_id']), url = fields['link_url'], description = fields['record_description'], user_id = current_user_id)
		# else:
		# 	document = None
		# 	try:
		# 		document = request.files['record']
		# 	except:
		# 		app.logger.info("\n\nNo file passed in")
		# 	return upload_record(request_id = int(fields['request_id']), document = document, description = fields['record_description'], user_id = current_user_id)
	elif "qa" in resource:
		return ask_a_question(request_id = int(fields['request_id']), user_id = current_user_id, question = fields['question_text'])
	elif "owner" in resource:
		participant_id, new = add_staff_participant(request_id = fields['request_id'], email = fields['owner_email'], reason = fields['owner_reason'])
		if new:
			generate_prr_emails(request_id = fields['request_id'], notification_type = "Staff participant added", user_id = get_attribute("user_id", obj_id = participant_id, obj_type = "Owner"))
		return participant_id
	elif "subscriber" in resource:
		return add_subscriber(request_id=fields['request_id'], email = fields['follow_email'])
	else:
		return False