diff --git a/client/python/cryoet_data_portal/src/cryoet_data_portal/_models.py b/client/python/cryoet_data_portal/src/cryoet_data_portal/_models.py index 2cfa1d120..02c268240 100644 --- a/client/python/cryoet_data_portal/src/cryoet_data_portal/_models.py +++ b/client/python/cryoet_data_portal/src/cryoet_data_portal/_models.py @@ -101,7 +101,9 @@ def find( """ Examples: >>> alignments = Alignment.find(client, query_filters=[Alignment.run.name == "TS_026"]) + Get all results for this type: + >>> alignments = Alignment.find(client) """ return super(Alignment, cls).find(client, query_filters) @@ -113,8 +115,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an Alignment by ID: + >>> alignment = Alignment.get_by_id(client, 1) - print(alignment.name) + >>> print(alignment.id) """ return super(Alignment, cls).get_by_id(client, id) @@ -208,7 +211,9 @@ def find( """ Examples: >>> annotations = Annotation.find(client, query_filters=[Annotation.run.name == "TS_026"]) + Get all results for this type: + >>> annotations = Annotation.find(client) """ return super(Annotation, cls).find(client, query_filters) @@ -220,8 +225,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an Annotation by ID: + >>> annotation = Annotation.get_by_id(client, 1) - print(annotation.name) + >>> print(annotation.id) """ return super(Annotation, cls).get_by_id(client, id) @@ -309,7 +315,9 @@ def find( """ Examples: >>> annotation_authors = AnnotationAuthor.find(client, query_filters=[AnnotationAuthor.annotation.run.name._in(['TS_026', 'TS_027']), AnnotationAuthor.annotation.object_name.ilike('%membrane%')]) + Get all results for this type: + >>> annotation_authors = AnnotationAuthor.find(client) """ return super(AnnotationAuthor, cls).find(client, query_filters) @@ -321,8 +329,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an AnnotationAuthor by ID: + >>> annotation_author = AnnotationAuthor.get_by_id(client, 1) - print(annotation_author.name) + >>> print(annotation_author.name) """ return super(AnnotationAuthor, cls).get_by_id(client, id) @@ -381,7 +390,9 @@ def find( ): """ Examples: + Get all results for this type: + >>> annotation_files = AnnotationFile.find(client) """ return super(AnnotationFile, cls).find(client, query_filters) @@ -393,8 +404,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an AnnotationFile by ID: + >>> annotation_file = AnnotationFile.get_by_id(client, 1) - print(annotation_file.name) + >>> print(annotation_file.id) """ return super(AnnotationFile, cls).get_by_id(client, id) @@ -441,7 +453,9 @@ def find( """ Examples: >>> annotation_method_links = AnnotationMethodLink.find(client, query_filters=[AnnotationMethodLink.annotation.run.name._in(['TS_026', 'TS_027']), AnnotationMethodLink.annotation.object_name.ilike('%membrane%')]) + Get all results for this type: + >>> annotation_method_links = AnnotationMethodLink.find(client) """ return super(AnnotationMethodLink, cls).find(client, query_filters) @@ -453,8 +467,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an AnnotationMethodLink by ID: + >>> annotation_method_link = AnnotationMethodLink.get_by_id(client, 1) - print(annotation_method_link.name) + >>> print(annotation_method_link.name) """ return super(AnnotationMethodLink, cls).get_by_id(client, id) @@ -496,7 +511,9 @@ def find( """ Examples: >>> annotation_shapes = AnnotationShape.find(client, query_filters=[AnnotationShape.annotation.run.name._in(['TS_026', 'TS_027']), AnnotationShape.annotation.object_name.ilike('%membrane%')]) + Get all results for this type: + >>> annotation_shapes = AnnotationShape.find(client) """ return super(AnnotationShape, cls).find(client, query_filters) @@ -508,8 +525,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an AnnotationShape by ID: + >>> annotation_shape = AnnotationShape.get_by_id(client, 1) - print(annotation_shape.name) + >>> print(annotation_shape.id) """ return super(AnnotationShape, cls).get_by_id(client, id) @@ -602,7 +620,9 @@ def find( ): """ Examples: + Get all results for this type: + >>> datasets = Dataset.find(client) """ return super(Dataset, cls).find(client, query_filters) @@ -614,8 +634,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an Dataset by ID: + >>> dataset = Dataset.get_by_id(client, 1) - print(dataset.name) + >>> print(dataset.id) """ return super(Dataset, cls).get_by_id(client, id) @@ -676,8 +697,11 @@ def find( """ Examples: Filter dataset authors by attributes, including attributes in related models: + >>> dataset_authors = DatasetAuthor.find(client, query_filters=[DatasetAuthor.name == "TS_026", DatasetAuthor.dataset.id == 10000]) + Get all results for this type: + >>> dataset_authors = DatasetAuthor.find(client) """ return super(DatasetAuthor, cls).find(client, query_filters) @@ -689,8 +713,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an DatasetAuthor by ID: + >>> dataset_author = DatasetAuthor.get_by_id(client, 1) - print(dataset_author.name) + >>> print(dataset_author.name) """ return super(DatasetAuthor, cls).get_by_id(client, id) @@ -728,8 +753,11 @@ def find( """ Examples: Filter dataset fundings by attributes, including attributes in related models: + >>> dataset_fundings = DatasetFunding.find(client, query_filters=[DatasetFunding.dataset.id == 10000]) + Get all results for this type: + >>> dataset_fundings = DatasetFunding.find(client) """ return super(DatasetFunding, cls).find(client, query_filters) @@ -741,8 +769,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an DatasetFunding by ID: + >>> dataset_funding = DatasetFunding.get_by_id(client, 1) - print(dataset_funding.name) + >>> print(dataset_funding.id) """ return super(DatasetFunding, cls).get_by_id(client, id) @@ -817,7 +846,9 @@ def find( ): """ Examples: + Get all results for this type: + >>> depositions = Deposition.find(client) """ return super(Deposition, cls).find(client, query_filters) @@ -829,8 +860,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an Deposition by ID: + >>> deposition = Deposition.get_by_id(client, 1) - print(deposition.name) + >>> print(deposition.id) """ return super(Deposition, cls).get_by_id(client, id) @@ -881,7 +913,9 @@ def find( ): """ Examples: + Get all results for this type: + >>> deposition_authors = DepositionAuthor.find(client) """ return super(DepositionAuthor, cls).find(client, query_filters) @@ -893,8 +927,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an DepositionAuthor by ID: + >>> deposition_author = DepositionAuthor.get_by_id(client, 1) - print(deposition_author.name) + >>> print(deposition_author.name) """ return super(DepositionAuthor, cls).get_by_id(client, id) @@ -929,7 +964,9 @@ def find( ): """ Examples: + Get all results for this type: + >>> deposition_types = DepositionType.find(client) """ return super(DepositionType, cls).find(client, query_filters) @@ -941,8 +978,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an DepositionType by ID: + >>> deposition_type = DepositionType.get_by_id(client, 1) - print(deposition_type.name) + >>> print(deposition_type.id) """ return super(DepositionType, cls).get_by_id(client, id) @@ -992,7 +1030,9 @@ def find( """ Examples: >>> frames = Frame.find(client, query_filters=[Frame.run.name == "TS_026"]) + Get all results for this type: + >>> frames = Frame.find(client) """ return super(Frame, cls).find(client, query_filters) @@ -1004,8 +1044,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an Frame by ID: + >>> frame = Frame.get_by_id(client, 1) - print(frame.name) + >>> print(frame.id) """ return super(Frame, cls).get_by_id(client, id) @@ -1043,7 +1084,9 @@ def find( """ Examples: >>> frame_acquisition_files = FrameAcquisitionFile.find(client, query_filters=[FrameAcquisitionFile.run.name == "TS_026"]) + Get all results for this type: + >>> frame_acquisition_files = FrameAcquisitionFile.find(client) """ return super(FrameAcquisitionFile, cls).find(client, query_filters) @@ -1055,8 +1098,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an FrameAcquisitionFile by ID: + >>> frame_acquisition_file = FrameAcquisitionFile.get_by_id(client, 1) - print(frame_acquisition_file.name) + >>> print(frame_acquisition_file.id) """ return super(FrameAcquisitionFile, cls).get_by_id(client, id) @@ -1094,7 +1138,9 @@ def find( """ Examples: >>> gain_files = GainFile.find(client, query_filters=[GainFile.run.name == "TS_026"]) + Get all results for this type: + >>> gain_files = GainFile.find(client) """ return super(GainFile, cls).find(client, query_filters) @@ -1106,8 +1152,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an GainFile by ID: + >>> gain_file = GainFile.get_by_id(client, 1) - print(gain_file.name) + >>> print(gain_file.id) """ return super(GainFile, cls).get_by_id(client, id) @@ -1152,7 +1199,9 @@ def find( ): """ Examples: + Get all results for this type: + >>> per_section_alignment_parameters = PerSectionAlignmentParameters.find(client) """ return super(PerSectionAlignmentParameters, cls).find(client, query_filters) @@ -1164,8 +1213,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an PerSectionAlignmentParameters by ID: + >>> per_section_alignment_parameters = PerSectionAlignmentParameters.get_by_id(client, 1) - print(per_section_alignment_parameters.name) + >>> print(per_section_alignment_parameters.id) """ return super(PerSectionAlignmentParameters, cls).get_by_id(client, id) @@ -1229,9 +1279,12 @@ def find( """ Examples: Filter runs by attributes, including attributes in related models: + >>> runs = Run.find(client, query_filters=[Run.name == "TS_026", Run.dataset.id == 10000]) >>> runs = Run.find(client, query_filters=[Run.name._in(['TS_026', 'TS_027']), Run.annotations.object_name.ilike('%membrane%')]) + Get all results for this type: + >>> runs = Run.find(client) """ return super(Run, cls).find(client, query_filters) @@ -1243,8 +1296,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an Run by ID: + >>> run = Run.get_by_id(client, 1) - print(run.name) + >>> print(run.name) """ return super(Run, cls).get_by_id(client, id) @@ -1359,7 +1413,9 @@ def find( """ Examples: >>> tilt_series = TiltSeries.find(client, query_filters=[TiltSeries.run.name == "TS_026"]) + Get all results for this type: + >>> tilt_series = TiltSeries.find(client) """ return super(TiltSeries, cls).find(client, query_filters) @@ -1371,8 +1427,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an TiltSeries by ID: + >>> tilt_series = TiltSeries.get_by_id(client, 1) - print(tilt_series.name) + >>> print(tilt_series.id) """ return super(TiltSeries, cls).get_by_id(client, id) @@ -1531,7 +1588,9 @@ def find( """ Examples: >>> tomograms = Tomogram.find(client, query_filters=[Tomogram.run.name == "TS_026"]) + Get all results for this type: + >>> tomograms = Tomogram.find(client) """ return super(Tomogram, cls).find(client, query_filters) @@ -1543,8 +1602,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an Tomogram by ID: + >>> tomogram = Tomogram.get_by_id(client, 1) - print(tomogram.name) + >>> print(tomogram.name) """ return super(Tomogram, cls).get_by_id(client, id) @@ -1643,7 +1703,9 @@ def find( ): """ Examples: + Get all results for this type: + >>> tomogram_authors = TomogramAuthor.find(client) """ return super(TomogramAuthor, cls).find(client, query_filters) @@ -1655,8 +1717,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an TomogramAuthor by ID: + >>> tomogram_author = TomogramAuthor.get_by_id(client, 1) - print(tomogram_author.name) + >>> print(tomogram_author.name) """ return super(TomogramAuthor, cls).get_by_id(client, id) @@ -1708,7 +1771,9 @@ def find( """ Examples: >>> tomogram_voxel_spacings = TomogramVoxelSpacing.find(client, query_filters=[TomogramVoxelSpacing.run.name == "TS_026"]) + Get all results for this type: + >>> tomogram_voxel_spacings = TomogramVoxelSpacing.find(client) """ return super(TomogramVoxelSpacing, cls).find(client, query_filters) @@ -1720,8 +1785,9 @@ def get_by_id(cls, client: Client, id: int): """ Examples: Get an TomogramVoxelSpacing by ID: + >>> tomogram_voxel_spacing = TomogramVoxelSpacing.get_by_id(client, 1) - print(tomogram_voxel_spacing.name) + >>> print(tomogram_voxel_spacing.id) """ return super(TomogramVoxelSpacing, cls).get_by_id(client, id) diff --git a/client/python/cryoet_data_portal/src/cryoet_data_portal/templates/Model.jinja2 b/client/python/cryoet_data_portal/src/cryoet_data_portal/templates/Model.jinja2 index 9bd54a9e7..73bd60242 100644 --- a/client/python/cryoet_data_portal/src/cryoet_data_portal/templates/Model.jinja2 +++ b/client/python/cryoet_data_portal/src/cryoet_data_portal/templates/Model.jinja2 @@ -20,11 +20,12 @@ class {{ model.name }}(Model): Examples: {% if model.fields | selectattr("name", "==", "dataset") | list | length %} Filter {{ model.plural }} by attributes, including attributes in related models: - {% if model.fields | selectattr("name", "==", "name") | list | length %} + + {% if model.fields | selectattr("name", "==", "name") | list | length %} >>> {{model.plural_underscores}} = {{ model.name }}.find(client, query_filters=[{{model.name}}.name == "TS_026", {{model.name}}.dataset.id == 10000]) - {% else %} + {% else %} >>> {{model.plural_underscores}} = {{ model.name }}.find(client, query_filters=[{{model.name}}.dataset.id == 10000]) - {% endif %} + {% endif %} {% endif %} {% if model.name == "Run" %} >>> {{model.plural_underscores}} = {{ model.name }}.find(client, query_filters=[{{model.name}}.name._in(['TS_026', 'TS_027']), {{model.name}}.annotations.object_name.ilike('%membrane%')]) @@ -35,7 +36,9 @@ class {{ model.name }}(Model): {% if model.fields | selectattr("name", "==", "annotation") | list | length %} >>> {{model.plural_underscores}} = {{ model.name }}.find(client, query_filters=[{{model.name}}.annotation.run.name._in(['TS_026', 'TS_027']), {{model.name}}.annotation.object_name.ilike('%membrane%')]) {% endif %} + Get all results for this type: + >>> {{model.plural_underscores}} = {{ model.name }}.find(client) """ return super({{ model.name }}, cls).find(client, query_filters) @@ -47,11 +50,17 @@ class {{ model.name }}(Model): """ Examples: Get an {{ model.name }} by ID: + >>> {{ model.model_name_underscores }} = {{ model.name }}.get_by_id(client, 1) - print({{ model.model_name_underscores }}.name) + {% if model.fields | selectattr("name", "==", "name") | list | length %} + >>> print({{ model.model_name_underscores }}.name) + {% else %} + >>> print({{ model.model_name_underscores }}.id) + {% endif %} """ return super({{ model.name}}, cls).get_by_id(client, id) + get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ )