<commit_before>from public_records_portal import models
from models import Note, QA
from db_helpers import get_obj, get_owner_data, get_requester, get_attribute
from helpers import *

class RequestTablePresenter:
	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.department = get_dept_by_request(request)
		self.point_of_contact = get_owner_data(request.id, attributes = ["alias"])[0]
		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)
			

<commit_msg>Reduce amount of queries used<commit_after>from public_records_portal import models
from models import Note, QA
from db_helpers import get_obj, get_owner_data, get_requester, get_attribute
from helpers import *

class RequestTablePresenter:
	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)
			


{'fraction_non_alphanumeric': 0.19172113289760348, 'fraction_numerical': 0.008932461873638345, 'mean_word_length': 5.145917001338688, 'pattern_counts': {'":': 8, '<': 99, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2265586', 'n_tokens_mistral': 1795, 'n_tokens_neox': 1677, 'n_words': 312}