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

@@ -274,6 +274,7 @@ def cancel_subscription(rower,id):
themessages.append("Subscription canceled")
except:
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)
@@ -358,37 +359,40 @@ def get_transactions(start_date,end_date):
statuses = []
ids = []
usernames = []
customerids = []
transactionids = []
subscriptionids = []
ownids = []
countlines = [1 for transaction in results]
for transaction in results:
try:
rs = Rower.objects.filter(
customer_id=transaction.customer['id'],
paymentprocessor='braintree')
if rs:
r = rs[0]
r = None
rs = Rower.objects.filter(
customer_id=transaction.customer['id'],
paymentprocessor='braintree')
if rs:
r = rs[0]
countries.append(r.country)
names.append('{f} {l}'.format(
f = r.user.first_name,
l = r.user.last_name,
)
)
emails.append(r.user.email)
ids.append(r.id)
ownids.append(r.id)
usernames.append(r.user.username)
except (KeyError,IndexError):
else:
countries.append(
transaction.credit_card_details.country_of_issuance)
names.append('{f} {l}'.format(
f = transaction.customer['first_name'],
l = transaction.customer['last_name']
)
)
emails.append(transaction.customer.email)
ids.append(transaction.customer['id'])
ownids.append('unknown')
usernames.append('unknown')
emails.append(transaction.customer_details.email)
names.append('{f} {l}'.format(
f = transaction.customer['first_name'],
l = transaction.customer['last_name']
)
)
customerids.append(transaction.customer['id'])
transactionids.append(transaction.id)
subscriptionids.append(transaction.subscription_id)
amounts.append(transaction.amount)
dates.append(transaction.created_at)
currencies.append(transaction.currency_iso_code)
@@ -396,7 +400,7 @@ def get_transactions(start_date,end_date):
transaction.credit_card_details.country_of_issuance)
statuses.append(transaction.status)
df = pd.DataFrame({
'name':names,
'email':emails,
@@ -407,7 +411,10 @@ def get_transactions(start_date,end_date):
'card_country':card_countries,
'status':statuses,
'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>
</Track>
</Lap>
<Notes>&lt;Element 'Notes' at 0x147c0f60&gt;</Notes>
<Notes>&lt;Element 'Notes' at 0x138c9ef0&gt;</Notes>
</Activity>
</Activities>
<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:
form = RowerForm(request.POST)
if form.is_valid():
@@ -13093,58 +13097,17 @@ def rower_prefs_view(request,userid=0,message=""):
tr = cd['tr']
an = cd['an']
rest = cd['rest']
try:
r.max = max(min(hrmax,250),10)
r.ut2 = max(min(ut2,250),10)
r.ut1 = max(min(ut1,250),10)
r.at = max(min(at,250),10)
r.tr = max(min(tr,250),10)
r.an = max(min(an,250),10)
r.rest = max(min(rest,250),10)
r.save()
successmessage = "Your Heart Rate data were changed"
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
r.max = max(min(hrmax,250),10)
r.ut2 = max(min(ut2,250),10)
r.ut1 = max(min(ut1,250),10)
r.at = max(min(at,250),10)
r.tr = max(min(tr,250),10)
r.an = max(min(an,250),10)
r.rest = max(min(rest,250),10)
r.save()
successmessage = "Your Heart Rate data were changed"
messages.info(request,successmessage)
elif request.method == 'POST' and "ftp" in request.POST:
powerform = RowerPowerForm(request.POST)
if powerform.is_valid():
@@ -13154,52 +13117,24 @@ def rower_prefs_view(request,userid=0,message=""):
hrftp = int((r.an+r.tr)/2.)
ftp = cd['ftp']
otwslack = cd['otwslack']
try:
powerfrac = 100*np.array([r.pw_ut2,
r.pw_ut1,
r.pw_at,
r.pw_tr,r.pw_an])/r.ftp
r.ftp = max(min(ftp,650),50)
r.otwslack = max(min(otwslack,50),0)
ut2,ut1,at,tr,an = (r.ftp*powerfrac/100.).astype(int)
r.pw_ut2 = ut2
r.pw_ut1 = ut1
r.pw_at = at
r.pw_tr = tr
r.pw_an = an
r.hrftp = hrftp
r.save()
message = "FTP and/or OTW slack values changed."
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
powerfrac = 100*np.array([r.pw_ut2,
r.pw_ut1,
r.pw_at,
r.pw_tr,r.pw_an])/r.ftp
r.ftp = max(min(ftp,650),50)
r.otwslack = max(min(otwslack,50),0)
ut2,ut1,at,tr,an = (r.ftp*powerfrac/100.).astype(int)
r.pw_ut2 = ut2
r.pw_ut1 = ut1
r.pw_at = at
r.pw_tr = tr
r.pw_an = an
r.hrftp = hrftp
r.save()
message = "FTP and/or OTW slack values changed."
messages.info(request,message)
elif request.method == 'POST' and "ut3name" in request.POST:
powerzonesform = RowerPowerZonesForm(request.POST)
if powerzonesform.is_valid():
@@ -13216,154 +13151,27 @@ def rower_prefs_view(request,userid=0,message=""):
trname = cd['trname']
anname = cd['anname']
powerzones = [ut3name,ut2name,ut1name,atname,trname,anname]
try:
r.pw_ut2 = pw_ut2
r.pw_ut1 = pw_ut1
r.pw_at = pw_at
r.pw_tr = pw_tr
r.pw_an = pw_an
r.powerzones = powerzones
r.save()
successmessage = "Your Power Zone data were changed"
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.pw_ut2 = pw_ut2
r.pw_ut1 = pw_ut1
r.pw_at = pw_at
r.pw_tr = pw_tr
r.pw_an = pw_an
r.powerzones = powerzones
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'
successmessage = "Your Power Zone data were 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',
{
'form':form,
'teams':get_my_teams(request.user),
'powerform':powerform,
'powerzonesform':powerzonesform,
'breadcrumbs':breadcrumbs,
'userform':userform,
'accountform':accountform,
'grants':grants,
'rower':r,
})
except Rower.DoesNotExist:
raise Http404("This user doesn't exist")
return render(request, 'rower_preferences.html',
{
'form':form,
'teams':get_my_teams(request.user),
'powerform':powerform,
'powerzonesform':powerzonesform,
'breadcrumbs':breadcrumbs,
'rower':r,
})
# Revoke an app that you granted access through the API.
# this views is called when you press a button on the User edit page