Private
Public Access
1
0

improved braintree transactions report

This commit is contained in:
Sander Roosendaal
2019-01-17 22:24:36 +01:00
parent 1b06a9eb46
commit 0dbb668f70
4 changed files with 82 additions and 267 deletions

View File

@@ -275,6 +275,7 @@ def cancel_subscription(rower,id):
except: except:
errormessages.append("We could not find the subscription record in our customer database. We have notified the site owner, who will contact you.") errormessages.append("We could not find the subscription record in our customer database. We have notified the site owner, who will contact you.")
name = '{f} {l}'.format(f = rower.user.first_name, l = rower.user.last_name) name = '{f} {l}'.format(f = rower.user.first_name, l = rower.user.last_name)
@@ -358,37 +359,40 @@ def get_transactions(start_date,end_date):
statuses = [] statuses = []
ids = [] ids = []
usernames = [] usernames = []
customerids = []
transactionids = []
subscriptionids = []
ownids = []
countlines = [1 for transaction in results]
for transaction in results: for transaction in results:
try: r = None
rs = Rower.objects.filter( rs = Rower.objects.filter(
customer_id=transaction.customer['id'], customer_id=transaction.customer['id'],
paymentprocessor='braintree') paymentprocessor='braintree')
if rs: if rs:
r = rs[0] r = rs[0]
countries.append(r.country) countries.append(r.country)
names.append('{f} {l}'.format( ownids.append(r.id)
f = r.user.first_name,
l = r.user.last_name,
)
)
emails.append(r.user.email)
ids.append(r.id)
usernames.append(r.user.username) usernames.append(r.user.username)
except (KeyError,IndexError): else:
countries.append( countries.append(
transaction.credit_card_details.country_of_issuance) transaction.credit_card_details.country_of_issuance)
ownids.append('unknown')
usernames.append('unknown')
emails.append(transaction.customer_details.email)
names.append('{f} {l}'.format( names.append('{f} {l}'.format(
f = transaction.customer['first_name'], f = transaction.customer['first_name'],
l = transaction.customer['last_name'] l = transaction.customer['last_name']
) )
) )
emails.append(transaction.customer.email) customerids.append(transaction.customer['id'])
ids.append(transaction.customer['id']) transactionids.append(transaction.id)
usernames.append('unknown') subscriptionids.append(transaction.subscription_id)
amounts.append(transaction.amount) amounts.append(transaction.amount)
dates.append(transaction.created_at) dates.append(transaction.created_at)
currencies.append(transaction.currency_iso_code) currencies.append(transaction.currency_iso_code)
@@ -407,7 +411,10 @@ def get_transactions(start_date,end_date):
'card_country':card_countries, 'card_country':card_countries,
'status':statuses, 'status':statuses,
'username':usernames, 'username':usernames,
'user_id':ids, 'user_id':ownids,
'customer_id':customerids,
'transaction_id':transactionids,
'subscription_id':subscriptionids
} }
) )

Binary file not shown.

View File

@@ -2502,7 +2502,7 @@
</Trackpoint> </Trackpoint>
</Track> </Track>
</Lap> </Lap>
<Notes>&lt;Element 'Notes' at 0x147c0f60&gt;</Notes> <Notes>&lt;Element 'Notes' at 0x138c9ef0&gt;</Notes>
</Activity> </Activity>
</Activities> </Activities>
<Creator> <Creator>

View File

@@ -13081,6 +13081,10 @@ def rower_prefs_view(request,userid=0,message=""):
} }
] ]
form = RowerForm(instance=r)
powerform = RowerPowerForm(instance=r)
powerzonesform = RowerPowerZonesForm(instance=r)
if request.method == 'POST' and "ut2" in request.POST: if request.method == 'POST' and "ut2" in request.POST:
form = RowerForm(request.POST) form = RowerForm(request.POST)
if form.is_valid(): if form.is_valid():
@@ -13093,7 +13097,7 @@ def rower_prefs_view(request,userid=0,message=""):
tr = cd['tr'] tr = cd['tr']
an = cd['an'] an = cd['an']
rest = cd['rest'] rest = cd['rest']
try:
r.max = max(min(hrmax,250),10) r.max = max(min(hrmax,250),10)
r.ut2 = max(min(ut2,250),10) r.ut2 = max(min(ut2,250),10)
r.ut1 = max(min(ut1,250),10) r.ut1 = max(min(ut1,250),10)
@@ -13104,47 +13108,6 @@ def rower_prefs_view(request,userid=0,message=""):
r.save() r.save()
successmessage = "Your Heart Rate data were changed" successmessage = "Your Heart Rate data were changed"
messages.info(request,successmessage) messages.info(request,successmessage)
form = RowerForm(instance=r)
powerform = RowerPowerForm(instance=r)
powerzonesform = RowerPowerZonesForm(instance=r)
accountform = AccountRowerForm(instance=r)
userform = UserForm(instance=r.user)
return render(request, 'rower_preferences.html',
{'form':form,
'powerzonesform':powerzonesform,
'teams':get_my_teams(request.user),
'breadcrumbs':breadcrumbs,
'powerform':powerform,
'rower':r,
'accountform':accountform,
'userform':userform,
})
except Rower.DoesNotExist:
message = "Funny. This user doesn't exist."
messages.error(request,message)
url = reverse(workouts_view)
response = HttpResponseRedirect(url)
else:
message = HttpResponse("invalid form")
#form = RowerForm(instance=r)
powerform = RowerPowerForm(instance=r)
powerzonesform = RowerPowerZonesForm(instance=r)
userform = UserForm(instance=r.user)
accountform = AccountRowerForm(instance=r)
return render(request, 'rower_preferences.html',
{'form':form,
'teams':get_my_teams(request.user),
'powerzonesform':powerzonesform,
'breadcrumbs':breadcrumbs,
'userform':userform,
'accountform':accountform,
'powerform':powerform,
'rower':r,
})
return response
elif request.method == 'POST' and "ftp" in request.POST: elif request.method == 'POST' and "ftp" in request.POST:
powerform = RowerPowerForm(request.POST) powerform = RowerPowerForm(request.POST)
if powerform.is_valid(): if powerform.is_valid():
@@ -13154,7 +13117,7 @@ def rower_prefs_view(request,userid=0,message=""):
hrftp = int((r.an+r.tr)/2.) hrftp = int((r.an+r.tr)/2.)
ftp = cd['ftp'] ftp = cd['ftp']
otwslack = cd['otwslack'] otwslack = cd['otwslack']
try:
powerfrac = 100*np.array([r.pw_ut2, powerfrac = 100*np.array([r.pw_ut2,
r.pw_ut1, r.pw_ut1,
r.pw_at, r.pw_at,
@@ -13171,35 +13134,7 @@ def rower_prefs_view(request,userid=0,message=""):
r.save() r.save()
message = "FTP and/or OTW slack values changed." message = "FTP and/or OTW slack values changed."
messages.info(request,message) messages.info(request,message)
url = reverse(rower_prefs_view,
kwargs = {
'userid':r.user.id,
})
response = HttpResponseRedirect(url)
except Rower.DoesNotExist:
message = "Funny. This user doesn't exist."
messages.error(request,message)
url = reverse(rower_edit_view)
response = HttpResponseRedirect(url)
else:
message = HttpResponse("invalid form")
form = RowerForm(instance=r)
#powerform = RowerPowerForm(instance=r)
powerzonesform = RowerPowerZonesForm(instance=r)
userform = UserForm(instance=r.user)
accountform = AccountRowerForm(instance=r)
return render(request, 'rower_preferences.html',
{'form':form,
'teams':get_my_teams(request.user),
'breadcrumbs':breadcrumbs,
'powerform':powerform,
'rower':r,
'userform':userform,
'accountform':accountform,
})
return response
elif request.method == 'POST' and "ut3name" in request.POST: elif request.method == 'POST' and "ut3name" in request.POST:
powerzonesform = RowerPowerZonesForm(request.POST) powerzonesform = RowerPowerZonesForm(request.POST)
if powerzonesform.is_valid(): if powerzonesform.is_valid():
@@ -13216,7 +13151,7 @@ def rower_prefs_view(request,userid=0,message=""):
trname = cd['trname'] trname = cd['trname']
anname = cd['anname'] anname = cd['anname']
powerzones = [ut3name,ut2name,ut1name,atname,trname,anname] powerzones = [ut3name,ut2name,ut1name,atname,trname,anname]
try:
r.pw_ut2 = pw_ut2 r.pw_ut2 = pw_ut2
r.pw_ut1 = pw_ut1 r.pw_ut1 = pw_ut1
r.pw_at = pw_at r.pw_at = pw_at
@@ -13226,130 +13161,7 @@ def rower_prefs_view(request,userid=0,message=""):
r.save() r.save()
successmessage = "Your Power Zone data were changed" successmessage = "Your Power Zone data were changed"
messages.info(request,successmessage) messages.info(request,successmessage)
form = RowerForm(instance=r)
accountform = AccountRowerForm(instance=r)
userform = UserForm(instance=r.user)
powerform = RowerPowerForm(instance=r)
powerzonesform = RowerPowerZonesForm(instance=r)
return render(request, 'rower_preferences.html',
{'form':form,
'teams':get_my_teams(request.user),
'powerzonesform':powerzonesform,
'powerform':powerform,
'userform':userform,
'breadcrumbs':breadcrumbs,
'accountform':accountform,
'rower':r,
})
except Rower.DoesNotExist:
message = "Funny. This user doesn't exist."
messages.error(request,message)
url = reverse(workouts_view)
response = HttpResponseRedirect(url)
return response
else:
form = RowerForm(instance=r)
powerform = RowerPowerForm(instance=r)
accountform = AccountRowerForm(instance=r)
userform = UserForm(instance=r.user)
#powerzonesform = RowerPowerZonesForm(instance=r)
message = HttpResponse("invalid form")
return render(request, 'rower_preferences.html',
{'form':form,
'teams':get_my_teams(request.user),
'powerform':powerform,
'breadcrumbs':breadcrumbs,
'powerzonesform':powerzonesform,
'accountform':accountform,
'userform':userform,
'rower':r,
})
elif request.method == 'POST' and "weightcategory" in request.POST:
accountform = AccountRowerForm(request.POST)
userform = UserForm(request.POST,instance=r.user)
if accountform.is_valid() and userform.is_valid():
# process
cd = accountform.cleaned_data
ucd = userform.cleaned_data
first_name = ucd['first_name']
last_name = ucd['last_name']
email = ucd['email']
sex = cd['sex']
defaultlandingpage = cd['defaultlandingpage']
weightcategory = cd['weightcategory']
adaptiveclass = cd['adaptiveclass']
birthdate = cd['birthdate']
showfavoritechartnotes = cd['showfavoritechartnotes']
getemailnotifications = cd['getemailnotifications']
getimportantemails = cd['getimportantemails']
defaulttimezone=cd['defaulttimezone']
u = r.user
if u.email != email and len(email):
resetbounce = True
else:
resetbounce = False
if len(first_name):
u.first_name = first_name
u.last_name = last_name
if len(email): ## and check_email_freeforuse(u,email):
u.email = email
resetbounce = True
u.save()
r.defaulttimezone=defaulttimezone
r.weightcategory = weightcategory
r.adaptiveclass = adaptiveclass
r.getemailnotifications = getemailnotifications
r.getimportantemails = getimportantemails
r.defaultlandingpage = defaultlandingpage
r.showfavoritechartnotes = showfavoritechartnotes
r.sex = sex
r.birthdate = birthdate
if resetbounce and r.emailbounced:
r.emailbounced = False
r.save()
form = RowerForm(instance=r)
powerform = RowerPowerForm(instance=r)
powerzonesform = RowerPowerZonesForm(instance=r)
accountform = AccountRowerForm(instance=r)
userform = UserForm(instance=u)
successmessage = 'Account Information changed'
messages.info(request,successmessage)
return render(request, 'rower_preferences.html',
{'form':form,
'teams':get_my_teams(request.user),
'powerzonesform':powerzonesform,
'breadcrumbs':breadcrumbs,
'powerform':powerform,
'accountform':accountform,
'userform':userform,
'rower':r,
})
else:
form = RowerForm(instance=r)
powerform = RowerPowerForm(instance=r)
powerzonesform = RowerPowerZonesForm(instance=r)
return render(request, 'rower_preferences.html',
{'form':form,
'teams':get_my_teams(request.user),
'powerzonesform':powerzonesform,
'powerform':powerform,
'breadcrumbs':breadcrumbs,
'accountform':accountform,
'userform':userform,
'rower':r,
})
else:
try:
form = RowerForm(instance=r)
powerform = RowerPowerForm(instance=r)
powerzonesform = RowerPowerZonesForm(instance=r)
accountform = AccountRowerForm(instance=r)
userform = UserForm(instance=r.user)
grants = AccessToken.objects.filter(user=request.user)
return render(request, 'rower_preferences.html', return render(request, 'rower_preferences.html',
{ {
'form':form, 'form':form,
@@ -13357,13 +13169,9 @@ def rower_prefs_view(request,userid=0,message=""):
'powerform':powerform, 'powerform':powerform,
'powerzonesform':powerzonesform, 'powerzonesform':powerzonesform,
'breadcrumbs':breadcrumbs, 'breadcrumbs':breadcrumbs,
'userform':userform,
'accountform':accountform,
'grants':grants,
'rower':r, 'rower':r,
}) })
except Rower.DoesNotExist:
raise Http404("This user doesn't exist")
# Revoke an app that you granted access through the API. # Revoke an app that you granted access through the API.
# this views is called when you press a button on the User edit page # this views is called when you press a button on the User edit page