22 from logilab.common.debugger import Debugger |
22 from logilab.common.debugger import Debugger |
23 from logilab.common.umessage import message_from_string |
23 from logilab.common.umessage import message_from_string |
24 from logilab.common.decorators import cached, classproperty, clear_cache |
24 from logilab.common.decorators import cached, classproperty, clear_cache |
25 from logilab.common.deprecation import deprecated |
25 from logilab.common.deprecation import deprecated |
26 |
26 |
27 from cubicweb import NoSelectableObject, AuthenticationError |
27 from cubicweb import ValidationError, NoSelectableObject, AuthenticationError |
28 from cubicweb import cwconfig, devtools, web, server |
28 from cubicweb import cwconfig, devtools, web, server |
29 from cubicweb.dbapi import repo_connect, ConnectionProperties, ProgrammingError |
29 from cubicweb.dbapi import repo_connect, ConnectionProperties, ProgrammingError |
30 from cubicweb.sobjects import notification |
30 from cubicweb.sobjects import notification |
31 from cubicweb.web import Redirect, application |
31 from cubicweb.web import Redirect, application |
32 from cubicweb.devtools import SYSTEM_ENTITIES, SYSTEM_RELATIONS, VIEW_VALIDATORS |
32 from cubicweb.devtools import SYSTEM_ENTITIES, SYSTEM_RELATIONS, VIEW_VALIDATORS |
671 def _check_html(self, output, view, template='main-template'): |
671 def _check_html(self, output, view, template='main-template'): |
672 """raises an exception if the HTML is invalid""" |
672 """raises an exception if the HTML is invalid""" |
673 try: |
673 try: |
674 validatorclass = self.vid_validators[view.__regid__] |
674 validatorclass = self.vid_validators[view.__regid__] |
675 except KeyError: |
675 except KeyError: |
676 if template is None: |
676 if view.content_type in ('text/html', 'application/xhtml+xml'): |
677 default_validator = htmlparser.HTMLValidator |
677 if template is None: |
|
678 default_validator = htmlparser.HTMLValidator |
|
679 else: |
|
680 default_validator = htmlparser.DTDValidator |
678 else: |
681 else: |
679 default_validator = htmlparser.DTDValidator |
682 default_validator = None |
680 validatorclass = self.content_type_validators.get(view.content_type, |
683 validatorclass = self.content_type_validators.get(view.content_type, |
681 default_validator) |
684 default_validator) |
682 if validatorclass is None: |
685 if validatorclass is None: |
683 return None |
686 return None |
684 validator = validatorclass() |
687 validator = validatorclass() |
777 edict = {} |
780 edict = {} |
778 for etype in unprotected_entities(self.schema, strict=True): |
781 for etype in unprotected_entities(self.schema, strict=True): |
779 rset = cu.execute('%s X' % etype) |
782 rset = cu.execute('%s X' % etype) |
780 edict[str(etype)] = set(row[0] for row in rset.rows) |
783 edict[str(etype)] = set(row[0] for row in rset.rows) |
781 existingrels = {} |
784 existingrels = {} |
782 ignored_relations = SYSTEM_RELATIONS | self.ignored_relations |
785 ignored_relations = SYSTEM_RELATIONS + self.ignored_relations |
783 for rschema in self.schema.relations(): |
786 for rschema in self.schema.relations(): |
784 if rschema.final or rschema in ignored_relations: |
787 if rschema.final or rschema in ignored_relations: |
785 continue |
788 continue |
786 rset = cu.execute('DISTINCT Any X,Y WHERE X %s Y' % rschema) |
789 rset = cu.execute('DISTINCT Any X,Y WHERE X %s Y' % rschema) |
787 existingrels.setdefault(rschema.type, set()).update((x, y) for x, y in rset) |
790 existingrels.setdefault(rschema.type, set()).update((x, y) for x, y in rset) |
788 q = make_relations_queries(self.schema, edict, cu, ignored_relations, |
791 q = make_relations_queries(self.schema, edict, cu, ignored_relations, |
789 existingrels=existingrels) |
792 existingrels=existingrels) |
790 for rql, args in q: |
793 for rql, args in q: |
791 cu.execute(rql, args) |
794 try: |
|
795 cu.execute(rql, args) |
|
796 except ValidationError, ex: |
|
797 # failed to satisfy some constraint |
|
798 print 'error in automatic db population', ex |
792 self.post_populate(cu) |
799 self.post_populate(cu) |
793 self.commit() |
800 self.commit() |
794 |
801 |
795 def iter_individual_rsets(self, etypes=None, limit=None): |
802 def iter_individual_rsets(self, etypes=None, limit=None): |
796 etypes = etypes or self.to_test_etypes() |
803 etypes = etypes or self.to_test_etypes() |