improved braintree transactions report
This commit is contained in:
@@ -274,6 +274,7 @@ def cancel_subscription(rower,id):
|
|||||||
themessages.append("Subscription canceled")
|
themessages.append("Subscription canceled")
|
||||||
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)
|
||||||
names.append('{f} {l}'.format(
|
ownids.append('unknown')
|
||||||
f = transaction.customer['first_name'],
|
|
||||||
l = transaction.customer['last_name']
|
|
||||||
)
|
|
||||||
)
|
|
||||||
emails.append(transaction.customer.email)
|
|
||||||
ids.append(transaction.customer['id'])
|
|
||||||
usernames.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)
|
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)
|
||||||
@@ -396,7 +400,7 @@ def get_transactions(start_date,end_date):
|
|||||||
transaction.credit_card_details.country_of_issuance)
|
transaction.credit_card_details.country_of_issuance)
|
||||||
statuses.append(transaction.status)
|
statuses.append(transaction.status)
|
||||||
|
|
||||||
|
|
||||||
df = pd.DataFrame({
|
df = pd.DataFrame({
|
||||||
'name':names,
|
'name':names,
|
||||||
'email':emails,
|
'email':emails,
|
||||||
@@ -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
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
Binary file not shown.
2
rowers/tests/testdata/testdata.tcx
vendored
2
rowers/tests/testdata/testdata.tcx
vendored
@@ -2502,7 +2502,7 @@
|
|||||||
</Trackpoint>
|
</Trackpoint>
|
||||||
</Track>
|
</Track>
|
||||||
</Lap>
|
</Lap>
|
||||||
<Notes><Element 'Notes' at 0x147c0f60></Notes>
|
<Notes><Element 'Notes' at 0x138c9ef0></Notes>
|
||||||
</Activity>
|
</Activity>
|
||||||
</Activities>
|
</Activities>
|
||||||
<Creator>
|
<Creator>
|
||||||
|
|||||||
292
rowers/views.py
292
rowers/views.py
@@ -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,58 +13097,17 @@ 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.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,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
r.max = max(min(hrmax,250),10)
|
||||||
|
r.ut2 = max(min(ut2,250),10)
|
||||||
return response
|
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:
|
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,52 +13117,24 @@ 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,
|
||||||
r.pw_tr,r.pw_an])/r.ftp
|
r.pw_tr,r.pw_an])/r.ftp
|
||||||
r.ftp = max(min(ftp,650),50)
|
r.ftp = max(min(ftp,650),50)
|
||||||
r.otwslack = max(min(otwslack,50),0)
|
r.otwslack = max(min(otwslack,50),0)
|
||||||
ut2,ut1,at,tr,an = (r.ftp*powerfrac/100.).astype(int)
|
ut2,ut1,at,tr,an = (r.ftp*powerfrac/100.).astype(int)
|
||||||
r.pw_ut2 = ut2
|
r.pw_ut2 = ut2
|
||||||
r.pw_ut1 = ut1
|
r.pw_ut1 = ut1
|
||||||
r.pw_at = at
|
r.pw_at = at
|
||||||
r.pw_tr = tr
|
r.pw_tr = tr
|
||||||
r.pw_an = an
|
r.pw_an = an
|
||||||
r.hrftp = hrftp
|
r.hrftp = hrftp
|
||||||
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,154 +13151,27 @@ 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_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
|
|
||||||
|
|
||||||
|
r.pw_ut2 = pw_ut2
|
||||||
u.save()
|
r.pw_ut1 = pw_ut1
|
||||||
r.defaulttimezone=defaulttimezone
|
r.pw_at = pw_at
|
||||||
r.weightcategory = weightcategory
|
r.pw_tr = pw_tr
|
||||||
r.adaptiveclass = adaptiveclass
|
r.pw_an = pw_an
|
||||||
r.getemailnotifications = getemailnotifications
|
r.powerzones = powerzones
|
||||||
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()
|
r.save()
|
||||||
form = RowerForm(instance=r)
|
successmessage = "Your Power Zone data were changed"
|
||||||
powerform = RowerPowerForm(instance=r)
|
|
||||||
powerzonesform = RowerPowerZonesForm(instance=r)
|
|
||||||
accountform = AccountRowerForm(instance=r)
|
|
||||||
userform = UserForm(instance=u)
|
|
||||||
successmessage = 'Account Information changed'
|
|
||||||
messages.info(request,successmessage)
|
messages.info(request,successmessage)
|
||||||
return render(request, 'rower_preferences.html',
|
|
||||||
{'form':form,
|
return render(request, 'rower_preferences.html',
|
||||||
'teams':get_my_teams(request.user),
|
{
|
||||||
'powerzonesform':powerzonesform,
|
'form':form,
|
||||||
'breadcrumbs':breadcrumbs,
|
'teams':get_my_teams(request.user),
|
||||||
'powerform':powerform,
|
'powerform':powerform,
|
||||||
'accountform':accountform,
|
'powerzonesform':powerzonesform,
|
||||||
'userform':userform,
|
'breadcrumbs':breadcrumbs,
|
||||||
'rower':r,
|
'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")
|
|
||||||
|
|
||||||
# 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
|
||||||
|
|||||||
Reference in New Issue
Block a user