def setUp(self): init_annalist_test_site() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection.create(self.testsite, "testcoll", collection_create_values("testcoll")) self.testtype = RecordType.create(self.testcoll, "testtype", recordtype_create_values("testcoll", "testtype")) self.testtype2 = RecordType.create(self.testcoll, "testtype2", recordtype_create_values("testcoll", "testtype2")) self.testdata = RecordTypeData.create(self.testcoll, "testtype", {}) self.testdata2 = RecordTypeData.create(self.testcoll, "testtype2", {}) e1 = self._create_entity_data("entity1") e2 = self._create_entity_data("entity2") e3 = self._create_entity_data("entity3") e4 = EntityData.create(self.testdata2, "entity4", entitydata_create_values("entity4", type_id="testtype2") ) self.type_ids = get_site_types_linked("testcoll") self.type_ids.append(FieldChoice("_type/testtype", label="RecordType testcoll/_type/testtype", link=recordtype_url("testcoll", "testtype") )) self.type_ids.append(FieldChoice("_type/testtype2", label="RecordType testcoll/_type/testtype2", link=recordtype_url("testcoll", "testtype2") )) self.list_ids = get_site_lists_linked("testcoll") # Login and permissions create_test_user(self.testcoll, "testuser", "testpassword") self.client = Client(HTTP_HOST=TestHost) loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) return
def select_option(opt): if isinstance(opt, (str, unicode)): opt = FieldChoice(opt) selected = ('' if opt.value != sel else ' selected="selected"') label = (placeholder or "") if opt.value == "" else opt.choice() if escape_label: label = escape(label) # label = opt.label or opt.value or placeholder or "" return '<option value="%s"%s>%s</option>' % (opt.value, selected, label)
def expect_render_option(choice_val, select_val, placeholder): selected = ''' selected="selected"''' if choice_val == select_val else '''''' if choice_val == "": option_val = "" choice_text = placeholder value_text = ''' value=""''' else: option_val = "opt_type/"+choice_val choice_text = "label "+choice_val value_text = ''' value="%s"'''%option_val fc = FieldChoice(id=option_val, label=choice_text, choice_value=(choice_val=="dup")) return '''<option%s%s>%s</option>'''%(value_text, selected, fc.choice_html())
def expect_render_select(select_name, choice_list, select_val, placeholder): sel = """<select name="%s">"""%select_name if select_val not in choice_list: val = "opt_type/"+select_val if select_val else "" lab = "opt_type/"+select_val if select_val else placeholder fc = FieldChoice(id=val, label=lab) nopt = ['''<option value="%s" selected="selected">%s</option>'''%(val, fc.choice_html())] else: nopt = [] opts = [ expect_render_option(choice_val, select_val, placeholder) for choice_val in choice_list ] end = "</select>\n" return "\n".join([sel]+nopt+opts+[end])
def expect_render_option(choice_val, select_val, placeholder): selected = ''' selected="selected"''' if choice_val == select_val else '''''' if choice_val == "": option_val = "" choice_text = placeholder value_text = ''' value=""''' else: option_val = "opt_type/" + choice_val choice_text = "label " + choice_val value_text = ''' value="%s"''' % option_val fc = FieldChoice(id=option_val, label=choice_text, choice_value=(choice_val == "dup")) return '''<option%s%s>%s</option>''' % (value_text, selected, fc.choice_html())
def setUp(self): init_annalist_test_site() init_annalist_test_coll() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection(self.testsite, "testcoll") # Populate collection with linked record types, views and lists self.testsrc_type = RecordType.create(self.testcoll, "testsrc_type", testsrc_type_create_values) self.testtgt_type = RecordType.create(self.testcoll, "testtgt_type", testtgt_type_create_values) self.testsrc_view = RecordView.create(self.testcoll, "testsrc_view", testsrc_view_create_values) self.testtgt_view = RecordView.create(self.testcoll, "testtgt_view", testtgt_view_create_values) self.testsrc_list = RecordList.create(self.testcoll, "testsrc_list", testsrc_list_create_values) self.testtgt_list = RecordList.create(self.testcoll, "testtgt_list", testtgt_list_create_values) self.testtgtref_field = RecordField.create( self.testcoll, "testtgtref_field", testtgtref_field_create_values) self.no_options = [FieldChoice('', label="(no options)")] self.tgt_options = ([ FieldChoice("testtgt_type/" + v, label="testtgt_entity %s label" % v, link=entity_url("testcoll", "testtgt_type", v)) for v in ["testtgt1", "testtgt2"] ]) # Create data records for testing: self.testtgt_type_info = EntityTypeInfo(self.testcoll, "testtgt_type", create_typedata=True) self.testsrc_type_info = EntityTypeInfo(self.testcoll, "testsrc_type", create_typedata=True) for tgt_id in ("testtgt1", "testtgt2"): self.testtgt_type_info.create_entity( tgt_id, testtgt_entity_create_values(tgt_id)) for src_id, tgt_ref in (("testsrc1", "testtgt1"), ("testsrc2", "testtgt2")): self.testsrc_type_info.create_entity( src_id, testsrc_entity_create_values(src_id, tgt_ref)) # Login and permissions create_test_user(self.testcoll, "testuser", "testpassword") self.client = Client(HTTP_HOST=TestHost) loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) return
def _make_select_test_context(self, valkey, vallink, valchoices, valplaceholder): valtext = "opt_type/" + valkey if valkey else "" if valkey not in valchoices: vallink = None # log.info( # "_make_select_test_context: valtext %r, vallink %r, valchoices %r"% # (valtext, vallink, valchoices) # ) valoptions = [] for c in valchoices: if c != "": val = "opt_type/" + c lab = "label " + c else: val = "" lab = valplaceholder lnk = vallink if val == valtext else "@@no_link@@" valoptions.append(FieldChoice(val, label=lab, link=lnk)) # log.info( # "_make_select_test_context: valoptions %r"% # (valoptions,) # ) return self._make_test_context(valtext, field_ref_type="ref_type", options=valoptions, field_link=vallink)
def render(self, context): try: val = get_field_edit_value(context, None) or "" # Use refer-to type if value does not include type.. typval = fill_type_entity_id( val, context['field'].description['field_ref_type']) textval = SelectValueMapper.encode(typval) options = update_choice_labels(context['field']['options']) # print repr(options) if textval not in [o.value for o in options]: options = list(options) # clone options.insert(0, FieldChoice( textval)) # Add missing current value to options with context.push(encoded_field_value=textval, field_options=options): result = self._template.render(context) except Exception as e: log.exception("Exception in Select_edit_renderer.render") log.error("Select_edit_renderer.render: " + repr(e)) # log.error("Field val %r"%(val,)) # log.error("Field name %r"%(context['field'].field_name,)) # log.error("Field type ref %r"%(context['field'].description['field_ref_type'],)) # ex_type, ex, tb = sys.exc_info() # traceback.print_tb(tb) result = repr(e) return result
def test_select_subtype1_fields(self): ref_view = self._create_ref_type_view(view_id="Test_ref_type1_view", record_type="test:testtypes") ref_field = self._create_ref_type_field(entity_type="test:testtype1") u = entitydata_edit_url("new", "testcoll", "ref_type", view_id="Test_ref_type1_view") r = self.client.get(u) self.assertEqual(r.status_code, 200) self.assertEqual(r.reason_phrase, "OK") # Check render context self.assertEqual(r.context['coll_id'], "testcoll") self.assertEqual(r.context['type_id'], "ref_type") # Fields head_fields = context_list_head_fields(r.context) self.assertEqual(len(head_fields), 1) # One row of 2 cols.. self.assertEqual(len(head_fields[0]['row_field_descs']), 2) f0 = context_view_field(r.context, 0, 0) f1 = context_view_field(r.context, 0, 1) self.assertEqual(f0['field_id'], "Entity_id") self.assertEqual(f1['field_id'], "Test_ref_type_field") baselabel = "Entity testcoll/" baseuri = TestBasePath + "/c/testcoll/d/%s/" ref_options = ([ FieldChoice(opt, label=baselabel + opt, link=baseuri % opt) for opt in ['testtype1/entity1'] ]) self.assertEqual(f1['options'], ref_options) return
def setUp(self): init_annalist_test_site() init_annalist_test_coll() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection(self.testsite, "testcoll") # Populate collection with linked record types, views and lists self.test_supertype_type = RecordType.create( self.testcoll, "test_supertype_type", test_supertype_type_create_values) self.test_subtype_type = RecordType.create( self.testcoll, "test_subtype_type", test_subtype_type_create_values) self.no_options = [FieldChoice('', label="(no options)")] # Create type and data records for testing: self.test_supertype_type_info = EntityTypeInfo(self.testcoll, "test_supertype_type", create_typedata=True) self.test_subtype_type_info = EntityTypeInfo(self.testcoll, "test_subtype_type", create_typedata=True) for entity_id in ("test_subtype_entity", ): self.test_subtype_type_info.create_entity( entity_id, test_subtype_entity_create_values(entity_id)) # Login and permissions create_test_user(self.testcoll, "testuser", "testpassword") self.client = Client(HTTP_HOST=TestHost) loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) return
def get_field_options(self): #@@ # options = self._field_description['field_choice_labels'] # OrderedDict # options = options.values() if options is not None else ["(no options)"] #@@ options = self._field_description['field_choices'] # OrderedDict options = (options.values() if options is not None else [FieldChoice('', label="(no options)")]) return options
def expect_render_select(select_name, choice_list, select_val, placeholder): sel = """<select name="%s">""" % select_name if select_val not in choice_list: val = "opt_type/" + select_val if select_val else "" lab = "opt_type/" + select_val if select_val else placeholder fc = FieldChoice(id=val, label=lab) nopt = [ '''<option value="%s" selected="selected">%s</option>''' % (val, fc.choice_html()) ] else: nopt = [] opts = [ expect_render_option(choice_val, select_val, placeholder) for choice_val in choice_list ] end = "</select>\n" return "\n".join([sel] + nopt + opts + [end])
def setUp(self): init_annalist_test_site() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection.create(self.testsite, "testcoll", collection_create_values("testcoll")) self.no_options = [FieldChoice('', label="(no options)")] self.no_view_id = [FieldChoice('', label="(view id)")] self.no_list_id = [FieldChoice('', label="(list id)")] self.view_options = self.no_view_id + get_site_views_linked("testcoll") self.list_options = self.no_list_id + get_site_lists_linked("testcoll") # For checking Location: header values... self.continuation_url = (TestHostUri + entitydata_list_type_url( coll_id="testcoll", type_id=layout.TYPE_TYPEID)) # Login and permissions create_test_user(self.testcoll, "testuser", "testpassword") self.client = Client(HTTP_HOST=TestHost) loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) return
def setUp(self): init_annalist_test_site() init_annalist_test_coll() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection.create(self.testsite, "testcoll", collection_create_values("testcoll")) self.testtype = RecordType.create(self.testcoll, "testtype", recordtype_create_values("testtype")) self.testdata = RecordTypeData.create(self.testcoll, "testtype", {}) self.no_options = [FieldChoice('', label="(no options)")] self.no_view_id = [FieldChoice('', label="(view id)")] self.no_list_id = [FieldChoice('', label="(list id)")] self.view_options = get_site_views_linked("testcoll") self.list_options = get_site_lists_linked("testcoll") # Login and permissions create_test_user(self.testcoll, "testuser", "testpassword") self.client = Client(HTTP_HOST=TestHost) loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) return
def setUp(self): self.testsite = init_annalist_test_site() self.testcoll = init_annalist_named_test_coll(layout.BIBDATA_ID) self.no_options = [FieldChoice('', label="(no options)")] def special_field(fid): return (fid.startswith("Field_") or fid.startswith("List_") or fid.startswith("Type_") or fid.startswith("View_") or fid.startswith("User_")) self.field_options = sorted([ fid for fid in self.testcoll.child_entity_ids(RecordField, altscope="all") if fid != layout.INITIAL_VALUES_ID ]) self.field_options_no_bibentry = sorted([ fid for fid in self.testcoll.child_entity_ids(RecordField, altscope="all") if fid != layout.INITIAL_VALUES_ID and not fid.startswith("Bib_") ]) self.field_options_bib_no_special = sorted([ fid for fid in self.testcoll.child_entity_ids(RecordField, altscope="all") if fid != layout.INITIAL_VALUES_ID and not special_field(fid) ]) self.field_options_no_special = sorted([ fid for fid in self.testcoll.child_entity_ids(RecordField, altscope="all") if fid != layout.INITIAL_VALUES_ID and not (fid.startswith("Bib_") or special_field(fid)) ]) # log.info(self.field_options_no_bibentry) # For checking Location: header values... self.continuation_path = entitydata_list_type_url( coll_id="testcoll", type_id=layout.VIEW_TYPEID) self.continuation_url = TestHostUri + self.continuation_path create_test_user(self.testcoll, "testuser", "testpassword") self.client = Client(HTTP_HOST=TestHost) loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) return
def setUp(self): init_annalist_test_site() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection.create(self.testsite, "testcoll", collection_create_values("testcoll")) self.annalcoll = Collection.load(self.testsite, layout.SITEDATA_ID) self.no_options = [FieldChoice('', label="(no options)")] # For checking Location: header values... self.continuation_url = (TestHostUri + entitydata_list_type_url( coll_id="testcoll", type_id=layout.VOCAB_TYPEID)) # Login and permissions create_test_user(self.testcoll, "testuser", "testpassword") create_user_permissions(self.annalcoll, "testuser", user_permissions=["VIEW"]) self.client = Client(HTTP_HOST=TestHost) loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) return
def setUp(self): init_annalist_test_site() self.testsite = Site(TestBaseUri, TestBaseDir) self.testcoll = Collection.create(self.testsite, "testcoll", collection_create_values("testcoll") ) self.testtype = RecordType.create(self.testcoll, "testtype", recordtype_create_values("testcoll", "testtype") ) self.testdata = RecordTypeData.create(self.testcoll, "testtype", {}) # Create view with repeated field id self.viewdata = recordview_create_values(view_id="DupField_view") recordview_values_add_field( self.viewdata, field_id="Entity_comment", field_placement="small:0,12" ) recordview_values_add_field( self.viewdata, field_id="Entity_comment", field_property_uri="rdfs:comment_alt", field_placement="small:0,12" ) self.testview = RecordView.create(self.testcoll, "DupField_view", self.viewdata) # Other data self.type_ids = get_site_types_linked("testcoll") self.type_ids.append(FieldChoice("_type/testtype", label="RecordType testcoll/_type/testtype", link=recordtype_url("testcoll", "testtype") )) # Login and permissions create_test_user(self.testcoll, "testuser", "testpassword") self.client = Client(HTTP_HOST=TestHost) loggedin = self.client.login(username="******", password="******") self.assertTrue(loggedin) return
def _no_test_test_select_view_subtype_fields(self): # @@INCOMPLETE: this was an attempt to check field selction from the view context, # but abandoned to to complexity of reconstructing bound fields. # NOTE: sitedata tests use Beautifulsoup representation of rendered # page for these tests ref_view = self._create_ref_type_view() ref_field = self._create_ref_type_field() u = entitydata_edit_url("edit", "testcoll", "_view", "Test_ref_type_view", view_id="View_view") r = self.client.get(u) self.assertEqual(r.status_code, 200) self.assertEqual(r.reason_phrase, "OK") # Check render context self.assertEqual(r.context['coll_id'], "testcoll") self.assertEqual(r.context['type_id'], "_view") # Fields self.assertEqual(len(r.context['fields']), 6) self.assertEqual(r.context['fields'][0]['field_id'], "View_id") self.assertEqual(r.context['fields'][1]['field_id'], "View_label") self.assertEqual(r.context['fields'][2]['field_id'], "View_comment") self.assertEqual(r.context['fields'][3]['field_id'], "View_target_type") self.assertEqual(r.context['fields'][4]['field_id'], "View_edit_view") self.assertEqual(r.context['fields'][5]['field_id'], "View_fields") print repr(r.context['fields'][5]) baselabel = "Entity testcoll/" baseuri = TestBasePath + "/c/testcoll/d/%s/" ref_options = ([ FieldChoice(opt, label=baselabel + opt, link=baseuri % opt) for opt in ['testtype1/entity1', 'testtype2/entity2', 'testtypes/entitys'] ]) self.assertEqual(r.context['fields'][5]['options'], ref_options) return
def __init__(self, collection, recordfield, view_context=None, field_property=None, field_placement=None, group_view=None, group_ids_seen=[], field_placement_classes=None): """ Creates a field description value to use in a context value when rendering a form. Values defined here are mentioned in field rendering templates. The FieldDescription object behaves as a dictionary containing the various field attributes. collection is a collection from which data is being rendered. Used when generating enumerated values. recordfield is a RecordField value or dictionary containing details of the field for which a descriptor is constructed. view_context is a dictionary of additional values that may be used in assembling values to be used when rendering the field. In particular, a copy of the view description record provides context for some enumeration type selections. field_property if supplied, overrides the field property URI from `recordfield` field_placement if supplied, overrides field placement from `recordfield` group_view if the field itself references a list of fields, this is a RecordGroup value or dictionary containing the referenced list of fields. group_ids_seen group ids expanded so far, to check for recursive reference. field_classes if supplied, overrides field placement classes derived from value for `field_placement` string. """ self._collection = collection # log.debug("FieldDescription recordfield: %r"%(recordfield,)) field_id = recordfield.get(ANNAL.CURIE.id, "_missing_id_") field_name = recordfield.get(ANNAL.CURIE.field_name, field_id) # Field name in form field_label = recordfield.get(RDFS.CURIE.label, "") field_property = field_property or recordfield.get( ANNAL.CURIE.property_uri, "") field_placement = field_placement or recordfield.get( ANNAL.CURIE.field_placement, "") field_placement_c = field_placement_classes or get_placement_classes( field_placement) field_placeholder = recordfield.get(ANNAL.CURIE.placeholder, "") field_render_type = extract_entity_id( recordfield.get(ANNAL.CURIE.field_render_type, "")) field_value_mode = extract_entity_id( recordfield.get(ANNAL.CURIE.field_value_mode, "@@FieldDescription:value_mode@@")) field_ref_type = extract_entity_id( recordfield.get(ANNAL.CURIE.field_ref_type, None)) field_entity_type = recordfield.get(ANNAL.CURIE.field_entity_type, None) field_group_ref = extract_entity_id( recordfield.get(ANNAL.CURIE.group_ref, None)) self._field_desc = ({ 'field_id': field_id, 'field_name': field_name, 'field_instance_name': field_name, 'field_render_type': field_render_type, 'field_value_mode': field_value_mode, 'field_value_type': recordfield.get(ANNAL.CURIE.field_value_type, ""), 'field_label': field_label, 'field_help': recordfield.get(RDFS.CURIE.comment, ""), 'field_property_uri': field_property, 'field_placement': field_placement_c, 'field_placeholder': field_placeholder, 'field_default_value': recordfield.get(ANNAL.CURIE.default_value, None), 'field_ref_type': field_ref_type, 'field_ref_field': recordfield.get(ANNAL.CURIE.field_ref_field, None), 'field_ref_restriction': recordfield.get(ANNAL.CURIE.field_ref_restriction, "ALL"), 'field_entity_type': field_entity_type, 'field_choices': None # , 'field_choice_labels': None # , 'field_choice_links': None , 'field_group_ref': field_group_ref, 'group_label': None, 'group_add_label': None, 'group_delete_label': None, 'group_view': None, 'group_field_descs': None, 'field_render_label': get_label_renderer(field_render_type, field_value_mode), 'field_render_view': get_view_renderer(field_render_type, field_value_mode), 'field_render_edit': get_edit_renderer(field_render_type, field_value_mode), 'field_render_label_view': get_label_view_renderer(field_render_type, field_value_mode), 'field_render_label_edit': get_label_edit_renderer(field_render_type, field_value_mode), 'field_render_colhead': get_col_head_renderer(field_render_type, field_value_mode), 'field_render_colhead_view': get_col_head_view_renderer(field_render_type, field_value_mode), 'field_render_colhead_edit': get_col_head_edit_renderer(field_render_type, field_value_mode), 'field_render_colview': get_col_view_renderer(field_render_type, field_value_mode), 'field_render_coledit': get_col_edit_renderer(field_render_type, field_value_mode), 'field_render_mode': get_mode_renderer(field_render_type, field_value_mode), 'field_value_mapper': get_value_mapper(field_render_type) }) self._field_suffix_index = 0 # No dup self._field_suffix = "" # If field references type, pull in copy of type id and link values type_ref = self._field_desc['field_ref_type'] if type_ref: restrict_values = self._field_desc['field_ref_restriction'] entity_finder = EntityFinder(collection, selector=restrict_values) # Determine subtypes of field entity type, if specified # @@TODO: subtype logic here is just pig ugly... # need context to provide info that can be used to calculate supertypes # on-the-fly as needed by the field restriction expression. E.g. include # collection object in context. if field_entity_type and restrict_values: field_entity_subtypes = ([ t.get_type_uri() for t in entity_finder.get_collection_uri_subtypes( field_entity_type, altscope="all") ]) self._field_desc[ 'field_entity_subtypes'] = field_entity_subtypes field_view_context = dict( view_context or {}, field={'subtypes': field_entity_subtypes}) else: field_view_context = view_context entities = entity_finder.get_entities_sorted( type_id=type_ref, context=field_view_context, altscope="select") # Note: the options list may be used more than once, so the id generator # returned must be materialized as a list # Uses collections.OrderedfDict to preserve entity ordering self._field_desc['field_choices'] = collections.OrderedDict() if field_render_type in ["Enum_optional", "Enum_choice_opt"]: # Add blank choice for optional selections self._field_desc['field_choices'][''] = FieldChoice( '', label=field_placeholder) for e in entities: eid = e.get_id() val = e.get_type_entity_id() if eid != "_initial_values": self._field_desc['field_choices'][val] = FieldChoice( val, label=e.get_label(), link=e.get_view_url_path()) # log.debug("FieldDescription: typeref %s: %r"% # (self._field_desc['field_ref_type'], list(self._field_desc['field_choices'].items())) # ) # If field references group, pull in field details if group_view: if field_id in group_ids_seen: raise Annalist_Error( field_id, "Recursive field reference in field group") group_ids_seen = group_ids_seen + [field_id] group_label = (field_label or group_view.get( RDFS.CURIE.label, self._field_desc['field_group_ref'])) add_label = recordfield.get(ANNAL.CURIE.repeat_label_add, None) or "Add " + field_id remove_label = recordfield.get(ANNAL.CURIE.repeat_label_delete, None) or "Remove " + field_id group_field_descs = [] for subfield in group_view[ANNAL.CURIE.group_fields]: f = field_description_from_view_field(collection, subfield, view_context, group_ids_seen) group_field_descs.append(f) self._field_desc.update({ 'group_id': field_id, 'group_label': group_label, 'group_add_label': add_label, 'group_delete_label': remove_label, 'group_view': group_view, 'group_field_descs': group_field_descs }) # log.debug("FieldDescription: %s"%field_id) # log.info("FieldDescription._field_desc %r"%(self._field_desc,)) # log.info("FieldDescription.field_placement %r"%(self._field_desc['field_placement'],)) return
def test_Repeat_Ref_Multifield_edit(self): self._create_image_multifield_repeat_ref_and_view() # Render view of multifield reference u = entitydata_edit_url("edit", "testcoll", "ref_type", "Test_rpt_entity", view_id="Test_rptimg_view") r = self.client.get(u) self.assertEqual(r.status_code, 200) self.assertEqual(r.reason_phrase, "OK") # Check render context self.assertEqual(r.context['coll_id'], "testcoll") self.assertEqual(r.context['type_id'], "ref_type") self.assertEqual(r.context['entity_id'], "Test_rpt_entity") self.assertEqual(r.context['action'], "edit") # Fields self.assertEqual(len(r.context['fields']), 2) # 1st field - Id f0 = context_view_field(r.context, 0, 0) self.assertEqual(f0['field_id'], "Entity_id") self.assertEqual(f0['field_name'], "entity_id") self.assertEqual(f0['field_label'], "Id") self.assertEqual(f0['field_value'], "Test_rpt_entity") # 2nd field - multifield group f1 = context_view_field(r.context, 1, 0) self.assertEqual(f1['field_id'], "Test_rptref_field") self.assertEqual(f1['field_name'], "Test_rptref_field") self.assertEqual(f1['field_label'], "Repeat image reference") self.assertEqual(f1['field_render_type'], "Group_Seq_Row") self.assertEqual(f1['field_value_mode'], "Value_direct") self.assertEqual(f1['field_value_type'], "annal:Field_group") self.assertEqual(f1['field_group_ref'], "Test_rptref_group") self.assertEqual(f1['group_label'], "Repeat image reference") self.assertEqual(f1['field_property_uri'], "test:rpt_image") self.assertEqual(f1['field_value'][0], {'test:ref_image': 'Test_img_entity'}) # Test rendered result field_vals = default_fields( coll_id="testcoll", type_id="ref_type", entity_id="Test_rpt_entity", view_id="Test_rptimg_view", basepath=TestBasePath, tooltip1=f0['field_help'], ) formrow1 = """ <div class="small-12 medium-6 columns" title="%(tooltip1)s"> <div class="row view-value-row"> <div class="%(label_classes)s"> <span>Id</span> </div> <div class="%(input_classes)s"> <input type="text" size="64" name="entity_id" placeholder="(entity id)" value="%(entity_id)s"/> </div> </div> </div> """ % field_vals(width=6) formrow2a = """ <div class="group-label small-12 medium-2 columns"> <span>Repeat image reference</span> </div> """ formrow2b = """ <div class="small-12 medium-10 columns hide-for-small-only"> <div class="row"> <div class="small-1 columns"> </div> <div class="small-11 columns"> <div class="edit-grouprow col-head row"> <div class="%(col_head_classes)s"> <span>Image reference</span> </div> </div> </div> </div> </div> """ % field_vals(width=6) tgt_field_vals = default_fields( coll_id="testcoll", type_id="img_type", entity_id="Test_img_entity", view_id="Test_rptimg_view", repeat_id="Test_rptref_field", field_id="Test_refimg_field", tooltip3b=f1._field_description['group_field_descs'][0] ['field_help']) formrow3a = """ <div class="small-12 medium-2 columns hide-for-small-only"> </div> """ % tgt_field_vals(width=6) formrow3b = (""" <div class="small-12 medium-10 columns"> <div class="tbody row select-row"> <div class="small-1 columns checkbox-in-edit-padding"> <input type="checkbox" class="select-box right" name="%(repeat_id)s__select_fields" value="0" /> </div> <div class="small-11 columns"> <div class="edit-grouprow row"> <div class="%(col_item_classes)s" title="%(tooltip3b)s"> <div class="row show-for-small-only"> <div class="view-label small-12 columns"> <span>Image reference</span> </div> </div> <div class="row view-value-col"> <div class="view-value small-12 columns"> """ + render_select_options( "%(repeat_id)s__0__%(field_id)s", "Image reference", [ FieldChoice("%(type_id)s/%(entity_id)s", label="Label %(entity_id)s") ], "%(type_id)s/%(entity_id)s") + """ </div> </div> </div> </div> </div> </div> </div> """) % tgt_field_vals(width=6) # log.info(r.content) self.assertContains(r, formrow1, html=True) self.assertContains(r, formrow2a, html=True) self.assertContains(r, formrow2b, html=True) self.assertContains(r, formrow3a, html=True) self.assertContains(r, formrow3b, html=True) return
def no_selection(label): return [FieldChoice("", "", label)]
def list_view_context_data( coll_id="testcoll", list_id=None, orig_id=None, action=None, list_uri=None, list_type="List", list_label=None, list_descr=None, list_default_type="_type/Default_type", type_choices=None, list_default_view="_type/Default_view", view_choices=None, list_entity_selector="ALL", list_entity_type="", list_fields=None, num_fields=0, update="RecordList", continuation_url=None ): if list_label is None: if list_id: #@@TODO: use same format as no list_id; change form data too list_label = "%s %s/%s"%(update, coll_id, list_id) else: list_label = "%s list (%s/)"%(update, coll_id) if list_fields is None: if num_fields == 2: list_fields = ( [ { "annal:field_id": layout.FIELD_TYPEID+"/Entity_id" , "annal:field_placement": "small:0,3" } , { "annal:field_id": layout.FIELD_TYPEID+"/Entity_label" , "annal:field_placement": "small:3,9" } ]) if num_fields == 3: list_fields = ( [ { "annal:field_id": layout.FIELD_TYPEID+"/Entity_id" , "annal:field_placement": "small:0,3" } , { "annal:field_id": layout.FIELD_TYPEID+"/Entity_type" , "annal:field_placement": "small:3,3" } , { "annal:field_id": layout.FIELD_TYPEID+"/Entity_label" , "annal:field_placement": "small:6,6" } ]) list_type_choices = get_site_list_types_linked("testcoll") if type_choices is None: type_choices = ( [ FieldChoice("", label="(default entity type)")] + get_site_types_linked("testcoll") + [ FieldChoice("_type/testtype", label="RecordType testcoll/_type/testtype", link=recordtype_url("testcoll", "testtype") )] ) if view_choices is None: view_choices = ( [ FieldChoice("", label="(view id)") ] + get_site_views_linked("testcoll") ) if continuation_url is None: continuation_url = entitydata_list_type_url(coll_id, layout.LIST_TYPEID) view_label = "List definition" view_title = ( "%s - %s - Collection %s"%(list_label, view_label, coll_id) if list_label else "%s - Collection %s"%(view_label, coll_id) ) # Target record fields listed in the view description context_dict = ( { 'title': view_title , 'heading': view_label , 'coll_id': coll_id , 'type_id': layout.LIST_TYPEID , 'view_id': 'List_view' , 'entity_id': list_id or "" , 'orig_id': orig_id , 'orig_type': layout.LIST_TYPEID , 'record_type': "annal:List" , 'continuation_url': continuation_url , 'fields': [ context_field_row( get_bound_field("List_id", list_id), # 0 (0,0) get_bound_field("List_type", list_type, # 1 (0,1) options=list_type_choices), ) , context_field_row( get_bound_field("List_label", list_label) # 2 (1,0) ) , context_field_row( get_bound_field("List_comment", list_descr) # 3 (2,0) ) , context_field_row( get_bound_field("List_default_type", list_default_type, # 4 (3,0) options=type_choices), get_bound_field("List_default_view", list_default_view, # 5 (3,1) options=view_choices), ) , context_field_row( get_bound_field("List_entity_selector", list_entity_selector) # 6 (4,0) ) , context_field_row( get_bound_field("List_entity_type", list_entity_type) # 7 (5,0) ) , get_bound_field("List_fields", list_fields) # 8 (6, 0) ] }) if action: context_dict['action'] = action if list_uri: context_dict['entity_uri'] = list_uri return context_dict
def test_Ref_Multifield_edit(self): self._create_image_multifield_ref_and_view() # Render view of multifield reference u = entitydata_edit_url("edit", "testcoll", "ref_type", "Test_ref_entity", view_id="Test_refimg_view") r = self.client.get(u) self.assertEqual(r.status_code, 200) self.assertEqual(r.reason_phrase, "OK") # Check render context self.assertEqual(r.context['coll_id'], "testcoll") self.assertEqual(r.context['type_id'], "ref_type") self.assertEqual(r.context['entity_id'], "Test_ref_entity") self.assertEqual(r.context['action'], "edit") # Fields self.assertEqual(len(r.context['fields']), 1) # 1st field - Id f0 = context_view_field(r.context, 0, 0) self.assertEqual(f0['field_id'], "Entity_id") self.assertEqual(f0['field_name'], "entity_id") self.assertEqual(f0['field_label'], "Id") self.assertEqual(f0['field_value'], "Test_ref_entity") # 2nd field - multifield group f1 = context_view_field(r.context, 0, 1) self.assertEqual(f1['field_id'], "Test_refimg_field") self.assertEqual(f1['field_name'], "Test_refimg_field") self.assertEqual(f1['field_label'], "Image reference") self.assertEqual(f1['field_render_type'], "RefMultifield") self.assertEqual(f1['field_value_mode'], "Value_entity") self.assertEqual(f1['field_value_type'], "annal:Field_group") self.assertEqual(f1['field_group_ref'], "Test_refimg_group") self.assertEqual(f1['group_label'], "Image reference") self.assertEqual(f1['field_property_uri'], "test:ref_image") self.assertEqual(f1['field_value'], "Test_img_entity") # Test rendered result field_vals = default_fields( coll_id="testcoll", type_id="ref_type", entity_id="Test_ref_entity", view_id="Test_refimg_view", basepath=TestBasePath, tooltip1=f0['field_help'], ) formrow1 = """ <div class="small-12 medium-6 columns" title="%(tooltip1)s"> <div class="row view-value-row"> <div class="%(label_classes)s"> <span>Id</span> </div> <div class="%(input_classes)s"> <input type="text" size="64" name="entity_id" placeholder="(entity id)" value="%(entity_id)s"/> </div> </div> </div> """ % field_vals(width=6) tgt_field_vals = default_fields( coll_id="testcoll", type_id="img_type", entity_id="Test_img_entity", view_id="Test_refimg_view", field_id="Test_refimg_field", basepath=TestBasePath, tooltip2=f1['field_help'], ) formrow2 = (""" <div class="small-12 medium-6 columns" title="%(tooltip2)s"> <div class="row view-value-row"> <div class="%(label_classes)s"> <span>Image reference</span> </div> <div class="%(input_classes)s"> """ + render_select_options("%(field_id)s", "Image reference", [ FieldChoice("%(type_id)s/%(entity_id)s", label="Label %(entity_id)s") ], "%(type_id)s/%(entity_id)s") + """ </div> </div> </div> """) % tgt_field_vals(width=6) # log.info(r.content) self.assertContains(r, formrow1, html=True) self.assertContains(r, formrow2, html=True) return
def test_Repeat_Ref_Multifield_edit(self): self._create_image_multifield_repeat_ref_and_view() # Render view of multifield reference u = entitydata_edit_url("edit", "testcoll", "ref_type", "Test_rpt_entity", view_id="Test_rptimg_view") response = self.client.get(u) self.assertEqual(response.status_code, 200) self.assertEqual(response.reason_phrase, "OK") # Check render context expect_context = self._create_rptref_view_context( entity_id="Test_rpt_entity", action="edit", continuation_url="" ) actual_context = context_bind_fields(response.context) self.assertEqual(len(response.context['fields']), 2) self.assertDictionaryMatch(actual_context, expect_context) f0 = context_view_field(response.context, 0, 0) f1 = context_view_field(response.context, 1, 0) # Test rendered result field_vals = default_fields( coll_id="testcoll", type_id="ref_type", entity_id="Test_rpt_entity", view_id="Test_rptimg_view", basepath=TestBasePath, tooltip1=f0['field_tooltip'], ) formrow1 = """ <div class="small-12 medium-6 columns" title="%(tooltip1)s"> <div class="row view-value-row"> <div class="%(label_classes)s"> <span>Id</span> </div> <div class="%(input_classes)s"> <input type="text" size="64" name="entity_id" placeholder="(entity id)" value="%(entity_id)s"/> </div> </div> </div> """%field_vals(width=6) formrow2a = """ <div class="group-label small-12 medium-2 columns"> <span>Repeat image reference</span> </div> """ formrow2b = """ <div class="small-12 medium-10 columns hide-for-small-only"> <div class="row"> <div class="small-1 columns"> </div> <div class="small-11 columns"> <div class="edit-grouprow col-head row"> <div class="%(col_head_classes)s"> <span>Image reference</span> </div> </div> </div> </div> </div> """%field_vals(width=6) tgt_field_vals = default_fields( coll_id="testcoll", type_id="img_type", entity_id="Test_img_entity", view_id="Test_rptimg_view", repeat_id="Test_rptref_field", field_id="Test_refimg_field", tooltip3b=f1._field_description['group_field_descs'][0]['field_tooltip_test'] ) formrow3a = """ <div class="small-12 medium-2 columns hide-for-small-only"> </div> """%tgt_field_vals(width=6) formrow3b = (""" <div class="small-12 medium-10 columns"> <div class="tbody row select-row"> <div class="small-1 columns checkbox-in-edit-padding"> <input type="checkbox" class="select-box right" name="%(repeat_id)s__select_fields" value="0" /> </div> <div class="small-11 columns"> <div class="edit-grouprow row"> <div class="%(col_item_classes)s" title="%(tooltip3b)s"> <div class="row show-for-small-only"> <div class="view-label small-12 columns"> <span>Image reference</span> </div> </div> <div class="row view-value-col"> <div class="view-value small-12 columns"> """+ render_select_options( "%(repeat_id)s__0__%(field_id)s", "Image reference", [FieldChoice("%(type_id)s/%(entity_id)s", label="Label %(entity_id)s")], "%(type_id)s/%(entity_id)s" )+ """ </div> </div> </div> </div> </div> </div> </div> """)%tgt_field_vals(width=6) # log.info(r.content) self.assertContains(response, formrow1, html=True) self.assertContains(response, formrow2a, html=True) self.assertContains(response, formrow2b, html=True) self.assertContains(response, formrow3a, html=True) self.assertContains(response, formrow3b, html=True) return
def __init__(self, collection, recordfield, view_context=None, field_property=None, field_placement=None, field_list=None, field_ids_seen=[], field_placement_classes=None): """ Creates a field description value to use in a context value when rendering a form. Values defined here are mentioned in field rendering templates. The FieldDescription object behaves as a dictionary containing the various field attributes. collection is a collection from which data is being rendered. recordfield is a RecordField value or dictionary containing details of the field for which a descriptor is constructed. view_context is a dictionary of additional values that may be used in assembling values to be used when rendering the field. In particular, a copy of the view description record provides context for some enumeration type selections. field_property if supplied, overrides the field property URI from `recordfield` field_placement if supplied, overrides field placement from `recordfield` field_list if the field itself contains or references a list of fields, this is that list of fields. field_ids_seen field ids expanded so far, to check for recursive reference. field_placement_classes if supplied, overrides field placement classes derived from value for `field_placement` string. """ self._collection = collection # log.debug("FieldDescription recordfield: %r"%(recordfield,)) field_id = recordfield.get(ANNAL.CURIE.id, "_missing_id_") field_name = recordfield.get(ANNAL.CURIE.field_name, field_id) # Field name in form field_label = recordfield.get(RDFS.CURIE.label, "") field_help = recordfield.get(RDFS.CURIE.comment, "") field_property = field_property or recordfield.get( ANNAL.CURIE.property_uri, "") field_placement = field_placement or recordfield.get( ANNAL.CURIE.field_placement, "") field_placement_c = field_placement_classes or get_placement_classes( field_placement) field_placeholder = recordfield.get(ANNAL.CURIE.placeholder, "") field_tooltip = recordfield.get(ANNAL.CURIE.tooltip, "") field_render_type = extract_entity_id( recordfield.get(ANNAL.CURIE.field_render_type, "")) field_value_mode = extract_entity_id( recordfield.get(ANNAL.CURIE.field_value_mode, "@@FieldDescription:value_mode@@")) field_ref_type = extract_entity_id( recordfield.get(ANNAL.CURIE.field_ref_type, None)) field_entity_type = recordfield.get(ANNAL.CURIE.field_entity_type, None) field_group_ref = extract_entity_id( recordfield.get(ANNAL.CURIE.group_ref, None)) self._field_desc = ({ 'field_id': field_id, 'field_name': field_name, 'field_instance_name': field_name, 'field_render_type': field_render_type, 'field_value_mode': field_value_mode, 'field_value_type': recordfield.get(ANNAL.CURIE.field_value_type, ""), 'field_label': field_label, 'field_help': field_help, 'field_property_uri': field_property, 'field_placement': field_placement_c, 'field_placeholder': field_placeholder, 'field_tooltip': field_tooltip, 'field_tooltip_test': field_tooltip or (field_help) or "", 'field_default_value': recordfield.get(ANNAL.CURIE.default_value, None), 'field_ref_type': field_ref_type, 'field_ref_field': recordfield.get(ANNAL.CURIE.field_ref_field, None), 'field_ref_restriction': recordfield.get(ANNAL.CURIE.field_ref_restriction, "ALL"), 'field_entity_type': field_entity_type, 'field_choices': None, 'field_group_ref': field_group_ref, 'group_label': None, 'group_add_label': None, 'group_delete_label': None, 'group_field_list': None, 'group_field_descs': None, 'field_renderer': FieldRenderer(field_render_type, field_value_mode), 'field_value_mapper': get_value_mapper(field_render_type) # Used by fieldvaluemap.py }) self._field_suffix_index = 0 # No dup self._field_suffix = "" # If field references type, pull in copy of type id and link values type_ref = self._field_desc['field_ref_type'] if type_ref: restrict_values = self._field_desc['field_ref_restriction'] entity_finder = EntityFinder(collection, selector=restrict_values) entities = entity_finder.get_entities_sorted(type_id=type_ref, context=view_context, altscope="select") # Note: the options list may be used more than once, so the id generator # returned must be materialized as a list # Uses collections.OrderedfDict to preserve entity ordering self._field_desc['field_choices'] = collections.OrderedDict() if field_render_type in ["Enum_optional", "Enum_choice_opt"]: # Add blank choice for optional selections self._field_desc['field_choices'][''] = FieldChoice( '', label=field_placeholder) for e in entities: eid = e.get_id() val = e.get_type_entity_id() if eid != layout.INITIAL_VALUES_ID: self._field_desc['field_choices'][val] = FieldChoice( val, label=e.get_label(), link=e.get_view_url_path()) # If field references or contains field list, pull in field details if field_list: if field_id in field_ids_seen: raise Annalist_Error( field_id, "Recursive field reference in field group") field_ids_seen = field_ids_seen + [field_id] group_label = field_label add_label = recordfield.get(ANNAL.CURIE.repeat_label_add, None) or "Add " + field_id remove_label = recordfield.get(ANNAL.CURIE.repeat_label_delete, None) or "Remove " + field_id group_field_descs = [] for subfield in field_list: f = field_description_from_view_field(collection, subfield, view_context, field_ids_seen) group_field_descs.append(f) self._field_desc.update({ 'group_id': field_id, 'group_label': group_label, 'group_add_label': add_label, 'group_delete_label': remove_label, 'group_field_list': field_list # Description from field/group , 'group_field_descs': group_field_descs # Resulting field description list }) # log.debug("FieldDescription: %s"%field_id) # log.info("FieldDescription._field_desc %r"%(self._field_desc,)) # log.info("FieldDescription.field_placement %r"%(self._field_desc['field_placement'],)) return
def get_placement_options(): return [ FieldChoice(o, label=option_body(placement_occupancy[o])) for o in placement_occupancy ]
def test_Ref_Multifield_edit(self): self._create_image_multifield_ref_and_view() # Render edit view of multifield reference u = entitydata_edit_url("edit", "testcoll", "ref_type", "Test_ref_entity", view_id="Test_refimg_view") response = self.client.get(u) self.assertEqual(response.status_code, 200) self.assertEqual(response.reason_phrase, "OK") # Check render context expect_context = self._create_refimg_view_context( entity_id="Test_ref_entity", entity_ref="Test_img_entity", action="edit", continuation_url="" ) actual_context = context_bind_fields(response.context) self.assertEqual(len(response.context['fields']), 1) self.assertDictionaryMatch(actual_context, expect_context) # Test rendered result f0 = context_view_field(response.context, 0, 0) f1 = context_view_field(response.context, 0, 1) field_vals = default_fields( coll_id="testcoll", type_id="ref_type", entity_id="Test_ref_entity", view_id="Test_refimg_view", basepath=TestBasePath, tooltip1=f0['field_tooltip'], ) formrow1 = """ <div class="small-12 medium-6 columns" title="%(tooltip1)s"> <div class="row view-value-row"> <div class="%(label_classes)s"> <span>Id</span> </div> <div class="%(input_classes)s"> <input type="text" size="64" name="entity_id" placeholder="(entity id)" value="%(entity_id)s"/> </div> </div> </div> """%field_vals(width=6) tgt_field_vals = default_fields( coll_id="testcoll", type_id="img_type", entity_id="Test_img_entity", view_id="Test_refimg_view", field_id="Test_refimg_field", basepath=TestBasePath, tooltip2=f1['field_tooltip'], ) formrow2 = (""" <div class="small-12 medium-6 columns" title="%(tooltip2)s"> <div class="row view-value-row"> <div class="%(label_classes)s"> <span>Image reference</span> </div> <div class="%(input_classes)s"> """+ render_select_options( "%(field_id)s", "Image reference", [FieldChoice("%(type_id)s/%(entity_id)s", label="Label %(entity_id)s")], "%(type_id)s/%(entity_id)s" )+ """ </div> </div> </div> """)%tgt_field_vals(width=6) # log.info(r.content) self.assertContains(response, formrow1, html=True) self.assertContains(response, formrow2, html=True) return
def test_RenderRepeatGroupEdit(self): fieldrender = RenderRepeatGroup(render_repeatgroup.edit_group) rendered_text = fieldrender.render(self._get_repeatgroup_context()) # print "\n**************\n" # print rendered_text # print "\n**************\n" # replace runs of whitespace/newlines with single space: rendered_text = re.sub(r'\s+', " ", rendered_text) field_choices = ([ FieldChoice(id=""), FieldChoice(id="_field/Entity_comment", label="Comment"), FieldChoice(id="_field/Entity_id", label="Id"), FieldChoice(id="_field/Entity_label", label="Label"), FieldChoice(id="_field/Entity_see_also_r", label="See also"), FieldChoice(id="_field/Entity_type", label="Type"), FieldChoice(id="_field/Entity_uri", label="Entity URI") ]) expect_elements = ([ '''<div class="group-label small-2 columns"> <span>Fields</span> </div>''', '''<div class="row selectable">''', '''<div class="view-label small-12 medium-4 columns"> <span>Field ref</span> </div>''', '''<div class="view-label small-12 medium-4 columns"> <span>Property URI</span> </div>''', '''<div class="view-label small-12 medium-4 columns"> <span>Position/size</span> </div>''' # 1st field , '''<input type="checkbox" name="View_fields__select_fields"''' + ''' value="0" class="right" />''', re.sub( r'\s+', " ", render_choice_options("View_fields__0__View_field_sel", field_choices, "_field/Entity_id", placeholder="(field reference)")), '''<input type="text" size="64" name="View_fields__0__View_field_property"''' + ''' placeholder="(field URI or CURIE)"''' + ''' value=""/>''' # 2nd field , '''<input type="checkbox" name="View_fields__select_fields"''' + ''' value="1" class="right" />''', re.sub( r'\s+', " ", render_choice_options("View_fields__1__View_field_sel", field_choices, "_field/Entity_type", placeholder="(field reference)")), '''<input type="text" size="64" name="View_fields__1__View_field_property"''' + ''' placeholder="(field URI or CURIE)"''' + ''' value=""/>''' # 3rd field , '''<input type="checkbox" name="View_fields__select_fields"''' + ''' value="2" class="right" />''', re.sub( r'\s+', " ", render_choice_options("View_fields__2__View_field_sel", field_choices, "_field/Entity_label", placeholder="(field reference)")), '''<input type="text" size="64" name="View_fields__2__View_field_property"''' + ''' placeholder="(field URI or CURIE)"''' + ''' value="rdfs:label"/>''' # 4th field , '''<input type="checkbox" name="View_fields__select_fields"''' + ''' value="3" class="right" />''', re.sub( r'\s+', " ", render_choice_options("View_fields__3__View_field_sel", field_choices, "_field/Entity_comment", placeholder="(field reference)")), '''<input type="text" size="64" name="View_fields__3__View_field_property"''' + ''' placeholder="(field URI or CURIE)"''' + ''' value="rdfs:comment"/>''' # Buttons , '''<input type="submit" name="View_fields__remove" value="Remove selected field(s)" />''', '''<input type="submit" name="View_fields__add" value="Add field" />''' ]) for e in expect_elements: self.assertInIgnoreWS(e, rendered_text) return
def make_field_choices(options): return [FieldChoice(v, v, l) for v, l in options]
def update_options(opts): return update_choice_labels([ FieldChoice(o) if isinstance(o, (str, unicode)) else o for o in opts ])
for fid in range(4): item_field = item_fields[fid] head_field = head_fields[0]['row_field_descs'][fid] for fkey in ('field_id', 'field_name', 'field_label', 'field_property_uri', 'field_render_type', 'field_placement', 'field_value_type'): test.assertEqual(item_field[fkey], head_field[fkey]) # Check listed field values check_context_list_field_value(test, item_field, f[fid]) break else: test.fail("Field %s not found in context" % f[0]) return type_no_options = [FieldChoice('', label="(no options)")] def check_type_view_context_fields(test, response, action="", entity_id="", orig_entity_id=None, type_id="_type", type_label="(?type_label)", type_comment="(?type_comment)", type_uri="(?type_uri)", type_supertype_uris="", type_view="Default_view", type_view_options=None, type_list="Default_list",
def add_link_to_field_choice(fc, coll_id, default_type_id=None): type_id, entity_id = split_type_entity_id(fc.id, default_type_id=default_type_id) return fc.add_link(entity_url(coll_id, type_id, entity_id)) # ----------------------------------------------------------------------------- # # ----- Site-wide entities defined # # ----------------------------------------------------------------------------- # ----- Types ----- site_types = ([ FieldChoice("_type/_initial_values"), FieldChoice("_type/_coll", label="Collection"), FieldChoice("_type/_field", label="Field"), FieldChoice("_type/_group", label="Field group"), FieldChoice("_type/_list", label="List"), FieldChoice("_type/_type", label="Type"), FieldChoice("_type/_user", label="User permissions"), FieldChoice("_type/_view", label="View"), FieldChoice("_type/_vocab", label="Vocabulary namespace"), FieldChoice("_type/Default_type", label="Default record"), FieldChoice("_type/Enum_list_type", label="List display type"), FieldChoice("_type/Enum_render_type", label="Field render type"), FieldChoice("_type/Enum_value_mode", label="Field value mode") ])