Skip to content

Commit

Permalink
Added a some docs and crave-out for relative dates
Browse files Browse the repository at this point in the history
  • Loading branch information
muddi900 committed Mar 16, 2024
1 parent d2be25f commit 99da42d
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions gspread/worksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from .urls import WORKSHEET_DRIVE_URL
from .utils import (
DateTimeOption,
RelativeDate,
Dimension,
GridRangeType,
InsertDataOption,
Expand Down Expand Up @@ -3203,17 +3204,32 @@ def cut_range(

def add_validation(
self,
range: str,
source: str,
condition_type: ValidationConditionType,
*values,
*values: Iterable[Any | RelativeDate],
**kwargs,
) -> Any:
"""
Adds a data validation to any given ranges.
"""Adds a data validation rule to any given range.
.. note::
``condition_type`` values are explained here: `ConditionType`_
.._ConditionType: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#ConditionType
.. note::
``RealtiveDate`` values are explained here: ``_
.._RelativeDate: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#RelativeDate
:param str source: The A1 notation of the source range to move
:param condition_type: The sort of condition to apply.
:param values: List of condition values or RelativeDate.
"""
grid = a1_range_to_grid_range(range, self.id)
grid = a1_range_to_grid_range(source, self.id)

body = {
"requests": [
Expand All @@ -3224,14 +3240,19 @@ def add_validation(
"condition": {
"type": condition_type,
"values": [
{"userEnteredValue": value} for value in values
(
{"userEnteredValue": value}
if not isinstance(value, RelativeDate)
else {"relativeDate": value}
)
for value in values
],
}
},
**kwargs
**kwargs,
}
}
],
}

self.client.batch_update(self.spreadsheet_id, body)
self.client.batch_update(self.spreadsheet_id, body)

0 comments on commit 99da42d

Please sign in to comment.