42 from cubicweb import (ValidationError, NoSelectableObject, AuthenticationError, |
42 from cubicweb import (ValidationError, NoSelectableObject, AuthenticationError, |
43 ProgrammingError, BadConnectionId) |
43 ProgrammingError, BadConnectionId) |
44 from cubicweb import cwconfig, devtools, web, server, repoapi |
44 from cubicweb import cwconfig, devtools, web, server, repoapi |
45 from cubicweb.utils import json |
45 from cubicweb.utils import json |
46 from cubicweb.sobjects import notification |
46 from cubicweb.sobjects import notification |
47 from cubicweb.web import Redirect, application |
47 from cubicweb.web import Redirect, application, eid_param |
48 from cubicweb.server.hook import SendMailOp |
48 from cubicweb.server.hook import SendMailOp |
49 from cubicweb.server.session import Session |
49 from cubicweb.server.session import Session |
50 from cubicweb.devtools import SYSTEM_ENTITIES, SYSTEM_RELATIONS, VIEW_VALIDATORS |
50 from cubicweb.devtools import SYSTEM_ENTITIES, SYSTEM_RELATIONS, VIEW_VALIDATORS |
51 from cubicweb.devtools import fake, htmlparser, DEFAULT_EMPTY_DB_ID |
51 from cubicweb.devtools import fake, htmlparser, DEFAULT_EMPTY_DB_ID |
52 from cubicweb.utils import json |
52 from cubicweb.utils import json |
883 req.cnx.commit() |
883 req.cnx.commit() |
884 except web.Redirect: |
884 except web.Redirect: |
885 req.cnx.commit() |
885 req.cnx.commit() |
886 raise |
886 raise |
887 return result |
887 return result |
|
888 |
|
889 @staticmethod |
|
890 def fake_form(formid, field_dict=None, entity_field_dicts=()): |
|
891 """Build _cw.form dictionnary to fake posting of some standard cubicweb form |
|
892 |
|
893 * `formid`, the form id, usually form's __regid__ |
|
894 |
|
895 * `field_dict`, dictionary of name:value for fields that are not tied to an entity |
|
896 |
|
897 * `entity_field_dicts`, list of (entity, dictionary) where dictionary contains name:value |
|
898 for fields that are not tied to the given entity |
|
899 """ |
|
900 assert field_dict or entity_field_dicts, \ |
|
901 'field_dict and entity_field_dicts arguments must not be both unspecified' |
|
902 if field_dict is None: |
|
903 field_dict = {} |
|
904 form = {'__form_id': formid} |
|
905 fields = [] |
|
906 for field, value in field_dict.items(): |
|
907 fields.append(field) |
|
908 form[field] = value |
|
909 def _add_entity_field(entity, field, value): |
|
910 entity_fields.append(field) |
|
911 form[eid_param(field, entity.eid)] = value |
|
912 for entity, field_dict in entity_field_dicts: |
|
913 if '__maineid' not in form: |
|
914 form['__maineid'] = entity.eid |
|
915 entity_fields = [] |
|
916 form.setdefault('eid', []).append(entity.eid) |
|
917 _add_entity_field(entity, '__type', entity.cw_etype) |
|
918 for field, value in field_dict.items(): |
|
919 _add_entity_field(entity, field, value) |
|
920 if entity_fields: |
|
921 form[eid_param('_cw_entity_fields', entity.eid)] = ','.join(entity_fields) |
|
922 if fields: |
|
923 form['_cw_fields'] = ','.join(fields) |
|
924 return form |
888 |
925 |
889 @deprecated('[3.19] use .admin_request_from_url instead') |
926 @deprecated('[3.19] use .admin_request_from_url instead') |
890 def req_from_url(self, url): |
927 def req_from_url(self, url): |
891 """parses `url` and builds the corresponding CW-web request |
928 """parses `url` and builds the corresponding CW-web request |
892 |
929 |