Programming API Observation

Navigate

    An Observation represents an entry contributed by a user. Together with a Location, an observations forms a contribution.

    Attributes

    Parameter Type Description
    id int Identifies the observation in the database.
    location Location Geographic location of the observation.
    project Project Project the observation has been contributed to.
    category Category Category of the observation.
    status string Status of the observation. Must be one of active, draft review, pending, deleted. Defaults to the default_status of the contributions category.
    properties dict Key-value pairs of the observation’s attributes. Keys represent the key of the category’s fields.
    created_at datetime Date and time when the observation was created.
    creator User User who created the observation.
    updated_at datetime Date and time when the observation last updated.
    updator User User who last updated the observation.
    version int Version of the observation. Is increased every time the observation is updated.

    Methods

    validate_partial(category, data)

    Partially validates data against the category. A partial validation only validates against those fields that are present in data; if a field that is required is not provided it will be ignored. This method should be used to validate drafts only.

    Parameters
    category: Category
    Category the data is validated against.
    data: dict
    Data that is validated.
    Raises
    ValidationError
    If the provided data is invalid.
    Example use
    from geokey.contributions.models import Observation
    
    data = {
        'name': 'Buckingham Palace',
        'built-in': 1703
    }
    Contribution.validate_partial(category, data)
    

    validate_full(category, data)

    Validates the data against all fields defined for the category.

    Parameters
    category: Category
    Category the data is validated against.
    data: dict
    Data that is validated.
    Raises
    ValidationError
    If the provided data is invalid.
    Example use
    from geokey.contributions.models import Observation
    
    data = {
        'name': 'Buckingham Palace',
        'built-in': 1703
    }
    Contribution.validate_full(category, data)
    

    update(properties, updator, status=None)

    Updates the properties of the Contribution.

    Parameters
    properties: dict
    Attributes that are updated. This can contain only updated attributes, all other fields will not be changed.
    updator: User
    The user who updates the observation.
    status: string
    Optional. The new status for the contribution.
    Returns

    Observation

    delete()

    Deletes the contribution by setting its status to deleted.

    Creating a model instance

    Observation.create(properties=None, creator=None, location=None, category=None, project=None, status=None)

    Parameters
    properties: dict
    Attributes of the contribution.
    creator: User
    The user who creates the observation.
    location: Location
    Geographic location of the observation.
    category: Category
    Category of the observation.
    project: Project
    Project the observation is contributed to..
    status: string
    Optional. The new status for the observation.
    Parameters

    Observation

    Accessing model instances

    for_moderator(user)

    Returns all observations for moderators; That includes all observations in a project; except this with status='draft', which where not created by the given user.

    Parameters
    user: User
    User the observations are queried for.
    Returns

    django.db.models.query.QuerySet: List of Observation

    Example
    project.observations.for_moderator(user)
    

    for_viewer(user)

    Returns all observations for viewer, i.e. users who have no moderation permissions on the project.

    If the user is anonymous, it returns only observations with status='active' and status='review'

    If the user is not anonymous, it returns it returns only observations with status='active' and status='review' as well as status='pending' when the given user is creator of those observation.

    Parameters
    user: User
    User the observations are queried for.
    Returns

    django.db.models.query.QuerySet: List of Observation

    Example
    project.observations.for_viewer(user)
    

    search(query)

    Returns a subset of the QuerySet containing observations where one of the properties matches the given query.

    query: string
    The query that is filtered for.
    Returns

    django.db.models.query.QuerySet: List of Observation

    project.observations.search('Palace')