Project data (Views)

The models that these views work on can be found in Project data (Models)

Where the views are used (frontend)

  • viewer.views.SnapshotsView: the json data in the data field in this view is used by the reducers on the front-end to re-create the context of any page that a user saves to a project, or saves as a standalone snapshot. The PUT method of this view is what is used by the front-end button push of ‘save’ or ‘share’ in the menu bar of a target specific page to send the state of the page to the view so that the data is saved and accessed later. The data can be accessed either through an endpoint, or if the user is logged in when they save the session, as part of its associated project, all of which are listed on the landing page when a user is logged in. If the user is logged in and navigates to a specific project, the project navigator will appear on the bottom right-hand side as a tree, which the user can navigate through to access different project snapshots. Information such as who created the snapshot, its title and description are also displayed here.

  • viewer.views.SessionProjectsView: This view is used to create a project (collection of snaphots) when a user is logged in and clicks the ‘+’ button on the projects pane of the landing page. The GET method of this view is used to retrieve information about user-created projects, and display it in the projects pane of the landing page.

View details

class viewer.views.SnapshotsView(**kwargs)

Djagno view to retrieve information about user sessions (snapshots) (GET). Also used for saving session information (PUT, POST, PATCH)

url:

api/snapshots

queryset:

viewer.models.Snapshot.objects.filter()

filter class:

viewer.filters.SnapshotFilter

filter fields:
  • viewer.models.Snapshot.id - ?id=<int>

  • viewer.models.Snapshot.type - ?type=<str>

  • viewer.models.Snapshot.author - ?author=<str>

  • viewer.models.Snapshot.description ?description=<str>

  • viewer.models.Snapshot.created - ?created=<str>

  • viewer.models.Snapshot.data - ?data=<JSON str>

  • viewer.models.Snapshot.session_project_id - ?session_project_id=<int>

  • viewer.models.Snapshot.parent - ?parent=<int>

  • viewer.models.Snapshot.children - ?children=<list>

  • viewer.models.Snapshot.session_project - ?session_project=<int>

returns: JSON
  • id: id of the snapshot

  • type: type of snapshot

  • title: title of snapshot given by author

  • description: description of the snapshot given by author

  • created: timestamp for when the snapshot was created

  • data: json string describing data needed to reproduce state of the snapshot by the front-end

  • session_project: dict describing the project that the snapshot belongs to:
    • id: project id

    • title: project title

    • init_data: timestamp for when the project was initiated

    • description: description of the project given by the author

    • tags: tags given to the project by the author

    • target: id of the target that the project is associated with

    • author: name of the author who created the project

  • parent: parent snapshot id of the current snapshot

  • children: list of children ids of the current snapshot

example output:
"results": [
    {
        "id": 132,
        "type": "INIT",
        "title": "-- 2020-07-09 -- 16:01:35",
        "author": null,
        "description": "Snapshot generated by anonymous user",
        "created": "2020-07-09T20:01:36.901552Z",
        "data": '"{"apiReducers":{"target_id_list":[{"id":2,"title":"NUDT7A",'
        "session_project": {
            "id": 124,
            "title": "READ_ONLY",
            "init_date": "2020-07-09T20:01:35.715324Z",
            "description": "READ_ONLY",
            "tags": "[]",
            "target": 62,
            "author": null
        },
        "parent": null,
        "children": []
    },]
get_serializer_class()

Determine which serializer to use based on whether the request is a GET or a POST, PUT or PATCH request

Returns

  • if GET: viewer.serializers.SnapshotReadSerializer

  • if other: viewer.serializers.SnapshotWriteSerializer

Return type

Serializer (rest_framework.serializers.ModelSerializer)

class viewer.views.SessionProjectsView(**kwargs)

Djagno view to retrieve information about user projects (collection of sessions) (GET). Also used for saving project information (PUT, POST, PATCH)

url:

api/session-projects

queryset:

viewer.models.SessionProject.objects.filter()

filter fields:
  • viewer.models.SessionProject.title - ?title=<str>

  • viewer.models.SessionProject.init_date - ?date=<str>

  • viewer.models.SessionProject.description - ?description=<str>

  • viewer.models.SessionProject.target - ?target=<int>

  • viewer.models.SessionProject.author - ?author=<str>

  • viewer.models.SessionProject.tags - ?tags=<list>

returns: JSON
  • id: id of the project

  • target: dict of target info:
    • id: target id

    • title: name of the target protein

    • project_id: id of the project

    • protein_set: list of protein objects associated with the target

    • template_protein: link to the file used as the reference in fragalysis frontend

    • metadata: link to the target metadata file

    • zip_archive: link to the zip archive of uploaded files

  • author: name of the author that created the session

  • title: title for the project

  • init_date: timestamp for when the project was created

  • description: author defined description of the project

  • tags: list of tags given to the project by the author

example output:
"results": [
{
    "id": 122,
    "target": {
        "id": 62,
        "title": "Mpro",
        "project_id": [
            2
        ],
        "protein_set": [
            29281,
            29274,
            29259,
            29305,
            29250,
            ...,
        ],
        "template_protein": "/media/pdbs/Mpro-x10417_0_apo.pdb",
        "metadata": "http://fragalysis.diamond.ac.uk/media/metadata/metadata_2FdP5OJ.csv",
        "zip_archive": "http://fragalysis.diamond.ac.uk/media/targets/Mpro.zip"
    },
    "author": null,
    "title": "READ_ONLY",
    "init_date": "2020-07-09T19:52:10.506119Z",
    "description": "READ_ONLY",
    "tags": "[]"
},]
get_serializer_class()

Determine which serializer to use based on whether the request is a GET or a POST, PUT or PATCH request

Returns

  • if GET: viewer.serializers.SessionProjectReadSerializer

  • if other: viewer.serializers.SessionProjectWriteSerializer

Return type

Serializer (rest_framework.serializers.ModelSerializer)