0001-datasource-don-t-fail-if-digests-are-not-defined-557.patch
tests/test_carddef.py | ||
---|---|---|
421 | 421 | |
422 | 422 | |
423 | 423 |
def test_data_source_custom_view_digest(pub): |
424 |
if pub.is_using_postgresql(): |
|
425 |
pub.loggederror_class.wipe() |
|
426 | ||
424 | 427 |
CardDef.wipe() |
425 | 428 |
carddef = CardDef() |
426 | 429 |
carddef.name = 'foo' |
... | ... | |
517 | 520 |
assert len(cards) == 1 |
518 | 521 |
assert cards[0]['text'] == 'Hello Foo Bar' |
519 | 522 | |
523 |
# digests are not defined |
|
524 |
carddef.digest_templates = {} |
|
525 |
carddef.store() |
|
526 |
carddata.id_display = None |
|
527 |
carddata.digests = None |
|
528 |
carddata.store() |
|
529 |
carddata2.id_display = None |
|
530 |
carddata2.digests = None |
|
531 |
carddata2.store() |
|
532 |
carddef.digest_templates = {'custom-view:view': '{{ form_var_foo }} Foo Bar'} |
|
533 |
carddef.store() |
|
534 |
assert [i['text'] for i in CardDef.get_data_source_items('carddef:foo')] == ['', ''] |
|
535 |
assert [i['text'] for i in CardDef.get_data_source_items('carddef:foo:view')] == ['', ''] |
|
536 |
if pub.is_using_postgresql(): |
|
537 |
assert pub.loggederror_class.count() == 2 |
|
538 |
logged_error = pub.loggederror_class.select()[0] |
|
539 |
assert logged_error.summary == 'Digest (default) not defined' |
|
540 |
assert logged_error.formdata_id == str(carddata2.id) |
|
541 |
logged_error = pub.loggederror_class.select()[1] |
|
542 |
assert logged_error.summary == 'Digest (custom view "view") not defined' |
|
543 |
assert logged_error.formdata_id == str(carddata2.id) |
|
544 | ||
520 | 545 | |
521 | 546 |
def test_data_source_query_escape(pub): |
522 | 547 |
CardDef.wipe() |
wcs/carddata.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU General Public License |
15 | 15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
from quixote import get_publisher |
|
18 | ||
17 | 19 |
from wcs.formdata import FormData |
18 | 20 | |
21 |
from .qommon import _ |
|
22 | ||
19 | 23 | |
20 | 24 |
class CardData(FormData): |
21 | 25 |
def get_formdef(self): |
... | ... | |
33 | 37 |
formdef = property(get_formdef) |
34 | 38 | |
35 | 39 |
def get_data_source_structured_item(self, digest_key='default'): |
40 |
if self.digests is None: |
|
41 |
if digest_key == 'default': |
|
42 |
summary = _('Digest (default) not defined') |
|
43 |
else: |
|
44 |
summary = _('Digest (custom view "%s") not defined') % digest_key.replace('custom-view:', '') |
|
45 |
get_publisher().record_error(summary, formdata=self) |
|
46 | ||
36 | 47 |
item = { |
37 | 48 |
'id': self.id, |
38 |
'text': self.digests.get(digest_key),
|
|
49 |
'text': (self.digests or {}).get(digest_key) or '',
|
|
39 | 50 |
} |
40 | 51 |
for field in self.formdef.get_all_fields(): |
41 | 52 |
if not field.varname: |
42 |
- |