class CaseSearchConfigJSON(jsonobject.JsonObject): fuzzy_properties = jsonobject.ListProperty(FuzzyProperties) def add_fuzzy_property(self, case_type, property): self.add_fuzzy_properties(case_type, [property]) def add_fuzzy_properties(self, case_type, properties): for prop in self.fuzzy_properties: if prop.case_type == case_type: prop.properties = list(set(prop.properties) | set(properties)) return self.fuzzy_properties = self.fuzzy_properties + [ FuzzyProperties(case_type=case_type, properties=properties) ] def remove_fuzzy_property(self, case_type, property): for prop in self.fuzzy_properties: if prop.case_type == case_type and property in prop.properties: prop.properties = list(set(prop.properties) - set([property])) return raise AttributeError("{} is not a fuzzy property for {}".format( property, case_type)) def get_fuzzy_properties_for_case_type(self, case_type): """ Returns a list of search properties to be fuzzy searched """ for prop in self.fuzzy_properties: if prop.case_type == case_type: return prop.properties return []
class AggregationSpec(jsonobject.JsonObject): domain = jsonobject.StringProperty(required=True) table_id = jsonobject.StringProperty(required=True) display_name = jsonobject.StringProperty() primary_table = jsonobject.ObjectProperty(PrimaryTableSpec) time_aggregation = jsonobject.ObjectProperty(TimeAggregationConfigSpec) secondary_tables = jsonobject.ListProperty(SecondaryTableSpec)
class FieldSpec(jsonobject.StrictJsonObject): field = jsonobject.StringProperty() description = jsonobject.StringProperty() show_in_menu = jsonobject.BooleanProperty(default=False) discoverable = jsonobject.BooleanProperty(default=True) values_hints = jsonobject.ListProperty() deprecated = jsonobject.BooleanProperty(default=False)
class TaskStatusResultError(jsonobject.StrictJsonObject): title = jsonobject.StringProperty() description = jsonobject.StringProperty() column = jsonobject.StringProperty() # usually an int, but field has been hijacked to include other debug info # search 'row_number=' in tasks.py # longer-term solution would be to have another field for debug info rows = jsonobject.ListProperty()
class StockReportHelper(jsonobject.JsonObject): """ Intermediate class for dealing with stock XML """ domain = jsonobject.StringProperty() form_id = jsonobject.StringProperty() timestamp = jsonobject.DateTimeProperty() tag = jsonobject.StringProperty() transactions = jsonobject.ListProperty(lambda: StockTransactionHelper) server_date = jsonobject.DateTimeProperty() deprecated = jsonobject.BooleanProperty() @property def report_type(self): # this is for callers to be able to use a less confusing name return self.tag @classmethod def make_from_form(cls, form, timestamp, tag, transactions): deprecated = form.is_deprecated return cls( domain=form.domain, form_id=form.form_id if not deprecated else form.orig_id, timestamp=timestamp, tag=tag, transactions=transactions, server_date=form.received_on, deprecated=deprecated, ) def validate(self): """ Validates this object as best we can and raises Exceptions if we find anything invalid . """ if any(transaction_helper.product_id in ('', None) for transaction_helper in self.transactions): raise MissingProductId( _('Product IDs must be set for all ledger updates!'))
class FuzzyProperties(jsonobject.JsonObject): case_type = jsonobject.StringProperty() properties = jsonobject.ListProperty(unicode)
class AppInfo(jsonobject.JsonObject): id = jsonobject.StringProperty() names = jsonobject.StringProperty() langs = jsonobject.ListProperty(unicode)
class TaskStatusResult(jsonobject.StrictJsonObject): match_count = jsonobject.IntegerProperty() created_count = jsonobject.IntegerProperty() too_many_matches = jsonobject.IntegerProperty() num_chunks = jsonobject.IntegerProperty() errors = jsonobject.ListProperty(lambda: TaskStatusResultError)
class SecondaryTableSpec(jsonobject.JsonObject): data_source_id = jsonobject.StringProperty(required=True) join_column_primary = jsonobject.StringProperty(required=True) join_column_secondary = jsonobject.StringProperty(required=True) time_window_column = jsonobject.StringProperty() columns = jsonobject.ListProperty(SecondaryColumnSpec)
class PrimaryTableSpec(jsonobject.JsonObject): data_source_id = jsonobject.StringProperty(required=True) key_column = jsonobject.StringProperty(required=True, default='doc_id') columns = jsonobject.ListProperty(PrimaryColumnSpec)
class AppInfo(jsonobject.JsonObject): id = jsonobject.StringProperty() names = jsonobject.StringProperty() langs = jsonobject.ListProperty(six.text_type)