def search(self): #names self.set('entity', self.request.params.get('entity','')) self.set('escaped_entity', self.request.params.get('entity','').replace('"','\\"').replace("'","\\'")) self.set('firstname', self.request.params.get('firstname','')) self.set('escaped_firstname', self.request.params.get('firstname','').replace('"','\\"').replace("'","\\'")) self.set('keywords', self.request.params.get('keywords','')) self.set('escaped_keywords', self.request.params.get('keywords','').replace('"','\\"').replace("'","\\'")) self.set('mode', self.request.params.get('mode',False)) #dates self.set('start_date', int(self.request.params.get('start_date', 0))) self.set('end_date', int(self.request.params.get('end_date', datetime.datetime.today().year))) sd = DBSession.query(Cases).filter(Cases.year > 1800).order_by('year asc').first() if sd: self.set('earliest_recorded_date', sd.year) else: self.set('earliest_recorded_date', 1800) ed = DBSession.query(Cases).filter(Cases.year < datetime.datetime.today().year).order_by('year desc').first() if ed: self.set('last_recorded_date', ed.year) else: self.set('last_recorded_date', datetime.datetime.today().year) #types actiontypes = [ int(at) for at in self.request.params.getall('actiontypes') ] self.set('actiontypes', actiontypes) self.set('actiontypes_list', ActionTypes.loadAll(order='actiontype asc')) #counties counties = [ int(at) for at in self.request.params.getall('counties') ] self.set('counties', counties) self.set('counties_list', Counties.loadAll(order='county asc')) #roles roles = [ int(r) for r in self.request.params.getall('roles') ] self.set('roles', roles) self.set('roles_list', Roles.loadAll(order='role asc')) #archives archives = [ int(l) for l in self.request.params.getall('archives') ] self.set('archives', archives) self.set('archives_list', Archives.loadAll(order='name asc')) #courts courts = [ int(l) for l in self.request.params.getall('courts') ] self.set('courts', courts) self.set('courts_list', Courts.loadAll(order='court asc')) return self.response
def make_facets(self,query): facets = [] # ActionTypes Facets if Validators.bool( Config.get('enable_facet_casetypes', purify=True) ): actiontypes = ActionTypes.loadAll(order='actiontype asc'); _types = {'name' : 'actiontypes' , 'clean_name': 'Case Types', 'data' :[]}; for at in actiontypes: subquery = query.filter(Cases.actiontype==at.id) _types['data'].append({'facet':at.actiontype, 'id': at.id, 'count':self.fast_count(subquery)}) facets.append(_types) # County Facets if Validators.bool( Config.get('enable_facet_counties', purify=True) ): counties = Counties.loadAll(order='county asc'); _counties = {'name' : 'counties' , 'clean_name': 'Counties', 'data' :[]}; for county in counties: subquery = query.filter(Cases.county==county.id) _counties['data'].append({'facet':county.county, 'id': county.id, 'count':self.fast_count(subquery)}) facets.append(_counties) # Roles Facets if Validators.bool( Config.get('enable_facet_roles', purify=True) ): roles = Roles.loadAll(order='role asc'); _roles = {'name' : 'roles' , 'clean_name': 'Roles', 'data' :[]}; for role in roles: subquery = query.filter(Entities.role==role.id) _roles['data'].append({'facet':role.role, 'id': role.id, 'count':self.fast_count(subquery)}) facets.append(_roles) # Courts Facets if Validators.bool( Config.get('enable_facet_courts', purify=True) ): courts = Courts.loadAll(order='court asc'); _court = {'name' : 'courts' , 'clean_name': 'Courts', 'data' :[]}; for court in courts: subquery = query.filter(Cases.court==court.id) _court['data'].append({'facet':court.court, 'id': court.id, 'count':self.fast_count(subquery)}) facets.append(_court) # Archive Facets if Validators.bool( Config.get('enable_facet_archives', purify=True) ): archives = Archives.loadAll(order='name asc'); _archives = {'name' : 'archives' , 'clean_name': 'Archives', 'data' :[]}; for archive in archives: subquery = query.filter(Cases.archive==archive.id) _archives['data'].append({'facet':archive.name, 'id': archive.id, 'count':self.fast_count(subquery)}) facets.append(_archives) return facets
def manage_importer(self): # Do one look up for speed self.roles = Results2Dict(Roles.loadAll()) self.counties = Results2Dict(Counties.loadAll()) self.courts = Results2Dict(Courts.loadAll()) self.callnumbers = Results2Dict(CallNumbers.loadAll()) self.containers = Results2Dict(Containers.loadAll(order="container asc")) self.actiontypes = Results2Dict(ActionTypes.loadAll()) self.suffixs = Results2Dict(Suffixs.loadAll()) self.prefixs = Results2Dict(Prefixs.loadAll()) if "submit" in self.request.params: # case_override = json.loads(self.request.params.get('case.override','{}')) # entity_override = json.loads(self.request.params.get('entity.override','{}')) entities = self.request.POST["entities"].file entities_fields = self.request.params.get("entity.fields").split(",") cases = self.request.POST["cases"].file case_fields = self.request.params.get("case.fields").split(",") archive_id = self.request.params.get("archive", 0) print "CREATING CASES --------------" cases_id_map = self.createCases_returnMap(cases, case_fields, archive_id) print "CREATING ENTITIES ----------------" fix = self.request.params.get("firstname.fix", "0") == "1" self.createEntitiesCleanup(entities, entities_fields, cases_id_map, fix) # else: # self.createEntities(entities,entities_fields,cases_id_map) self.set("archives", Archives.loadAll(order="name asc")) self.set("containers", self.containers) self.set("callnumbers", self.callnumbers) return self.response
def manage_records(self): case_id = self.request.matchdict['case_id'] if case_id != 'new': case_id = int(case_id) # Add last entry for new entries self.set('lastentry',case_id) lastcase = Cases.load(order='id desc') if lastcase: self.set('lastentry',lastcase.id) # Handle Saving if 'edit.Form.submit.save' in self.request.params or 'edit.Form.submit.savenext' in self.request.params: self._save(case_id) if 'edit.Form.submit.savenext' in self.request.params: return HTTPFound(location=route_url('manage_records', self.request, case_id='new')) return HTTPFound(location=route_url('manage_records', self.request, case_id=case_id)) # Handle Loading Information on screen if case_id == 'new' or case_id == 0: case = None else: case = DBSession.query(Cases,Counties,ActionTypes,Archives).filter(Cases.id == case_id) \ .filter(Cases.actiontype == ActionTypes.id) \ .filter(Cases.county == Counties.id) \ .filter(Cases.archive == Archives.id) \ .first() entities = [] if case_id != 'new': entities = DBSession.query(Entities,Roles).filter(Entities.case_id == case_id) \ .filter(Entities.role == Roles.id) \ .order_by('entity asc').all() self.set('case',case) self.set('year',self._get_year) self.set('case_id',case_id) self.set('entities',entities) self.set('actiontypes',ActionTypes.loadAll(order="actiontype asc")) self.set('containers',Containers.loadAll(order="container asc")) self.set('courts',Courts.loadAll(order="court asc")) self.set('call_numbers',CallNumbers.loadAll(order="call_number asc")) self.set('archives',Archives.loadAll(order="name asc")) self.set('roles',Roles.loadAll(order="role asc")) self.set('counties',Counties.loadAll(order="county asc")) self.set('prefixs',Prefixs.loadAll(order="prefix asc")) self.set('suffixs',Suffixs.loadAll(order="suffix asc")) #${request.application_url}/manage/data/Entities/delete/${entity.Entities.id}?back=${request.url} delete_url = '' if case: entity_base_url = self.request.application_url + '/manage/data/Entities/delete/' case_base_url = self.request.application_url + '/manage/data/Cases/delete/' delete_url = case_base_url + str(case.Cases.id) + '?back=' for e in entities: delete_url += entity_base_url + str(e.Entities.id) + '?back=' delete_url += self.request.application_url + '/manage/cases' # Back to base self.set('delete_url', delete_url) return self.response