diff --git a/contentcuration/contentcuration/utils/google_drive.py b/contentcuration/contentcuration/utils/google_drive.py deleted file mode 100644 index f8430a55c7..0000000000 --- a/contentcuration/contentcuration/utils/google_drive.py +++ /dev/null @@ -1,80 +0,0 @@ -import google.auth -import gspread - - -def colnum_string(n): - """ colnum_string: get column letter - Args: n (int) index of column to get letter for - Returns: str letter(s) of column - """ - string = "" - while n > 0: - n, remainder = divmod(n - 1, 26) - string = chr(65 + remainder) + string - return string - - -def get_credentials(): - scopes = ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive'] - credentials, _project = google.auth.default(scopes=scopes) - return credentials - - -class GoogleClient(): - - def __init__(self, *args, **kwargs): - credentials = get_credentials() - - self.client = gspread.authorize(credentials) - - def get(self, spreadsheet_id): - """ get: returns spreadsheet matching id - Args: spreadsheet_id (str) ID of spreadsheet - Returns: Spreadsheet (see https://github.com/burnash/gspread/blob/master/gspread/models.py#L77) - """ - return self.client.open_by_key(spreadsheet_id) - - def get_length(self, worksheet): - """ get_length: get number of non-empty rows in a worksheet - Args: worksheet (Worksheet) - Returns: number of rows - - Note: need to iterate through worksheet as all sheets automatically start with 1000 rows - Start with the end of the list in case there are blank rows in the middle - """ - values_list = worksheet.col_values(1) # Get values from first column - for idx, val in enumerate(reversed(values_list)): - if val: - return len(values_list) - idx - - -def add_row_to_sheet(sheet_id, values, worksheet=None): - """ add_row_to_sheet: appends a row to a worksheet - Args: - sheet_id (str) Sheet id to append to - values ([str]) List of values to write to row - worksheet (Worksheet) Worksheet to append row to (if empty, appends to first worksheet) - Returns: None - """ - client = GoogleClient() # Open Google client to read from - sheet = client.get(sheet_id) - worksheet = worksheet or sheet.sheet1 - num_rows = client.get_length(worksheet) - - # Append row if reached the end of the worksheet - # Otherwise, update the last row - # Note: using this method as insert_row takes too long - if num_rows + 1 > worksheet.row_count: - worksheet.append_row(values) - else: - update_row = num_rows + 1 - - # Get range of cells - cell_list = worksheet.range('A{row}:{col}{row}'.format(row=update_row, col=colnum_string(worksheet.col_count))) - - for i, cell in enumerate(cell_list): - if i >= len(values): - break - cell.value = values[i] - - worksheet.update_cells(cell_list) diff --git a/contentcuration/contentcuration/views/settings.py b/contentcuration/contentcuration/views/settings.py index f956db9b32..f41b6ac926 100644 --- a/contentcuration/contentcuration/views/settings.py +++ b/contentcuration/contentcuration/views/settings.py @@ -35,7 +35,6 @@ from contentcuration.utils.messages import get_messages from contentcuration.views.base import current_user_for_context from contentcuration.viewsets.channel import SettingsChannelSerializer -# from contentcuration.utils.google_drive import add_row_to_sheet ISSUE_UPDATE_DATE = datetime(2018, 10, 29) @@ -172,36 +171,6 @@ class StorageSettingsView(PostFormMixin, FormView): form_class = StorageRequestForm def form_valid(self, form): - # Send email with storage request - # name, email, storage requested, date of request, number of resources, - # average resource size, kind of content, licenses, potential public - # channels, audience, uploading for, message, time constraint - # values = [ - # "{} {}".format(self.request.user.first_name, self.request.user.last_name), - # self.request.user.email, - # form.cleaned_data.get('storage'), - # datetime.now().strftime("%Y-%m-%d %H:%M:%S"), - # form.cleaned_data.get('resource_count'), - # form.cleaned_data.get('resource_size'), - # form.cleaned_data.get('kind'), - # form.cleaned_data.get('creators'), - # form.cleaned_data.get('sample_link'), - # form.cleaned_data.get('license'), - # form.cleaned_data.get("public"), - # form.cleaned_data.get('audience'), - # form.cleaned_data.get('location'), - # form.cleaned_data.get('import_count'), - # form.cleaned_data.get('uploading_for'), - # form.cleaned_data.get('organization_type'), - # form.cleaned_data.get('message'), - # form.cleaned_data.get('time_constraint'), - # ] - # Write to storage request sheet - # In production: https://docs.google.com/spreadsheets/d/1uC1nsJPx_5g6pQT6ay0qciUVya0zUFJ8wIwbsTEh60Y/edit#gid=0 - # Debug mode: https://docs.google.com/spreadsheets/d/16X6zcFK8FS5t5tFaGpnxbWnWTXP88h4ccpSpPbyLeA8/edit#gid=0 - # Comment out for now as there is an authentication issue - # add_row_to_sheet(ccsettings.GOOGLE_STORAGE_REQUEST_SHEET, values) - channels = [c for c in form.cleaned_data["public"].split(", ") if c] message = render_to_string( "settings/storage_request_email.txt", diff --git a/requirements-dev.txt b/requirements-dev.txt index e0449fe50f..29f7d6c56e 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -366,7 +366,6 @@ ujson==4.0.2 # python-lsp-server uritemplate==3.0.1 # via - # -c requirements.txt # coreapi # drf-yasg urllib3==1.26.5 diff --git a/requirements.in b/requirements.in index 2f9511d6cc..91e7946e0a 100644 --- a/requirements.in +++ b/requirements.in @@ -24,8 +24,6 @@ google-cloud-storage django-s3-storage==0.13.4 requests>=2.20.0 google-cloud-core -gspread==3.6.0 -google-api-python-client django-db-readonly==0.7.0 oauth2client django-mathfilters diff --git a/requirements.txt b/requirements.txt index 2f69ec90d3..a66c791ff3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -104,26 +104,15 @@ future==0.18.2 # via -r requirements.in google-api-core[grpc]==1.27.0 # via - # google-api-python-client # google-cloud-core # google-cloud-error-reporting # google-cloud-kms # google-cloud-logging -google-api-python-client==2.4.0 - # via -r requirements.in google-auth==1.30.0 # via # google-api-core - # google-api-python-client - # google-auth-httplib2 - # google-auth-oauthlib # google-cloud-core # google-cloud-storage - # gspread -google-auth-httplib2==0.1.0 - # via google-api-python-client -google-auth-oauthlib==0.4.4 - # via gspread google-cloud-core==1.7.3 # via # -r requirements.in @@ -152,8 +141,6 @@ grpcio==1.37.1 # google-api-core # googleapis-common-protos # grpc-google-iam-v1 -gspread==3.6.0 - # via -r requirements.in gunicorn==20.1.0 # via -r requirements.in html5lib==1.1 @@ -161,8 +148,6 @@ html5lib==1.1 httplib2==0.19.1 # via # django-postmark - # google-api-python-client - # google-auth-httplib2 # oauth2client idna==2.10 # via requests @@ -184,8 +169,6 @@ newrelic==6.2.0.156 # via -r requirements.in oauth2client==4.1.3 # via -r requirements.in -oauthlib==3.1.0 - # via requests-oauthlib packaging==20.9 # via google-api-core pathlib==1.0.1 @@ -253,10 +236,6 @@ requests==2.25.1 # -r requirements.in # google-api-core # google-cloud-storage - # gspread - # requests-oauthlib -requests-oauthlib==1.3.0 - # via google-auth-oauthlib rsa==4.7.2 # via # google-auth @@ -269,9 +248,7 @@ six==1.16.0 # via # click-repl # google-api-core - # google-api-python-client # google-auth - # google-auth-httplib2 # google-cloud-core # google-resumable-media # grpcio @@ -284,8 +261,6 @@ six==1.16.0 # python-utils sqlparse==0.4.1 # via django -uritemplate==3.0.1 - # via google-api-python-client urllib3==1.26.5 # via # botocore