本文整理汇总了Python中products.models.Product.get_ordering方法的典型用法代码示例。如果您正苦于以下问题:Python Product.get_ordering方法的具体用法?Python Product.get_ordering怎么用?Python Product.get_ordering使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类products.models.Product
的用法示例。
在下文中一共展示了Product.get_ordering方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tracker
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import get_ordering [as 别名]
def tracker(request, is_isa=False, form_class=TIMRateTrackerForm,
template_file='thisismoney/ratetracker/wizard.html'):
"""
"""
empty_values = ['', ' ', None, 0]
context = _init_context(is_isa)
success_view = _get_success_view(is_isa)
if request.method == 'POST':
if SEARCH in request.POST.keys():
# The wizard forks depending on which product type was selected, we need to check what
# was in the request keys
form = form_class(request.POST)
if form.is_valid():
# bog standard searching
if not form.set_reminder:
request.session[constants.RESULTS] = constants.RT_RESULTS
form_email = form.cleaned_data.get('email')
# if the form is valid we want to then display the results.html
template_file = 'thisismoney/ratetracker/results.html' if not is_isa else 'thisismoney/isatracker/isa_results.html'
selected_product = get_object_or_404(Product, pk=form.cleaned_data.get('product'))
context['selected_product'] = selected_product
bestbuy = BestBuy.objects.get(pk=form.cleaned_data.get('account_type'))
context['bestbuy_type'] = bestbuy
# set up the Product Form to Track this product
initial = {'provider': selected_product.provider,
'account_type': form.cleaned_data.get('account_type'),
'product': selected_product,
'balance': form.cleaned_data.get('balance'),
'notice': selected_product.notice,
'bonus_term': selected_product.bonus_term,
}
#set up the registration form
initialDetails = {'username': form.cleaned_data.get('email'),
'email': form.cleaned_data.get('email'),
'email2': form.cleaned_data.get('email'),
'password2': 'doesnotmatterjustneededforformisvalid',
'salutation': 'Mr',
'source': 'This is Money',
'uuid': create_uid_next(form),
}
if selected_product.bonus_term not in empty_values: # wtf this is a float?
initial['bonus_term'] = selected_product.bonus_term
context['track_product_form'] = ProductReminderForm(initial=initial)
context['register_form'] = SCRegistrationForm(initial=initialDetails)
product_rate = selected_product.get_rate(datetime.datetime.now().date())
context['rate'] = product_rate
#store user in TiMSignups
new_signup = TiMSignups(email=form.cleaned_data.get('email'), completed_signup=False)
if not TiMSignups.objects.filter(email=form.cleaned_data.get('email')).exists():
new_signup.save()
filters = {'%s__gte' % Product.get_ordering(bestbuy.slug): 1}
products = Product.objects.filter(bestbuy_type__pk=form.cleaned_data.get('account_type')) \
.filter(**filters).order_by(Product.get_ordering(bestbuy.slug)) \
.filter(minimum__lte=form.cleaned_data.get('balance'))
if 'variable-rate-isa' in bestbuy.slug:
products = products.filter(is_isa_transfers_in=True)
try:
your_interest_balance = form.cleaned_data.get('balance') * (product_rate / 100)
except:
your_interest_balance = 0
if products and len(products) > 0:
context['suggested_product'] = products[0]
suggested_interest_balance = form.cleaned_data.get('balance') * (products[0].gross_rate / 100)
context['suggested_interest_amount'] = suggested_interest_balance + form.cleaned_data.get(
'balance')
context['extra_interest'] = suggested_interest_balance - your_interest_balance
context['your_interest_amount'] = your_interest_balance + form.cleaned_data.get('balance')
else:
# form is valid so we copy straight across from one to another
# TODO now needs to check if they are logged in
if not request.user.is_authenticated():
context = RequestContext(request)
new_signup = TiMSignups(email=form.cleaned_data.get('email'), completed_signup=False)
if not TiMSignups.objects.filter(email=form.cleaned_data.get('email')).exists():
new_signup.save()
data = {'username': MakeUsername(),
'provider': form.cleaned_data.get('provider'),
'account_type': form.cleaned_data.get('account_type'),
'balance': form.cleaned_data.get('balance'),
'maturity_date': form.cleaned_data.get('maturity_date'),
#.........这里部分代码省略.........
示例2: tracker
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import get_ordering [as 别名]
def tracker(request, is_isa=False, form_class=RateTrackerForm, template_file='products/ratetracker/wizard.html'):
"""
"""
context = _init_context(is_isa)
success_view = _get_success_view(is_isa)
if request.method == 'POST':
if SEARCH in request.POST.keys():
# The wizard forks depending on which product type was selected, we need to check what
# was in the request keys
form = form_class(request.POST)
if form.is_valid():
# bog standard searching
if not form.set_reminder:
request.session[constants.RESULTS] = constants.RT_RESULTS
# if the form is valid we want to then display the results.html
template_file = 'products/ratetracker/results.html' if not is_isa else 'products/isatracker/isa_results.html'
selected_product = get_object_or_404(Product, pk=form.cleaned_data.get('product'))
context['selected_product'] = selected_product
bestbuy = BestBuy.objects.get(pk=form.cleaned_data.get('account_type'), client_type='p')
context['bestbuy_type'] = bestbuy
# set up the Form to Track this product
initial = {'provider': selected_product.provider,
'account_type': form.cleaned_data.get('account_type'),
'product': selected_product,
'balance': form.cleaned_data.get('balance'),
'notice': selected_product.notice,
'opening_date': form.cleaned_data.get('opening_date'),
}
if selected_product.bonus_term not in EMPTY_VALUES: # wtf this is a float?
initial['bonus_term'] = selected_product.bonus_term
context['expiryDate'] = form.cleaned_data.get('opening_date') + relativedelta(
months=selected_product.bonus_term)
context['track_product_form'] = ProductReminderForm(initial=initial)
product_rate = selected_product.get_rate(form.cleaned_data.get('opening_date'))
context['rate'] = product_rate
filters = {'%s__gte' % Product.get_ordering(bestbuy.slug): 1}
products = Product.objects.filter(bestbuy_type__pk=form.cleaned_data.get('account_type')) \
.filter(**filters).order_by(Product.get_ordering(bestbuy.slug)) \
.filter(minimum__lte=form.cleaned_data.get('balance'))
if 'variable-rate-isa' in bestbuy.slug:
products = products.filter(is_isa_transfers_in=True)
if products and len(products) > 0:
context['suggested_product'] = products[0]
suggested_interest_balance = form.cleaned_data.get('balance') * products[0].gross_rate
try:
your_interest_balance = form.cleaned_data.get('balance') * product_rate
except:
your_interest_balance = 0
context['your_interest_amount'] = your_interest_balance + form.cleaned_data.get('balance')
context['suggested_interest_amount'] = suggested_interest_balance + form.cleaned_data.get('balance')
context['extra_interest'] = suggested_interest_balance - your_interest_balance
else:
# form is valid so we copy straight across from one to another
# TODO now needs to check if they are logged in
if not request.user.is_authenticated():
uid_next = create_uid_next(form)
messages.add_message(request, messages.INFO, create_redirect_url(uid_next))
return HttpResponseRedirect(
'%s?tracker=register&uuid=%s' % (reverse('registration_register'), uid_next))
request.session[constants.RESULTS] = constants.RT_FR_RESULTS
_make_reminder(form.cleaned_data, request)
return HttpResponseRedirect('%s?updated=%s' % (reverse(success_view), time.time()))
if TRACK in request.POST.keys():
track_product_form = ProductReminderForm(request.POST)
if track_product_form.is_valid():
if not request.user.is_authenticated():
uid_next = create_uid_next(track_product_form)
messages.add_message(request, messages.INFO, create_redirect_url(uid_next))
return HttpResponseRedirect(
'%s?tracker=register&uuid=%s' % (reverse('registration_register'), uid_next))
_make_product_reminder(track_product_form.cleaned_data, request)
return HttpResponseRedirect('%s?updated=%s' % (reverse(success_view), time.time()))
#.........这里部分代码省略.........