def render_linked_field(context, linked_object, field_name, containing_object): if linked_object is None: return "Unable to get linked object from %s" % getattr(containing_object, field_name) templates = [model_name(x) + '/' + field_name + '_linked_view.html' for x in fedora_user_classes(containing_object)] # noinspection PyProtectedMember fieldtype = containing_object._meta.fields_by_name[field_name] for y in fedora_user_classes(containing_object): templates.extend([ '{0}/{1}_linked_view.html'.format(model_name(y), model_name(x)) for x in fedora_user_classes(linked_object) ]) templates.extend([ '{0}/{1}_linked_view.html'.format(fullname(fieldtype.__class__).replace('.', '/'), model_name(x)) for x in fedora_user_classes(linked_object) ]) templates.append('{0}_linked_view.html'.format(fullname(fieldtype.__class__).replace('.', '/'))) templates.append('fedoralink/partials/linked_view.html') print(templates) context = Context(context) # noinspection PyProtectedMember context['field'] = containing_object._meta.fields_by_name[field_name] context['value'] = linked_object context['containing_object'] = containing_object chosen_template = select_template(templates) return chosen_template.template.render(context)
def render_linked_field(context, linked_object, field_name, containing_object): if linked_object is None: return "Unable to get linked object from %s" % getattr(containing_object, field_name) templates = [model_name(x) + '/' + field_name + '_linked_view.html' for x in fedora_user_classes(containing_object)] # noinspection PyProtectedMember fieldtype = containing_object._meta.fields_by_name[field_name] for y in fedora_user_classes(containing_object): templates.extend([ '{0}/{1}_linked_view.html'.format(model_name(y), model_name(x)) for x in fedora_user_classes(linked_object) ]) templates.extend([ '{0}/{1}_linked_view.html'.format(fullname(fieldtype.__class__).replace('.', '/'), model_name(x)) for x in fedora_user_classes(linked_object) ]) templates.append('{0}_linked_view.html'.format(fullname(fieldtype.__class__).replace('.', '/'))) templates.append('fedoralink/partials/linked_view.html') # print(templates) context = Context(context) # noinspection PyProtectedMember context['field'] = containing_object._meta.fields_by_name[field_name] context['value'] = linked_object context['containing_object'] = containing_object chosen_template = select_template(templates) return chosen_template.template.render(context)
def render_links(context, fedora_object, link_name): templates = [fullname(x).replace('.', '/') + '/' + link_name + '_link.html' for x in inspect.getmro(type(fedora_object))] templates.append('fedoralink_ui/partials/link.html') context = Context(context) context['links'] = getattr(fedora_object, link_name) chosen_template = select_template(templates) return chosen_template.template.render(context)
def render_links(context, fedora_object, link_name): templates = [fullname(x).replace('.', '/') + '/' + link_name + '_link.html' for x in inspect.getmro(type(fedora_object))] templates.append('fedoralink/partials/link.html') context = Context(context) context['links'] = getattr(fedora_object, link_name) chosen_template = select_template(templates) return chosen_template.template.render(context)
def get_field_template_string(fedora_object, field_name): if hasattr(fedora_object, '_meta'): field_fedoralink_type = fullname( fedora_object._meta.fields_by_name[field_name].__class__) # noinspection PyProtectedMember rdf_types = fedora_object._meta.rdf_types return FedoraTemplateCache._get_field_template_string_internal( field_name, rdf_types, field_fedoralink_type) else: return None
def classname(obj): return fullname(obj.__class__)
def get_model_class_from_fullname(classname): for model in FedoraTypeManager.models: if fullname(model) == classname: return model raise TypeError('Class with name %s is not registered as a model' % classname)