Programming API Category

Navigate

    A category is represents a data type in GeoKey. Each contribution has a category that defines “what” that contribution is. A set of fields is assigned to each category that structure the data that is being collected for contributions of a category.

    Parameter Type Description
    id int Identifies the category in the database.
    name string Short title of the category.
    description string Longer description about the category.
    project Project The project this category is assigned to.
    created_at datetime Date and time when the category was created.
    creator User The user who created the category
    order int Position at which the category should be displayed in the list of the project’s categories.
    status string Current status of the category, must be one of active, inactive or deleted. Defaults to active.
    display_field Field Field that is used to display contributions in a list. That field should be a descriptive field, such as a name.
    expiry_field Field Field that is used to set the expiry date for contributions.
    default_status string Default status that is assigned to all contributions of that category when they are created. Must be one of active or pending. Defaults to pending.
    colour string Hex code defining the colour that is used to display contributions of that category on the map.
    symbol File An image file that is used to display contributions of that category on the map.
    fields QuerySet List of fields assigned to this category.

    Methods

    re_order_fields(order)

    Re-orders the fields of the category according to the order provided. order is a list of field ids.

    Parameters
    order: list
    List of field ids, in the desired order.
    Example
        category.re_order_fields([1, 3, 10, 2])
    

    delete()

    Deletes the category by setting its status to deleted.

    Creating a category instance

    Example use
    Category.objects.create(
        name='Category',
        description='This is a category',
        project=project,
        creator=user,
        default_status='active',
        colour='#fff000',
        symbol=file
    )
    
    Parameters
    name: string
    Title for the category.
    description: string
    Optional. A long-form description for the category
    project: Project
    Project this category will be assigned to.
    creator: User
    User, who creates the category.
    default_status: string
    Optional. Default status of the category. Must be one of `active` or `pending`.
    colour: string
    Optional. Hex code of the categories' display colour.
    symbol: File
    Optional. An image that is used to display contributions of that category on the map.
    Returns

    Category

    Accessing model instances

    get_list(user, project_id)

    Returns a list of categories for a project that the user can access.

    Parameters
    user: User
    User the categories are queried for.
    project_id: integer
    Identifies the project in the database.
    Returns

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

    get_single(user, project_id, category_id)

    Returns a single category.

    Parameters
    user: User
    User the category is queried for.
    project_id: integer
    Identifies the project in the database.
    category_id: integer
    Identifies the category in the database.
    Returns

    Category

    Raises
    Category.DoesNotExist
    If the category was not found in the data base.
    PermissionDenied
    If the category can not be accessed by the user; e.g., the category is inactive or the user is not an admin of the project.

    as_admin(user, project_id, category_id)

    Returns a single category if the user is admin of the project.

    Parameters
    user: User
    User the category is queried for.
    project_id: integer
    Identifies the project in the database.
    category_id: integer
    Identifies the category in the database.
    Returns

    Category

    Raises
    Category.DoesNotExist
    If the category was not found in the data base.
    PermissionDenied
    If the user is not an administrator of the project.