def rate_partner(self, partner_code):
exchange_rate = ExchangeRates.objects.filter(partner__code=partner_code).latest('date_created')
return exchange_rate.rate
def pricing_policy(self, product, stockrecord):
# Check stockrecord has the appropriate data
if not stockrecord or stockrecord.price_excl_tax is None:
return prices.Unavailable()
return prices.FixedPrice(
currency=stockrecord.price_currency,
excl_tax=stockrecord.price_excl_tax*self.rate_partner('my_partner'),
tax=D('0.00'))
your_string = '<p>Ох уж этот php хотя java адский ад лучше уж пусть php</p>'
p = re.compile( '(php)(?=.*java)')
p.sub('', your_string)
$string = "<p>Ох уж этот php хотя java адский ад лучше уж пусть php</p>";
$string = ereg_replace('(php)(?=.*java)', '', $string);
from django.db.models import Q
queryset = Flat.objects.filter(
Q(price_currency='RUB', price__lte=price_max, price__gte=price_min) |
Q(price_currency='USD', price__lte=price_max*rate_usd, price__gte=price_min*rate_usd) |
Q(price_currency='EUR', price__lte=price_max*rate_eur, price__gte=price_min*rate_eur)
)
from math import sqrt
def input_int(count):
cathetus = raw_input('Введите число {}: '.format(count)) # python2
# cathetus = input('Введите число {}: '.format(count)) # python3
return int(cathetus) if cathetus.isdigit() else input_int(count)
def calculation(a, b):
hypotenuse = sqrt(a ** 2 + b ** 2)
square = float(a * b)/2 # updated, old: square = (a * b)/2
return {'hypotenuse': hypotenuse, 'square': square}
result = calculation(input_int(1), input_int(2))
print("\nгипотенуза: {hypotenuse}\nплощадь: {square}".format(**result))
class UniversityListView(ListView):
...
def get_queryset(self):
university = University.objects.filter(city='London')
return university
class University(models.Model):
...
city = models.ForeignKey('City')
...
class UniversityListView(ListView):
...
def get_queryset(self):
city = City.objects.get(name='London')
university = University.objects.filter(city=city)
return university
import json
import codecs
from pprint import pprint
def ld(p, encoding="utf8"):
u"""загрузка объекта"""
with codecs.open(p, "rt", encoding=encoding) as f:
return json.load(f)
json_dict = ld('my_file.json')
new_dict = dict()
for key in json_dict.keys():
new_dict[key] = json_dict[key]['html']
pprint(new_dict)