def preferences(request): context = RequestContext(request) context_dict = get_context_dictionary(request) sports = Sport.objects.all() context_dict['sports'] = sports # Make sure the user is valid. Return 401 Unauthorized if not. if not request.user.is_authenticated() or not request.user.is_active: return HttpResponseRedirect('/login/') profile = UserProfile.objects.get(user=request.user) context_dict['profile'] = profile context_dict['cities'] = City.objects.all().order_by('city') if request.method == "POST": context_dict['updated'] = False form = PreferencesForm(data = request.POST) if form.is_valid(): user = request.user user.last_name = request.POST['last_name'] user.first_name = request.POST['first_name'] user.email = request.POST['email'] if len(request.POST['password']) != 0: user.set_password(request.POST['password']) profile.about = request.POST['about'] cities = City.objects.filter(city=request.POST['city']) if cities.exists(): profile.city = cities[0] user.save() profile.save() context_dict['updated'] = True return render_to_response('preferences.html', context_dict, context)
def preferences(request): form = PreferencesForm(request.POST or None, instance=request.user.userprofile) if form.is_valid(): form.save() return render(request, 'accounts/preferences.html', {'form': form})
def preferences(): form = PreferencesForm() if form.validate_on_submit(): flash('Your changes have been made!', 'success') newsobj = news() newsobj.update(form.query.data, form.time.data, form.sortBy.data) session['articles'] = newsobj.articles return redirect(url_for('home')) return render_template('preferences.html', form=form)
def pref(): form = PreferencesForm() if (request.method == 'POST'): if (form.validate() == False): flash('Please fill all the weightages correctly') return render_template('pref.html', form=form) else: return render_template('base.html') else: return render_template('pref.html', form=form) return render_template('pref.html')
def preferences(request): user = request.user profile = user.get_profile() if request.method == "POST": form = PreferencesForm(request.POST) if form.is_valid(): return HttpResponseRedirect("/user/%d/" % user.id) # Redirect after POST else: form = PreferencesForm({"first_name": user.first_name, "last_name": user.last_name, "email": user.email}) return render_to_response("accounts/preferences.html", {"form": form}, context_instance=RequestContext(request))
def preferences(request, *args, **kws): user = get_requestor(request) try: preferences = user.preference except ObjectDoesNotExist: preferences = Preference(user = user) preferences.save() form = PreferencesForm(initial = {'timeZone' : preferences.timeZone}) if request.method == "POST": form = PreferencesForm(request.POST) if form.is_valid(): preferences.timeZone = form.cleaned_data['timeZone'] preferences.save() return HttpResponseRedirect("/profile/%s" % user.id) return render_to_response('users/preferences.html' , {'form' : form , 'u' : user })
def index(): foodForm = PreferencesForm(csrf_enabled=False) location = request.args.get('location') cache.set('location', location, timeout = 10 * 60) if (request.method == "POST"): lst = [] if (foodForm.indpak.data == "meh"): lst += ["indpak"] if (foodForm.greek.data == "meh"): lst += ["greek"] if (foodForm.thai.data == "meh"): lst += ["thai"] if (foodForm.tradamerican.data == "meh"): lst += ["tradamerican"] if (foodForm.italian.data == "meh"): lst += ["italian"] if (foodForm.norwegian.data == "meh"): lst += ["norwegian"] if (foodForm.mexican.data == "meh"): lst += ["mexican"] if (foodForm.chinese.data == "meh"): lst += ["chinese"] if (foodForm.japanese.data == "meh"): lst += ["japanese"] if (foodForm.pizza.data == "meh"): lst += ["pizza"] if (foodForm.diners.data == "meh"): lst += ["diners"] if len(lst) == 0: lst = ['tradamerican', 'italian', 'indpak', 'norwegian', 'greek','thai', 'mexican', 'chinese', 'japanese', 'pizza', 'diners'] mehfoods = lst api_calls = [] bizlist = [] nbizlist = [] n = len(mehfoods) for x in range (0,n): cat = mehfoods[x] for lat, long in location: params = get_search_parameters(lat, long, cat) api_calls.append(get_results(params)) eateries = api_calls[x][u'businesses']#.sort(key=operator.itemgetter('rating')) api_calls[x][u'businesses'] = reducer(eateries) time.sleep(1.0) l = len(api_calls[x][u'businesses']) bizlist.append(api_calls[x][u'businesses']) h = len(bizlist) for z in range (0, h): nbizlist += bizlist[z] nbizlist.sort(key=operator.itemgetter('distance')) cache.set( nbizlist, CACHE_TIMEOUT)
def create_new(request, template_name): """ Start process of creating new VPN certificate """ if request.method == "POST": if not request.session.test_cookie_worked(): return render_to_response("please_enable_cookies.html", {}, context_instance=RequestContext(request)) request.session.delete_test_cookie() form = PreferencesForm(request.POST) if form.is_valid(): data = {'email': get_user(request.user.username)['mail'][0], 'computer_type': form.cleaned_data['computer_type'], 'computer_owner': form.cleaned_data['computer_owner'], 'employment': form.cleaned_data['employment']} request.session['preferences'] = data return HttpResponseRedirect(reverse('create_new_upload')) else: request.session.flush() request.session['session_enabled'] = True form = PreferencesForm() request.session.set_test_cookie() return render_to_response(template_name, {'form': form}, context_instance=RequestContext(request))
def create_new(request, template_name): """ Start process of creating new VPN certificate """ if request.method == "POST": if not request.session.test_cookie_worked(): return render_to_response("please_enable_cookies.html", {}, context_instance=RequestContext(request)) request.session.delete_test_cookie() form = PreferencesForm(request.POST) if form.is_valid(): data = { 'email': get_user(request.user.username)['mail'][0], 'computer_type': form.cleaned_data['computer_type'], 'computer_owner': form.cleaned_data['computer_owner'], 'employment': form.cleaned_data['employment'] } request.session['preferences'] = data return HttpResponseRedirect(reverse('create_new_upload')) else: request.session.flush() request.session['session_enabled'] = True form = PreferencesForm() request.session.set_test_cookie() return render_to_response(template_name, {'form': form}, context_instance=RequestContext(request))
def preferences(): form = PreferencesForm() print(form.category1.data) print(form.category2.data) print(form.category3.data) print(form.category4.data) print(form.category5.data) print(form.category6.data) print(form.category7.data) print(form.category8.data) print(form.category9.data) print(form.category10.data) print(form.category11.data) if ( form.category1.data or form.category2.data or form.category3.data or form.category4.data or form.category5.data or form.category6.data or form.category7.data or form.category8.data or form.category9.data or form.category10.data or form.category11.data ): response = make_response(redirect('/home')) response.set_cookie(Constants.CATEGORIES[0], str(form.category1.data)) response.set_cookie(Constants.CATEGORIES[1], str(form.category2.data)) response.set_cookie(Constants.CATEGORIES[2], str(form.category3.data)) response.set_cookie(Constants.CATEGORIES[3], str(form.category4.data)) response.set_cookie(Constants.CATEGORIES[4], str(form.category5.data)) response.set_cookie(Constants.CATEGORIES[5], str(form.category6.data)) response.set_cookie(Constants.CATEGORIES[6], str(form.category7.data)) response.set_cookie(Constants.CATEGORIES[7], str(form.category8.data)) response.set_cookie(Constants.CATEGORIES[8], str(form.category9.data)) response.set_cookie(Constants.CATEGORIES[9], str(form.category10.data)) response.set_cookie(Constants.CATEGORIES[10], str(form.category11.data)) return response return render_template('preferences.html', title='Preferences', sidebar_preferences=preferences_from_request(request), form=form)
def preferences(token, header="Update your preferences", subheader="Customize your weather window"): email = auth.decode_token_to_email(token) form = PreferencesForm() if request.method == 'POST': try: form.validate() actions.update_preferences_for_user_from_form(email, form=form) flash( f"We've updated your preferences, thanks. You'll see this reflected in the next " f"weather window we send you!") return redirect(url_for('api.index')) except ValidationError as error: flash(error, category='error') form.initialize_from_db(actions.add_or_return_user_preferences(email)) return render_template('confirm.html', title='Weather Window: Preferences', header=header, subheader=subheader, form=form)
def test_form(test_client, test_app): with test_app.app_context(), test_app.test_request_context(): form = PreferencesForm() yield form
def blackout_worker(request, kind, forObj, b_id, requestor, urlRedirect): "Does most of the work for processing blackout forms" try: # use the requestor's time zone preference - not the users, # since this could be for a project blackout. tz = requestor.preference.timeZone except ObjectDoesNotExist: tz = "UTC" tz_form = PreferencesForm(initial = {'timeZone' : tz}) if request.method == 'POST': tz_form = PreferencesForm(request.POST) if tz_form.is_valid(): tzp = tz_form.cleaned_data['timeZone'] else: tz_form = PreferencesForm() tzp = tz f = BlackoutForm(request.POST) f.format_dates(tzp, request.POST) if f.is_valid(): if request.POST.get('_method', '') == 'PUT': b = Blackout.objects.get(id = b_id) else: if kind == "project_blackout": b = Blackout(project = forObj) else: b = Blackout(user = forObj) b.initialize(tzp, f.cleaned_start, f.cleaned_end, f.cleaned_data['repeat'], f.cleaned_until, f.cleaned_data['description']) revision.comment = get_rev_comment(request, b, "blackout") return HttpResponseRedirect(urlRedirect) else: b = Blackout.objects.get(id = b_id) if b_id is not None else None if request.GET.get('_method', '') == "DELETE" and b is not None: b.delete() return HttpResponseRedirect(urlRedirect) f = BlackoutForm.initialize(b, tz) if b is not None else BlackoutForm() blackoutUrl = "%d/" % int(b_id) if b_id is not None else "" # the forms we render have different actions according to whether # these blackouts are for users or projects if kind == "project_blackout": for_name = forObj.pcode form_action = "/project/%s/blackout/%s" % (forObj.pcode, blackoutUrl) cancel_action = "/project/%s" % forObj.pcode else: for_name = forObj.display_name() form_action = "/profile/%d/blackout/%s" % (forObj.id, blackoutUrl) cancel_action = "/profile/%d" % forObj.id return render_to_response("users/blackout_form.html" , {'form' : f , 'b_id' : b_id , 'action' : form_action , 'cancel' : cancel_action , 'for_name' : for_name , 'tz' : tz , 'tz_form' : tz_form })