Привет, хочу получить code review и feedback к следующему куску кода:
lat_from = self.request.query_params.get('lat_from', None)
lng_from = self.request.query_params.get('lng_from', None)
r_from = self.request.query_params.get('r_from', 0)
lat_to = self.request.query_params.get('lat_to', None)
lng_to = self.request.query_params.get('lng_to', None)
r_to = self.request.query_params.get('r_to', 0)
# [[h - hour, m - minute], [f - from, to - to], [f - floor, c - ceil]]
hff = self.request.query_params.get('hff', None)
hfc = self.request.query_params.get('hfc', None)
htf = self.request.query_params.get('htf', None)
htc = self.request.query_params.get('htc', None)
mff = self.request.query_params.get('mff', 0)
mfc = self.request.query_params.get('mfc', 59)
mtf = self.request.query_params.get('mtf', 0)
mtc = self.request.query_params.get('mtc', 59)
# [[y - year, m - month, d - day, wd - days of the week], [f - from, t - to]]
yf = self.request.query_params.get('yf', None)
yt = self.request.query_params.get('yt', None)
mf = self.request.query_params.get('mf', None)
mt = self.request.query_params.get('mt', None)
df = self.request.query_params.get('df', None)
dt = self.request.query_params.get('dt', None)
wdf = self.request.query_params.get('wdf', None)
wdt = self.request.query_params.get('wdt', None)
city_from = self.request.query_params.get('city_from', None)
city_to = self.request.query_params.get('city_to', None)
if lat_from and lng_from:
pnt = GEOSGeometry(f'Point({lng_from} {lat_from})', srid=4326)
qs = qs.annotate(distance=Distance('address_from__location', pnt))
qs = qs.filter(distance__lte=F('address_from__radius') + r_from)
if lat_to and lng_to:
pnt = GEOSGeometry(f'Point({lng_to} {lat_to})', srid=4326)
qs = qs.annotate(distance=Distance('address_to__location', pnt))
qs = qs.filter(distance__lte=F('address_to__radius') + r_to)
if hff and hfc:
hff, hfc, mff, mfc = map(int, (hff, hfc, mff, mfc))
qs = qs.filter(time_from__time__range=(datetime.time(hff, mff),
datetime.time(hfc, mfc)))
elif hff and hfc:
qs = qs.filter(time_from__time__range=(datetime.time(int(hff)),
datetime.time(int(hfc))))
elif hff:
qs = qs.filter(time_from__hour__gte=int(hff))
elif hfc:
qs = qs.filter(time_from__hour__lte=int(hfc))
if htf and htc and mtf and mtc:
htf, htc, mtf, mtc = map(int, (htf, htc, mtf, mtc))
qs = qs.filter(time_to__time__range=(datetime.time(htf, mtf),
datetime.time(htc, mtc)))
elif htf and htc:
qs = qs.filter(time_to__time__range=(datetime.time(int(htf)),
datetime.time(int(htc))))
elif hff:
qs = qs.filter(time_from__hour__gte=int(htf))
elif hfc:
qs = qs.filter(time_from__hour__lte=int(htc))
if yf and mf and df and yt and mt and dt:
qs = qs.filter(datetime_from__date__range=(
datetime.date(int(yf), int(mf), int(df)),
datetime.date(int(yt), int(mt), int(dt))
))
if yf and mf and df:
qs = qs.filter(datetime_from__date__gte=datetime.date(int(yf),
int(mf),
int(df)))
elif mf and df:
date = datetime.date.today().replace(month=int(mf), day=int(df))
qs = qs.filter(datetime_from__date__gte=date)
elif mf:
date = datetime.date.today().replace(month=int(mf))
qs = qs.filter(datetime_from__date_gte=date)
if yt and mt and dt:
qs = qs.filter(datetime_from__date__lte=datetime.date(int(yt),
int(mt),
int(dt)))
elif mt and dt:
date = datetime.date.today().replace(month=int(mt), day=int(dt))
qs = qs.filter(datetime_to__date__lte=date)
elif mt:
date = datetime.date.today().replace(month=int(mt))
qs = qs.filter(datetime_to__date__lte=date)
if wdf:
*wdf, = map(int, wdf.split(','))
qs = qs.filter(datetime_from__week_day__in=wdf)
if wdt:
*wdt, = map(int, wdt.split(','))
qs = qs.filter(datetime_to__week_day__in=wdt)
if city_from:
qs = qs.filter(address_from__city__icontains=city_from)
if city_to:
qs = qs.filter(address_to__city__icontains=city_to)
return qs
Спасибо.
Updated 5 July 2018, 20:59 by KhDenys.