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 |
880 req.cnx.commit() |
880 req.cnx.commit() |
881 except web.Redirect: |
881 except web.Redirect: |
882 req.cnx.commit() |
882 req.cnx.commit() |
883 raise |
883 raise |
884 return result |
884 return result |
|
885 |
|
886 @staticmethod |
|
887 def fake_form(formid, field_dict=None, entity_field_dicts=()): |
|
888 """Build _cw.form dictionnary to fake posting of some standard cubicweb form |
|
889 |
|
890 * `formid`, the form id, usually form's __regid__ |
|
891 |
|
892 * `field_dict`, dictionary of name:value for fields that are not tied to an entity |
|
893 |
|
894 * `entity_field_dicts`, list of (entity, dictionary) where dictionary contains name:value |
|
895 for fields that are not tied to the given entity |
|
896 """ |
|
897 assert field_dict or entity_field_dicts, \ |
|
898 'field_dict and entity_field_dicts arguments must not be both unspecified' |
|
899 if field_dict is None: |
|
900 field_dict = {} |
|
901 form = {'__form_id': formid} |
|
902 fields = [] |
|
903 for field, value in field_dict.items(): |
|
904 fields.append(field) |
|
905 form[field] = value |
|
906 def _add_entity_field(entity, field, value): |
|
907 entity_fields.append(field) |
|
908 form[eid_param(field, entity.eid)] = value |
|
909 for entity, field_dict in entity_field_dicts: |
|
910 if '__maineid' not in form: |
|
911 form['__maineid'] = entity.eid |
|
912 entity_fields = [] |
|
913 form.setdefault('eid', []).append(entity.eid) |
|
914 _add_entity_field(entity, '__type', entity.cw_etype) |
|
915 for field, value in field_dict.items(): |
|
916 _add_entity_field(entity, field, value) |
|
917 if entity_fields: |
|
918 form[eid_param('_cw_entity_fields', entity.eid)] = ','.join(entity_fields) |
|
919 if fields: |
|
920 form['_cw_fields'] = ','.join(fields) |
|
921 return form |
885 |
922 |
886 @deprecated('[3.19] use .admin_request_from_url instead') |
923 @deprecated('[3.19] use .admin_request_from_url instead') |
887 def req_from_url(self, url): |
924 def req_from_url(self, url): |
888 """parses `url` and builds the corresponding CW-web request |
925 """parses `url` and builds the corresponding CW-web request |
889 |
926 |