Skip to content

Commit

Permalink
Merge pull request #912 from burnash/feature/split_files
Browse files Browse the repository at this point in the history
split files `models.py` and `test.py`
  • Loading branch information
lavigne958 authored Aug 27, 2021
2 parents 42388be + 6832e04 commit 39d1ecb
Show file tree
Hide file tree
Showing 12 changed files with 1,926 additions and 1,914 deletions.
4 changes: 3 additions & 1 deletion gspread/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

from .auth import oauth, service_account, service_account_from_dict
from .client import Client
from .models import Spreadsheet, Worksheet, Cell
from .spreadsheet import Spreadsheet
from .worksheet import Worksheet
from .cell import Cell

from .exceptions import (
GSpreadException,
Expand Down
82 changes: 82 additions & 0 deletions gspread/cell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*-

"""
gspread.models
~~~~~~~~~~~~~~
This module contains common cells' models.
"""

from .utils import (
a1_to_rowcol,
numericise,
rowcol_to_a1,
)


class Cell(object):
"""An instance of this class represents a single cell
in a :class:`worksheet <gspread.models.Worksheet>`.
"""

def __init__(self, row, col, value=""):
self._row = row
self._col = col

#: Value of the cell.
self.value = value

@classmethod
def from_address(cls, label, value=""):
return cls(*a1_to_rowcol(label), value=value)

def __repr__(self):
return "<%s R%sC%s %s>" % (
self.__class__.__name__,
self.row,
self.col,
repr(self.value),
)

@property
def row(self):
"""Row number of the cell."""
return self._row

@property
def col(self):
"""Column number of the cell."""
return self._col

@property
def numeric_value(self):
numeric_value = numericise(self.value, default_blank=None)

# if could not convert, return None
if type(numeric_value) == int or type(numeric_value) == float:
return numeric_value
else:
return None

@property
def address(self):
"""Cell address in A1 notation."""
return rowcol_to_a1(self.row, self.col)

@property
def input_value(self):
""".. deprecated:: 2.0
This feature is not supported in Sheets API v4.
"""
import warnings

warnings.warn(
"Cell.input_value is deprecated, "
"this feature is not supported in Sheets API v4. "
"Please use `value_render_option` when you "
"Retrieve `Cell` objects (e.g. in `Worksheet.range()` method).",
DeprecationWarning,
stacklevel=2,
)
2 changes: 1 addition & 1 deletion gspread/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from google.auth.transport.requests import AuthorizedSession

from .exceptions import APIError, SpreadsheetNotFound
from .models import Spreadsheet
from .spreadsheet import Spreadsheet
from .utils import convert_credentials, extract_id_from_url, finditem

from .urls import (
Expand Down
Loading

0 comments on commit 39d1ecb

Please sign in to comment.