def createEntitiesCleanup(self, file, fields, cases_map, fix): reader = csv.reader(file, skipinitialspace=True, delimiter=b",", quoting=csv.QUOTE_MINIMAL, quotechar=b'"') for line in reader: row = {} for f, d in zip(fields, line): c = d.strip() if f == "case_id": if c == "": row[f] = 0 else: row[f] = cases_map[int(c)] elif str(f) == "role": row["role"] = FindInList(self.roles, "role", c, default={"id": 1, "role": ""})["id"] elif str(f) == "prefix": row["prefix"] = FindInList(self.prefixs, "prefix", c, default={"id": 1, "prefix": ""})["id"] elif str(f) == "suffix": row["suffix"] = FindInList(self.suffixs, "suffix", c, default={"id": 1, "suffix": ""})["id"] else: row[f] = c.replace("\n", "").replace("\r", "").replace('"', "").strip() row["import_file"] = self.request.params.get("import.marker", "not provided") if fix: self._fix_firstname_issues_and_insert(row) else: entities = Entities(**row) lastid = entities.insert(self.request) print "Uploaded Entity ID: " + str(lastid)
def _fix_firstname_issues_and_insert(self, row): firstname = row["firstname"].replace(" and ", "|") firstname = firstname.replace(" & ", "|") firstname = firstname.replace(", ", "|") entities = firstname.split("|") for e in entities: p, f, m, s = self._fix_firstnames(e) row["firstname"] = f row["middlename"] = m row["prefix"] = FindInList(self.prefixs, "prefix", p, default={"id": 1, "prefix": ""})["id"] row["suffix"] = FindInList(self.suffixs, "suffix", s, default={"id": 1, "suffix": ""})["id"] entities = Entities(**row) lastid = entities.insert(self.request) print "Uploaded 'CLEANED' Entity ID: " + str(lastid)
def get_location(cls,entity=None,case=None): from courtrecords.models import Entities, Cases id = 0 if entity: e = Entities.load(id=entity) case = e.case_id if case: c = Cases.load(id=case) id = c.archive if id: return Archives.load(id=id) return None
def get_other_entities(self,entity): entities = Entities.loadAll(case_id=entity.case_id) return filter(lambda x: x['id'] != entity.id, Results2Dict(entities))
def create_invoice(self): records = self.request.params.getall('records') if records: fullname = self.request.params.get('customer.name','') email = self.request.params.get('customer.email','') address = self.request.params.get('customer.address','') address2 = self.request.params.get('customer.address2','') phone = self.request.params.get('customer.phone','') agreement = Validators.bool(self.request.params.get('customer.agreement',0)) checkout = self.request.params.getall('customer.checkout') deliver_digitally = False deliver_physically = False # Delivery Options for option in checkout: if option == 'digitally': deliver_digitally = True if option == 'physically': deliver_physically = True # Prep Orders orders = [] total_price = 0.0 location_emails = {} # to notify any locations a request has been made for record in records: c = Cases.load(id=int(record)) e = Entities.load(case_id=int(record)) r = Roles.load(id=e.role) l = Archives.load(id=c.archive) location_emails[l.email] = l.email total_price += float(r.price) orders.append({'case':int(c.id), 'price' : r.price, 'location':int(l.id)}) invoice = Invoices(fullname=fullname, email=email, address=address, county_state_zip=address2, phone=phone, records=orders, agreement_accepted=agreement, deliver_digitally=deliver_digitally, deliver_physically=deliver_physically, total_price='${:,.2f}'.format(total_price)) invoice.insert(self.request) invoice = Invoices.load(order='id desc') #Email Client starting_status = Statuses.load(order='priority asc') Emailer.send(self.request, [email], starting_status.email_subject, starting_status.email_message, link=self.request.application_url + '/invoice/' + invoice.hash ) #Email Archives Involved Emailer.send(self.request, list(location_emails), 'Order request has been placed', 'A new order request has been placed', link=self.request.application_url + '/login?goto=' + self.request.application_url + '/manage/orders' ) response = HTTPFound(location=route_url('invoice', self.request, hash=invoice.hash)) response.delete_cookie('basket') return response else: return self.response
def _save(self, case_id): entities, new_entities = {}, {} cases, new_cases = {}, {} for k,v in self.request.params.items(): action, table, attr, id = k.split('.') if action == 'edit': if table == 'Entities': if id not in entities: entities[id] = { attr : v } else: entities[id][attr] = v if table == 'Cases': if id not in cases: cases[id] = { attr : v } else: cases[id][attr] = v if action == 'new': if table == 'Entities': if id not in new_entities: new_entities[id] = { attr : v } else: new_entities[id][attr] = v if table == 'Cases': if id not in new_cases: new_cases[id] = { attr : v } else: new_cases[id][attr] = v #new_cases[id]['year'] = self._determine_year # save new cases for k,v in new_cases.items(): case = Cases() for attr,value in v.items(): setattr(case,attr,value) case.year = self._determine_year(case.year_text)[0] case_id = case.insert(self.request) # save new entities for k,v in new_entities.items(): entity = Entities() for attr,value in v.items(): setattr(entity,attr,value) entity.case_id = case_id entity.insert(self.request) # save existing cases for k,v in cases.items(): case = Cases.load(id=k) for attr,value in v.items(): setattr(case,attr,value) case.year = self._determine_year(case.year_text)[0] case.save(self.request) # save existing entities for k,v in entities.items(): entity = Entities.load(id=k) for attr,value in v.items(): setattr(entity,attr,value) entity.save(self.request)