def get_lookupvalues_by_lookup_name(store_id, name): lookup = Lookup.find_by_name_and_store(store_id, name) if not lookup: abort(404, description=gettext(u'lookup with name %(name)s is not found', name=name)) return LookupValue.find_all_by_lookup_id(lookup.id)
def edit(selected_menu, campaign=None): current_user = g.user store_id = get_or_set_store_id() from application.forms.campaign import CampaignForm form = None campaign_cars = [] if campaign: campaign_cars = campaign.related_cars.split(',') form = CampaignForm(obj=campaign) else: form = CampaignForm() lookup = Lookup.find_by_name_and_store(store_id, 'intent-car') if lookup: cars = LookupValue.find_all_by_lookup_id(lookup.id) form.related_cars.choices = [(car.code, car.value) for car in cars] if form.related_cars.choices is None: form.related_cars.choices = [] if request.method == 'GET': form.related_cars.data = campaign_cars if request.method == 'POST' and form.validate_on_submit(): if campaign is None: campaign = Campaign() campaign.store_id = store_id form.populate_obj(campaign) campaign.related_cars = u','.join(form.related_cars.data) campaign.save_and_flush() flash_success(gettext(u'campaign saved')) return redirect(url_for('campaigns.campaigns')) # form. # campaign = form.po # if form.validate_on_submit(): # json_r = uc_login(form.username.data, form.password.data) # # if json_r and json_r['status'] == 0 and get_user_type(json_r) == 6: # user = save_user_from_uc(json_r) # add_user(user) # return redirect(referer or url_for('user.dashboard')) # # flash_error(gettext(u'login failed')) return render_template('campaigns/edit.html', selected_menu=selected_menu, campaign=campaign, form=form, back_url=back_url(url_for('campaigns.campaigns')))
def get_lookupvalues_by_lookup_id(uid): return LookupValue.find_all_by_lookup_id(uid)