def get_uiformatter(collection, tablename, fieldname): from specifyweb.specify.models import Splocalecontaineritem from specifyweb.specify.uiformatters import get_uiformatter if tablename.lower() == "collectionobject" and fieldname.lower( ) == "catalognumber": return get_uiformatter(collection, None, collection.catalognumformatname) try: field_format = Splocalecontaineritem.objects.get( container__discipline=collection.discipline, container__name=tablename.lower(), name=fieldname.lower(), format__isnull=False).format except ObjectDoesNotExist: return None else: return get_uiformatter(collection, None, field_format)
def add_to_query(self, query, objformatter, value=None, op_num=None, negate=False, collection=None, join_cache=None): no_filter = op_num is None if self.tree_rank is None and self.get_field() is None: query, orm_field = objformatter.objformat(query, getattr(models, self.root_table.name), None, join_cache) no_filter = True elif self.is_relationship(): # will be formatting or aggregating related objects if self.get_field().type == 'many-to-one': query, orm_model, table, field = self.build_join(query, self.join_path, join_cache) query, orm_field = objformatter.objformat(query, orm_model, None, join_cache) else: query, orm_model, table, field = self.build_join(query, self.join_path[:-1], join_cache) orm_field = objformatter.aggregate(query, self.get_field(), orm_model, None) else: query, orm_model, table, field = self.build_join(query, self.join_path, join_cache) if self.tree_rank is not None: query, orm_field = handle_tree_field(query, orm_model, table, self.tree_rank, self.tree_field, collection, join_cache) else: orm_field = getattr(orm_model, self.get_field().name) if field.type == "java.sql.Timestamp": # Only consider the date portion of timestamp fields. # This is to replicate the behavior of Sp6. It might # make sense to condition this on whether there is a # time component in the input value. orm_field = sql.func.DATE(orm_field) if field.is_temporal() and self.date_part != "Full Date": orm_field = extract(self.date_part, orm_field) if not no_filter: if isinstance(value, QueryFieldSpec): _, other_field = value.add_to_query(query.reset_joinpoint(), objformatter, join_cache=join_cache) uiformatter = None value = other_field else: uiformatter = field and get_uiformatter(collection, table.name, field.name) value = value op = QueryOps(uiformatter).by_op_num(op_num) f = op(orm_field, value) query = query.filter(sql.not_(f) if negate else f) query = query.reset_joinpoint() return query, orm_field
def get_uiformatter(collection, tablename, fieldname): from specifyweb.specify.models import Splocalecontaineritem from specifyweb.specify.uiformatters import get_uiformatter try: field_format = Splocalecontaineritem.objects.get( container__discipline=collection.discipline, container__name=tablename.lower(), name=fieldname.lower(), format__isnull=False).format except ObjectDoesNotExist: return None else: return get_uiformatter(collection, None, field_format)
def add_to_query(self, query, value=None, op_num=None, negate=False, formatter=None, formatauditobjs=False): no_filter = op_num is None #print "############################################################################" #print "formatauditobjs " + str(formatauditobjs) #if self.get_field() is not None: # print "field name " + self.get_field().name #print "is auditlog obj format field = " + str(self.is_auditlog_obj_format_field(formatauditobjs)) #print "############################################################################" if self.tree_rank is None and self.get_field() is None: query, orm_field = query.objectformatter.objformat( query, getattr(models, self.root_table.name), None) no_filter = True elif self.is_relationship(): # will be formatting or aggregating related objects if self.get_field().type == 'many-to-one': query, orm_model, table, field = self.build_join( query, self.join_path) query, orm_field = query.objectformatter.objformat( query, orm_model, formatter) else: query, orm_model, table, field = self.build_join( query, self.join_path[:-1]) orm_field = query.objectformatter.aggregate( query, self.get_field(), orm_model, formatter) else: query, orm_model, table, field = self.build_join( query, self.join_path) if self.tree_rank is not None: query, orm_field = query.handle_tree_field( orm_model, table, self.tree_rank, self.tree_field) else: orm_field = getattr(orm_model, self.get_field().name) if field.type == "java.sql.Timestamp": # Only consider the date portion of timestamp fields. # This is to replicate the behavior of Sp6. It might # make sense to condition this on whether there is a # time component in the input value. orm_field = sql.func.DATE(orm_field) if field.is_temporal() and self.date_part != "Full Date": orm_field = sql.extract(self.date_part, orm_field) if not no_filter: if isinstance(value, QueryFieldSpec): _, other_field = value.add_to_query(query.reset_joinpoint()) uiformatter = None value = other_field else: uiformatter = field and get_uiformatter( query.collection, table.name, field.name) value = value op = QueryOps(uiformatter).by_op_num(op_num) f = op(orm_field, value) query = query.filter(sql.not_(f) if negate else f) query = query.reset_joinpoint() return query, orm_field