Created
September 5, 2018 00:41
-
-
Save adambom/6be559a9563f5465a5c547086f21f29a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def save_sales_entries(form_values): | |
sanitized_form_values = sanitize_form_values(form_values) | |
validate_form_values(sanitized_form_values, raise_exeption=True) | |
normalized_sales_entries = normalize_form_entries( | |
sanitized_form_values.entries | |
) | |
return sales_api.enter_monthly_sales(normalized_sales_entries) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def save_sales_entries(form_values): | |
if form_values.last_name: | |
full_name = form_values.first_name | |
else: | |
full_name = ' '.join([form_values.first_name, form_values.last_name]) | |
if form_values.date_of_birth is None: | |
raise Exception | |
date_of_birth = form_values.date_of_birth.strftime('%Y-%m-%d %H:%M') | |
sales = [] | |
for entry in form_values.entries: | |
if entry.type == 'WIDGET': | |
amount = -1 if entry.amount > 1000 else entry.amount * 2 | |
sales.append({ | |
'type': 'widget_sale', | |
'value': entry.amount, | |
}) | |
elif entry.type == 'LOGO': | |
sales.append({ | |
'type': 'other', | |
'value': 0, | |
}) | |
else: | |
continue | |
url = 'https://carta.com/api/sales/' + form_values.id | |
r = requests.post(url, { | |
'full_name': full_name, | |
'date_of_birth': date_of_birth, | |
'sales': sales | |
}) | |
r.raise_for_exception() | |
return 'OK' if r.status.ok else 'FAIL' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment