97 |
97 |
return bool(obj._distance < distance)
|
98 |
98 |
return self._clone(self._criterias + [distance_check])
|
99 |
99 |
|
|
100 |
def apply_partial_filter(self, value):
|
|
101 |
assert self.pending_attr
|
|
102 |
for field in self._formdef.fields:
|
|
103 |
if getattr(field, 'varname', None) == self.pending_attr:
|
|
104 |
from wcs import sql
|
|
105 |
criteria = Equal(sql.get_field_id(field), value)
|
|
106 |
break
|
|
107 |
else:
|
|
108 |
raise Exception('invalid filter')
|
|
109 |
return self._clone(self._criterias + [criteria])
|
|
110 |
|
100 |
111 |
def __getattr__(self, attribute):
|
101 |
|
# backward compatibility
|
102 |
112 |
if attribute.startswith('count_status_'):
|
|
113 |
# backward compatibility
|
103 |
114 |
status = attribute[len('count_status_'):]
|
104 |
115 |
return len(self._formdef.data_class().get_ids_with_indexed_value(
|
105 |
116 |
'status', 'wf-%s' % status))
|
|
117 |
if attribute.startswith('filter_by_'):
|
|
118 |
# filter by attribute
|
|
119 |
qs = self._clone(self._criterias)
|
|
120 |
qs.pending_attr = attribute[len('filter_by_'):]
|
|
121 |
return qs
|
106 |
122 |
if attribute == 'formdef':
|
107 |
123 |
warnings.warn('Deprecated access to formdef', DeprecationWarning)
|
108 |
124 |
return self._formdef
|
... | ... | |
430 |
446 |
# this gets used to generate an email attachment :/
|
431 |
447 |
return self._formdata.export_to_json(include_files=include_files)
|
432 |
448 |
|
|
449 |
def get(self, key):
|
|
450 |
# compatibility with |get filter, to return a field by varname
|
|
451 |
return getattr(self.var, key, None)
|
|
452 |
|
433 |
453 |
def __getitem__(self, key):
|
434 |
454 |
try:
|
435 |
455 |
return getattr(self, key)
|
... | ... | |
867 |
887 |
field.id = field.varname or field.id
|
868 |
888 |
data = self._formdef.workflow_options
|
869 |
889 |
super(LazyFormDefOptions, self).__init__(fields, data)
|
|
890 |
|
|
891 |
|
|
892 |
class CardsSource:
|
|
893 |
@classmethod
|
|
894 |
def get_substitution_variables(cls):
|
|
895 |
return {'cards': cls()}
|
|
896 |
|
|
897 |
def __getattr__(self, attr):
|
|
898 |
from wcs.carddef import CardDef
|
|
899 |
return LazyFormDef(CardDef.get_by_urlname(attr))
|
870 |
|
-
|