Refactored to use kwarg

This commit is contained in:
Ken Tsang
2017-08-01 11:40:26 +01:00
parent 615d80cd41
commit 93eab4ca5f
5 changed files with 100 additions and 19 deletions

View File

@@ -5,8 +5,8 @@ from flask import current_app
from notifications_utils.s3 import s3upload as utils_s3upload
FILE_LOCATION_STRUCTURE = 'service-{}-notify/{}.csv'
TEMP_TAG = 'temp-{}_'
LOGO_LOCATION_STRUCTURE = '{}{}-{}'
TEMP_TAG = 'temp-{user_id}_'
LOGO_LOCATION_STRUCTURE = '{temp}{unique_id}-{filename}'
def s3upload(service_id, filedata, region):
@@ -35,8 +35,11 @@ def s3download(service_id, upload_id):
def upload_logo(filename, filedata, region, user_id):
upload_id = str(uuid.uuid4())
upload_file_name = LOGO_LOCATION_STRUCTURE.format(TEMP_TAG.format(user_id), upload_id, filename)
upload_file_name = LOGO_LOCATION_STRUCTURE.format(
temp=TEMP_TAG.format(user_id=user_id),
unique_id=str(uuid.uuid4()),
filename=filename
)
utils_s3upload(filedata=filedata,
region=region,
bucket_name=current_app.config['LOGO_UPLOAD_BUCKET_NAME'],
@@ -47,7 +50,7 @@ def upload_logo(filename, filedata, region, user_id):
def persist_logo(filename, user_id):
try:
if filename.startswith(TEMP_TAG.format(user_id)):
if filename.startswith(TEMP_TAG.format(user_id=user_id)):
persisted_filename = filename[len(TEMP_TAG.format(user_id)):]
else:
return filename

View File

@@ -65,7 +65,7 @@ def manage_org(logo=None):
user_id=session["user_id"]
)
if logo and logo.startswith(TEMP_TAG.format(session['user_id'])):
if logo and logo.startswith(TEMP_TAG.format(user_id=session['user_id'])):
delete_temp_file(logo)
return redirect(
@@ -84,7 +84,6 @@ def manage_org(logo=None):
org_id = resp['data']['id']
return redirect(url_for('.organisations', organisation_id=org_id))
if org:
form.name.data = org['name']
form.colour.data = org['colour']

View File

@@ -26,7 +26,7 @@ class OrganisationsClient(NotifyAdminAPIClient):
"name": name,
"colour": colour
}
return self.post("/organisation", data)
return self.post(url="/organisation", data=data)
def update_organisation(self, org_id, logo, name, colour):
data = {
@@ -34,4 +34,4 @@ class OrganisationsClient(NotifyAdminAPIClient):
"name": name,
"colour": colour
}
return self.post("/organisation/{}".format(org_id), data)
return self.post(url="/organisation/{}".format(org_id), data=data)