def set_dynamic_field(self, field_definition_id): oac = g_helper.get_org_access_control() dyn_data = oac.dynamic_field_data(self.Field.dynamic_field_definition_field_id, field_definition_id) for field, value in dyn_data: if hasattr(self.Field, field): setattr(self.Field, field, value)
def get_row(facility_name, table_name): criteria = request.json['criteria'] fields = request.json['fields'] oac = g_helper.get_org_access_control() row = oac.get_row(table_name, criteria) price = None ret = {} if row: for field in fields: ret[field] = str(getattr(row, field)) return json.dumps(ret)
def get_results(self): """ calls several class functions and returns results """ self.fc.set_fk_fields() results = [] self.criteria = self.add_table_query_criteria(self.criteria) self.oac = g_helper.get_org_access_control() self.results = self.oac.get_table_query_data( self.fc.fields, self.criteria ) return self.results
def __init__ (self, from_date, to_date, items, order, service_prefix, service_type_id): self.items = self.populate_items(items) self.from_date = from_date self.to_date = to_date self.order = order self.service_prefix = service_prefix self.service_type_id = service_type_id self.org_name = self.items[0].Organization.name self.org_id = self.items[0].Organization.id self.charge_method_type = self.items[0].ChargeMethodType.name # set by set_invoice self.id = None self.last_modified = None self.name = None self.Invoice = None self.number = None self.oac = g_helper.get_org_access_control() # set in total_items self.orders = self.group_by('Order', 'id') self.get_charge_method() self.users = self.group_by('User', 'id') self.total = self.set_total() # below are for the template self.facility_title = 'Harvard University Sequencing Facility' self.from_address = [ 'FAS Division of Science', 'Northwest Lab Room B227.30', '52 Oxford Street', 'Cambridge, MA 02138' ] self.core_prefix = { 'bauer': 'SC', 'helium': 'HU' } self.pdf_prefix = ( self.service_prefix.upper() + 'IG' # iggybase prefix + self.get_organization_type_prefix() + '-' + str(self.from_date.year)[2:4] + '{:02d}'.format(self.from_date.month) + '-' + util.zero_pad(self.order, 2) )
def __init__ (self, year = None, month = None, org_list = []): # default to last month last_month = util.get_last_month() if not year: year = last_month.year if not month: month = last_month.month self.month = month self.year = year self.org_list = org_list self.from_date, self.to_date = util.start_and_end_month(self.year, self.month) # create invoice objects self.oac = g_helper.get_org_access_control() self.invoices = self.get_invoices(self.from_date, self.to_date, self.org_list) self.set_invoices() # creates invoice rows in DB
def __init__(self, table_name, instance_name = None, depth = 2): self.role_access_control = g_helper.get_role_access_control() self.organization_access_control = g_helper.get_org_access_control() self.table_name = table_name self.tables = OrderedDict() self.fields = {} self.instances = {} self.instance_names = {} self.get_tables(depth) self.instance_counter = 0 if self.tables[table_name]['table_meta_data'] is None: abort(403) self.instance_id = None self.instance_name = None if instance_name is not None: self.get_data(instance_name)
def build_summary_ajax(table_name, criteria = {}): start = time.time() route = util.get_path(util.ROUTE) # TODO: we don't want oac instantiated multiple times oac = g_helper.get_org_access_control() ret = None filters = util.get_filters() key = current_app.cache.make_key( route, g.rac.role.id, oac.current_org_id, table_name ) if (not criteria and 'no_cache' not in filters): print('checking cache') ret = current_app.cache.get(key) ret = None if not ret: print('cache miss') tqc = TableQueryCollection(table_name, criteria) current = time.time() print(str(current - start)) tqc.get_results() current = time.time() print(str(current - start)) tqc.format_results() current = time.time() print(str(current - start)) table_query = tqc.get_first() current = time.time() print(str(current - start)) json_rows = table_query.get_row_list() current = time.time() print(str(current - start)) ret = jsonify({'data': json_rows}) if not criteria: print('caching') current_app.cache.set(key, ret, (24 * 60 * 60), [table_name]) else: print('cache hit') return ret
def __init__ (self, work_item_group_name, workflow_name, show_step = None): self.name = work_item_group_name # can be new self.rac = g_helper.get_role_access_control() self.oac = g_helper.get_org_access_control() self.workflow = Workflow(workflow_name) # sql alchemy results will populate these capitalized vars self.WorkItemGroup = None self.work_items = {} self.parent_work_item = None self.get_work_item_group() # which step is the wig currently on self.step = self.get_step() self.step_num = self.step.Step.order # which step is requested for show if show_step and show_step != self.step_num: self.show_step_num = int(show_step) self.step = self.get_step(show_step) else: self.show_step_num = self.step_num # set the url for current step self.endpoint = self.step.Module.name + '.' + self.step.Route.url_path self.dynamic_params = self.set_dynamic_params() self.url = self.workflow.get_step_url(self.show_step_num, self.name) # default set on init, actions can change this self.next_step = self.show_step_num + 1 # not all steps are necessary depending on items self.active_steps = self.get_active_steps(self.workflow.steps) self.buttons = [] self.saved_rows = {} # do before step actions, if current step if self.show_step_num == self.step_num: self.do_step_actions(timing.BEFORE)
def __init__ (self, year = None, month = None, org_list = [], invoiced = False): # default to last month last_month = util.get_last_month() if not year: year = last_month.year if not month: month = last_month.month self.month = month self.year = year self.org_list = org_list self.invoiced = invoiced self.from_date, self.to_date = util.start_and_end_month(self.year, self.month) self.reports = OrderedDict() self.oac = g_helper.get_org_access_control() self.line_items = self.oac.get_line_items(self.from_date, self.to_date, self.org_list, self.invoiced)
def search_results(self): oac = g_helper.get_org_access_control() input_id = self.search_vals['input_id'] table_name = self.search_vals['table_name'] display_name = self.search_vals['display_name'] modal_open = self.search_vals['modal_open'] search_value = self.search_vals['value'] # logging.info('input_id: ' + str(input_id)) # logging.info('table_name: ' + str(table_name)) # logging.info('display_name: ' + str(display_name)) # logging.info('modal_open: ' + str(modal_open)) search_params = {} fields = ['name'] for key, value in self.search_vals.items(): if key[:7] == 'search_': field_name = key[7:] if field_name != 'name' and field_name != 'by_field': fields.append(field_name) if value != '': search_params[field_name] = value # logging.info('search_params: ') # logging.info(search_params) criteria = {'display_name': display_name} fc = FieldCollection(None, table_name, criteria) fc.set_fk_fields() search_table = fc.fields[table_name + "|" + display_name].FK_TableObject.name search_fc = FieldCollection(None, search_table) for row in search_fc.get_search_fields(): if row.Field.display_name not in fields: fields.append(row.Field.display_name) search_ids = {} for table_field_name, search_field in search_fc.fields.items(): search_ids[search_field.Field.id] = search_field.Field.display_name search_field = fc.fields[table_name + "|" + display_name].Field.foreign_key_display if search_field: search_field = search_ids[search_field] else: search_field = 'name' if search_field not in fields: fields.append(search_field) if 'by_field' in self.search_vals and search_value != '': search_params = {search_field: search_value} # logging.info('search_table: ' + search_table) # logging.info('search_field: ' + str(search_field)) # logging.info('final search_params: ') # logging.info(search_params) search_results = oac.get_search_results(search_table, search_params) modal_html = '<table class="table-sm table-striped"><tr>' for field in fields: modal_html += '<th>' + field.replace("_", " ").title() + '</th>' modal_html += '</tr>' results = [] if search_results is not None and len(search_params) != 0: for row in search_results: modal_html += '<tr>' for field in fields: res = getattr(row, field) if field == search_field: results.append([1, format(res), row.id]) modal_html += ('<td><input luid="' + input_id + '"class="search-results" type="button" ' + 'val_id="' + str(row.id) + '" value="' + format(res) + '"></input></td>') else: if res is not None: modal_html += '<td><label>' + format(res) + '</label></td>' else: modal_html += '<td></td>' modal_html += '</tr>' else: modal_html += '<tr><td><label>No Results Found</label></td></tr>' modal_html += '</table>' # logging.info(modal_html) # logging.info(results) if len(results) == 1 and not modal_open: return json.dumps(results[0]) else: return json.dumps(modal_html)