def add_order(user_id, title, url, balance, cpa, type, auto_approve=True, allow_negative_balance=True, reentrant=False, male=None, min_age=None, max_age=None, city_filter_type=None, city=[], app_filter_type=None, app=[], min_hour=None, max_hour=None, **kwargs): params_dict = dict( userId=user_id, title=title, url=url, balance=balance, cpa=cpa, autoApprove=auto_approve, allowNegativeBalance=allow_negative_balance, reentrant=reentrant, type=type, **kwargs) if min_age is not None and min_age > 0: params_dict.update(minAge=min_age) if max_age is not None and max_age > 0: params_dict.update(maxAge=max_age) male = convert.to_bool(male) if male is not None: params_dict.update(male=male) if city_filter_type: params_dict.update(cityFilterType=city_filter_type, city=city) if app_filter_type: params_dict.update(appFilterType=app_filter_type, app=app) if min_hour is not None and 0 <= min_hour <= 23: params_dict.update(minHour=min_hour) if max_hour is not None and 0 <= max_hour <= 23: params_dict.update(maxHour=max_hour) id = post(path=resource_path, params_dict=params_dict) return int(id)
def orders_info_edit(id): order = do_or_abort(actions.orders.get_order, id, full=True) if order.user.id != g.user.id: abort(404) cities = [dict(id=city.id, name=city.name) for city in actions.cities.get_cities()] order_cities = [dict(id=city.id, name=city.name) for city in order.cities] if order.cities else [] form_args = dict( ordername = order.title, orderurl = order.url, orderbalance = order.account.balance, ordercpa = order.cpa, ordermale = u'' if order.male is None else unicode(order.male), orderminage = order.min_age, ordermaxage = order.max_age, orderminhour = order.min_hour, ordermaxhour = order.max_hour, ordercitiesfilter = order.city_filter_type ) if order.is_regular(): form_args.update(orderdesc = order.description) cls = forms.RegularOrderEditForm elif order.is_banner(): settings = actions.settings.get_settings() form_args.update(c_min=settings.c_min_safe(), c_rec=settings.c_rec()) cls = forms.BannerOrderEditForm elif order.is_video(): form_args.update(ordervideourl = order.video_url) cls = forms.VideoOrderEditForm form = cls(request.form, **form_args) if request.method == 'POST' and form.validate(): kwargs = dict() male = convert.to_bool(form.ordermale.data) if form.ordername.data != order.title: kwargs.update(title=form.ordername.data) # if form.orderurl.data != order.url: kwargs.update(url=form.orderurl.data) if float(form.ordercpa.data) != order.cpa: kwargs.update(cpa=form.ordercpa.data) if male != order.male: kwargs.update(male=male) if form.orderminage.data != order.min_age: kwargs.update(min_age=form.orderminage.data) if form.ordermaxage.data != order.max_age: kwargs.update(max_age=form.ordermaxage.data) if form.orderminhour.data != order.min_hour: kwargs.update(min_hour=form.orderminhour.data) if form.ordermaxhour.data != order.max_hour: kwargs.update(max_hour=form.ordermaxhour.data) old_cities = frozenset([city.id for city in order.cities]) new_cities = frozenset([int(x) for x in form.ordercities.data.split(',')] if form.ordercities.data else []) if new_cities != old_cities: kwargs.update(city=list(new_cities)) city_filter_type = (form.ordercitiesfilter.data or None) if new_cities else None if city_filter_type != order.city_filter_type: kwargs.update(city_filter_type=city_filter_type) if order.is_regular(): if form.orderdesc.data != order.description: kwargs.update(description=form.orderdesc.data) if form.orderimage.data is not None: kwargs.update(image=base64.encodestring(request.files['orderimage'].stream.read())) elif order.is_banner(): pass elif order.is_video(): if form.ordervideourl.data != order.video_url: kwargs.update(video_url=form.ordervideourl.data) if kwargs.keys(): actions.orders.update_order(order.id, **kwargs) mail.admin_order_changed(g.user, order) flash(u'Заказ успешно обновлен', 'success') else: flash(u'Вы не изменили ни одного поля', 'warning') return redirect(url_for('.orders_info', id=order.id)) return render_template('cabinet/orders-info-edit.html', order=order, form=form, cities=cities, order_cities=order_cities)