Ejemplo n.º 1
0
def add_group_address(group_id):
    group = Group.query.get(group_id)
    if group == None:
        flash("Group not found.")
        return redirect(url_for('index'))
    if not group.is_admin(g.user):
        flash("You are not an admin of this group")
        return redirect(url_for('index'))
    form = AddressForm()
    if form.validate_on_submit():
        group_address = GroupAddress(group = group,
            datetime = form.datetime.data,
            address = form.address.data,
            address2 = form.address2.data,
            city = form.city.data,
            state = form.state.data,
            zipcode = form.zipcode.data,
            directions = form.directions.data)
        db.session.add(group_address)
        db.session.commit()
        flash(gettext('Address was added to your group.'))
        return redirect(url_for('group', group_id = group_id))
    return render_template('add_address.html',
        title = "Add address - {0}".format(group.group_name),
        form = form)
Ejemplo n.º 2
0
def home():
    if "email" not in session:      #AUTHENTICATION IS USED HERE. This process comes under authentication
        return redirect(url_for("login"))   #No longer can access "home" if user is not logged in

    form = AddressForm()

    places = []
    my_coordinates = [37, -122]

    if request.method == "POST":
        if form.validate() == False:
            return render_template("home.html", form=form)
        else:
            # get the address
            address = form.address.data

            # query for places around it
            p = Place()
            my_coordinates = p.address_to_latlng(address)
            places = p.query(address)

            # return those results
            return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places)


    elif request.method == "GET":
        return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places)
Ejemplo n.º 3
0
def home():
	if 'email' not in session:
		return redirect(url_for('login'))

	form = AddressForm()

	places = []
	my_coordinates = (50.45146, 30.52187) #37.4221     -122.0844

	if request.method == 'POST':
		if form.validate() == False:
			return render_template("home.html", form=form)
		else:
			address = form.address.data

			p = Place()
			my_coordinates =p.address_to_latlng(address)
			places = p.query(address)

			return render_template("home.html", 
									form=form,
									my_coordinates=my_coordinates,
									places=places)

	elif request.method == 'GET':
		return render_template("home.html", 
								form=form,
								my_coordinates=my_coordinates,
								places=places)

	return render_template("home.html")
Ejemplo n.º 4
0
def home():
    if 'email' not in session:
        return redirect(url_for('login'))
    form = AddressForm()
    my_coordinates = []
    places = (37.4221, -122.0844)
    if request.method == 'POST':
        if form.validate() == False:
            return render_template('home', form=form)
        else:

            # Get The Address
            address = form.address.data
            # Query the places Around it
            p = Place()
            my_coordinates = p.address_to_latlng(address)
            places = p.query(address)
            # Show the Results
            return render_template('home.html',
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)

    return render_template('home.html',
                           form=form,
                           my_coordinates=my_coordinates,
                           places=places)
Ejemplo n.º 5
0
def home():
    if 'email' not in session:
        return redirect(url_for('login'))

    form = AddressForm()
    places = []
    my_coordinates = (37.4221, -122.0844)

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('home.html', form=form)
        else:
            # get the address
            address = form.address.data
            #address = add

            # query for places around it
            p = Place()
            my_coordinates = p.address_to_latlng(address)
            places = p.query(address)

            # return those results
            return render_template('home.html',
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)

    elif request.method == 'GET':
        return render_template("home.html",
                               form=form,
                               my_coordinates=my_coordinates,
                               places=places)
Ejemplo n.º 6
0
def home():
    if 'email' not in session:
        return redirect(url_for('login'))

    form = AddressForm()
    places = []
    my_coordinates = (37.4221, -122.0844)

    if request.method == 'POST':
        if form.validate() == False:
            return render_template("home.html",
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)
        else:
            address = form.address.data
            p = Place()
            my_coordinates = p.address_to_latlng(address)
            places = p.query(address)
            return render_template("home.html",
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)

    if request.method == 'GET':
        return render_template("home.html",
                               form=form,
                               my_coordinates=my_coordinates,
                               places=places)

    return render_template("home.html")
Ejemplo n.º 7
0
def home():
	if 'email' not in session:
		return redirect(url_for("login"))

	form=AddressForm()

	places = []
	my_coordinates = (30.620949, -96.350764)

	if request.method=="POST":
		if form.validate() == False:
			return render_template("home.html", form=form)
		else:
			# get the address
			address=form.address.data
			print("Hello")

			# query for places around it
			p=Place()
			my_coordinates = p.address_to_latlng(address)
			print(my_coordinates)
			places=p.query(address)

			# return those results
			return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places)

	elif request.method=="GET":
		return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places)
Ejemplo n.º 8
0
def home():
    if 'email' not in session:
        return redirect(url_for('login'))

    # Address Form
    form = AddressForm()

    places = []
    my_coordinates = (47.5729, -117.6822)

    # Checking form submission
    if request.method == 'POST':
        if form.validate() == False:
            return render_template('home.html', form=form)
        else:
            # TODO: get the address
            address = form.address.data

            # TODO: query for places around it
            p = Places()
            my_coordinates = p.address_to_latlng(address)
            places = p.query(address)

            # TODO: return those results
            return render_template('home.html',
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)

    elif request.method == 'GET':
        return render_template('home.html',
                               form=form,
                               my_coordinates=my_coordinates,
                               places=places)
Ejemplo n.º 9
0
def home():
    if 'email' not in session:
        return redirect(url_for("login"))

    form = AddressForm()
    places = []
    my_coordinates = (17.4435, 78.3772)

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('home.html', form=form)
        else:
            address = form.address.data

            p = Place()
            places = p.query(address)

            return render_template('home.html',
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)

    elif request.method == 'GET':
        return render_template("home.html",
                               form=form,
                               my_coordinates=my_coordinates,
                               places=places)
def home():

    form = AddressForm()

    places = []
    my_coordinates = (34.023076, -118.2870456)

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('home.html', form=form)
        else:
            # get the address
            address = form.address.data

            # query for places around it
            p = Place()
            my_coordinates = p.address_to_latlng(address)
            places = p.query(address)

            # return those results
            return render_template('home.html',
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)

    elif request.method == 'GET':
        return render_template("home.html",
                               form=form,
                               my_coordinates=my_coordinates,
                               places=places)
Ejemplo n.º 11
0
def add_address(request):
    if request.method == 'POST':
        form = AddressForm(request.POST)
        if form.is_valid():
            location = Location(house_number=form.cleaned_data['house_number'],
                                street=form.cleaned_data['street'],
                                city_name=form.cleaned_data['city_name'],
                                zip_code=form.cleaned_data['zip_code'])
            location.save()
            coord = find_coordinates(location.house_number, location.street,
                                     location.zip_code, location.city_name)
            location.latitude = float(coord.split(",")[2])
            location.longitude = float(coord.split(",")[3])
            location.save()
            address = Address(user=request.user, location=location)
            address.save()
            request.user.message_set.create(message="Adresse ajoutée.")
            return HttpResponseRedirect('/users/address/edit/%s' % address.id)
        else:
            return render_to_response('users/add_address.html', {'form': form},
                                      RequestContext(request))
    else:
        form = AddressForm()
        return render_to_response('users/add_address.html', {'form': form},
                                  RequestContext(request))
Ejemplo n.º 12
0
def maps():
    #if 'email' not in session:
    #	return redirect(url_for('login'))

    form = AddressForm()
    places = []
    my_coordinates = {}

    if request.method == 'POST':
        if not form.validate():
            return render_template('maps.html', form=form)
        else:
            address = form.address.data

            p = GPlace()
            # geocoder.google(address) isn't doing a great job of getting lat/lng's, often misses
            # Default is WLU
            lat, lng = p.address_to_latlng(address)
            my_coordinates = {"lat": lat, "lng": lng}
            places = p.query(lat, lng)
            print(places)

            return render_template('maps.html',
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)

    elif request.method == 'GET':
        return render_template("maps.html",
                               form=form,
                               my_coordinates=my_coordinates,
                               places=places)
Ejemplo n.º 13
0
def home():
    if "email" not in session:
        return redirect(url_for("login"))

    form = AddressForm()

    places = []
    my_coordinates = (40.7308619, -73.9871558)

    if request.method == "POST":
        if form.validate() == False:
            return render_template("home.html", form=form)
        else:
            # get the address
            address = form.address.data

            # query for places around it
            my_point = Place()
            my_coordinates = my_point.address_to_latlng(address)
            places = my_point.query(address)

            # return those results
            return render_template("home.html",
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)

    elif request.method == "GET":
        return render_template("home.html",
                               form=form,
                               my_coordinates=my_coordinates,
                               places=places)
Ejemplo n.º 14
0
def home():
    #enable this to have user login and permission
    # if 'email' not in session:
    #    return redirect(url_for('login'))

    form = AddressForm()

    places = []
    my_coordinates = (43.6629, -79.3957)

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('home.html', form=form)
        else:
            # get the address
            address = form.address.data

            # query for places around it
            p = Place()
            my_coordinates = p.address_to_latlng(address)
            places = p.query(address)

            # return those results
            return render_template('home.html',
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)

    elif request.method == 'GET':
        return render_template("home.html",
                               form=form,
                               my_coordinates=my_coordinates,
                               places=places)
Ejemplo n.º 15
0
def restaurant_address(name):
	response = make_response(render_template('404.html'))
	session_id = request.cookies.get('session_id')
	result_message = request.args.get('result_message')
	error_message = request.args.get('error_message')
	if session_id:
		flag, result = furls.auth_session_state(session_id)
		if flag and result['role'] == 'Manager':
			session_id = result['session_id']
			flag, restr_result = furls.restaurant_info(result['user_id'])
			flag, address = furls.restaurant_address_list(restr_result['restaurant_id'])	
			form = AddressForm()
			form.city.choices = session.get('cities_list')
			if form.validate_on_submit():
				session.pop('cities_list', None)
				flag, result = furls.restaurant_address_update(address['restaurant_id'], address['id'], form.data)
				if flag:				
					response = redirect(url_for('main.restaurant_address',name=name,result_message='Updated!'))
				else:
					response = redirect(url_for('main.restaurant_address',name=name,error_message=result['message']))
			else:
				flag, cities_result = furls.restaurant_get_cities()
				ch = [(x, x) for x in cities_result['cities_list']  if x != address['city']]
				ch.insert(0, (address['city'],address['city']))
				form.city.choices = ch
				form.station.default = address['station']
				form.process()
				session['cities_list'] = form.city.choices
				response = make_response(render_template('restaurant_addresses.html', result_message=result_message,\
							address=address, form=form, user=restr_result,error_message=error_message))
			response.set_cookie('session_id', session_id)
	return response
Ejemplo n.º 16
0
def home():
    if 'email' not in session:
        return redirect(url_for('login'))

    form = AddressForm()

    places = []
    my_coordinates = (42.650435, -73.758516)

    if request.method == 'POST' and form.validate():
        # get the address
        address = form.address.data

        # query for places around it
        p = Place()
        my_coordinates = p.address_to_latlng(address)
        places = p.query(address)

        # return the results
        return render_template('home.html', form=form,
                                            my_coordinates=my_coordinates,
                                            places=places)
    return render_template('home.html', form=form,
                                        my_coordinates=my_coordinates,
                                        places=places)
Ejemplo n.º 17
0
def client_address_create(name):
	response = render_template('404.html')
	session_id = request.cookies.get('session_id')
	result_message = request.args.get('result_message')
	error_message = request.args.get('error_message')
	if session_id:
		flag, result = furls.auth_session_state(session_id)
		if flag and result['role'] == 'Client':
			flag, uresult = furls.client_info(result['user_id'])
			form = AddressForm()
			flag, restr_result = furls.restaurant_get_cities()
			addresses = [(addr, addr) for addr in restr_result['cities_list']]
			form.city.choices = addresses
			if form.validate_on_submit():
				user_id = result['user_id']
				city = request.form.get('city')
				street = request.form.get('street')
				station = request.form.get('station')
				entrance = request.form.get('entrance')
				floor = request.form.get('floor')
				passcode = request.form.get('passcode')
				flag, aresult = furls.client_address_create(user_id, city, street, station, entrance, passcode, floor)
				if flag:				
					response = redirect(url_for('main.client_address_list', name=name, \
							result_message='Address created!'))
				else:
					response = redirect(url_for('main.client_address_list', name=name, \
							error_message=aresult['message']))
			else:	
				response = make_response(render_template('address_create.html',\
					form=form, user=uresult,name=name))
			response.set_cookie('session_id', result['session_id'])
	return response
Ejemplo n.º 18
0
def login():
    form = AddressForm()
    if form.validate_on_submit():
        global handyrep_address
        handyrep_address = form.address.data
        global username
        username = form.username.data
        global password
        password = form.password.data
        url_to_send = "{address}/get_master_name".format(
            address=handyrep_address)
        try:
            r = requests.get(url_to_send, auth=(username, password))
        except:
            message = "There is something wrong with the address, please try again."
            handyrep_address = None
            username = None
            password = None

            return render_template('login.html', form=form, message=message)
        if r.status_code in range(400, 500):
            if r.status_code == 404:
                return redirect(url_for("page_not_found"))
            message = "Please check username and password"

            return render_template('login.html', form=form, message=message)
        return redirect(request.args.get('next') or url_for('index'))

    return render_template('login.html', form=form)
Ejemplo n.º 19
0
def home():
    if 'email' not in session:
        return redirect(url_for('login'))

    form = AddressForm()

    places = []
    my_coordinates = (33.7489, -84.3789)  # Based on the city of Atlanta

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('home.html', form=form)
        else:
            # get the address
            address = form.address.data

            # query for places around it
            p = Place()
            my_coordinates = p.address_to_latlng(address)
            places = p.query(address)

            # return those results
            return render_template('home.html',
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)

    elif request.method == 'GET':
        return render_template('home.html',
                               form=form,
                               my_coordinates=my_coordinates,
                               places=places)
Ejemplo n.º 20
0
def home():
    if 'email' not in session:
        return redirect(url_for('login'))

    form = AddressForm()

    places = []
    my_coordinates = (66, -99)

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('home.html',
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)
        else:
            address = form.address.data
            print(address)

            p = Place()
            my_coordinates = p.address_to_latlng(address)
            places = p.get_places(*my_coordinates)

            return render_template('home.html',
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)
    elif request.method == 'GET':
        return render_template('home.html',
                               form=form,
                               my_coordinates=my_coordinates,
                               places=places)
Ejemplo n.º 21
0
def home():
  if 'email' not in session:
    return redirect(url_for('login'))

  form = AddressForm()

  places = []
  my_coordinates = (5.3109351,-1.9924259)

  if request.method == 'POST':
    if form.validate() == False:
      return render_template('home.html', form=form)
    else:
      # get the address
      address = form.address.data

      # query for places around it
      p = Place()
      my_coordinates = p.address_to_latlng(address)
      places = p.query(address)

      # return those results
      return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places)

  elif request.method == 'GET':
    return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places)
Ejemplo n.º 22
0
def home():
    if "email" not in session:
        return redirect(url_for("login"))

    form = AddressForm()
    places = []
    my_coordinates = [37.4221, -122.0844]

    if request.method == "POST":
        if not form.validate():
            return render_template("home.html", form=form)
        else:
            # get address
            address = form.address.data
            # query for places
            p = Place()
            my_coordinates = p.address_to_latlng(address)
            places = p.query(address)
            # return results
            return render_template("home.html",
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)
    elif request.method == "GET":
        return render_template("home.html",
                               form=form,
                               my_coordinates=my_coordinates,
                               places=places)
Ejemplo n.º 23
0
def address():
    # Create an address form object
    addressForm = AddressForm()

    # If user clicks submit button
    if addressForm.validate_on_submit():
        fullAddress = ''

        # Store user inputs to their corresponding variables
        address = request.form.get('address')
        city = request.form.get('city')
        state = request.form.get('state')
        zipcode = request.form.get('zipcode')

        # Create full address string
        fullAddress = address + ", " + city + "," + state + " " + zipcode

        # Pass the full address to an api function call and receive data back
        data = business_search(fullAddress)

        # Return a random restaurant url from the data
        randomRestaurant = random.choice(data)

        # redirect user to that url
        return redirect(randomRestaurant)
    return render_template('address.html', form=addressForm)
Ejemplo n.º 24
0
def home():
    if 'email' not in session:  #checks to see if logged in or not
        return redirect(url_for('login'))

    form = AddressForm()

    places = []
    my_coordinates = (41.7508, 88.1535)

    if request.method == 'POST':
        if form.validate() == False:
            my_coordinates = (41.7508, 88.1535)
            return render_template('home.html',
                                   form=form,
                                   my_coordinates=my_coordinates)
        else:
            # get the address
            address = form.address.data
            # query for places around it
            p = Place()
            my_coordinates = p.address_to_latlng(address)
            places = p.query(address)

            # return those results
            return render_template('home.html',
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)

    elif request.method == 'GET':
        return render_template("home.html",
                               form=form,
                               my_coordinates=my_coordinates,
                               places=places)
Ejemplo n.º 25
0
def home():
    if 'email' not in session:
        return redirect(url_for('login'))

    form = AddressForm()
    places = []
    my_coordinates = (37.4221, -122.0844)

    if request.method == "POST":
        if form.validate() == False:
            return render_template("home.html", form=form)
        else:
            #handle good case
            # Get the address
            address = form.address.data

            # Search for places around it
            p = Place()
            my_coordinates = p.address_to_latlng(address)
            places = p.query(address)

            # Return the results
            return render_template("home.html",
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)

    elif request.method == "GET":
        return render_template("home.html",
                               form=form,
                               my_coordinates=my_coordinates,
                               places=places)
Ejemplo n.º 26
0
def login():
    form = AddressForm()
    if form.validate_on_submit():
        global handyrep_address
        handyrep_address = form.address.data
        global username
        username = form.username.data
        global password
        password = form.password.data
        url_to_send = "{address}/get_master_name".format(address=handyrep_address)
        try:
            r = requests.get(url_to_send, auth=(username, password))
        except:
            message = "There is something wrong with the address, please try again."
            handyrep_address = None
            username = None
            password = None

            return render_template('login.html', form=form, message=message)
        if r.status_code in range(400, 500):
            if r.status_code == 404:
                return redirect(url_for("page_not_found"))
            message = "Please check username and password"

            return render_template('login.html', form=form, message=message)
        return redirect(request.args.get('next') or url_for('index'))

    return render_template('login.html', form=form)
Ejemplo n.º 27
0
def home():
    if 'email' not in session:
        return redirect(url_for('login'))

    form = AddressForm()

    places = []
    my_coordinates = (45.975589, 15.060825)

    if request.method == 'POST':
        if not form.validate():
            return render_template('home.html', form=form)
        else:
            # get the address
            address = form.address.data
            # query for places around it
            p = Place()
            my_coordinates = p.address_to_latlng(address)
            places = p.query(address)
            # return those results
            return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places)

    elif request.method == 'GET':
        return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places)

    return render_template('home.html')
Ejemplo n.º 28
0
def home(id=None):
    if 'email' not in session:  # used to avoid login page if user already login
        return redirect(url_for('login'))
    # q = User.query.get(id)
    user = User.query.filter_by(email=session['email']).first()
    form = AddressForm()
    places = []
    my_coord = (37.4332, -122.0844)
    if request.method == 'POST':
        if form.validate() == False:
            return render_template("home.html", **dict(user=user, form=form))
        else:
            #get the add
            address = form.address.data
            #query for add
            p = Place()
            my_coord = p.address_to_latlang(address)
            places = p.query(address)

            # return those results
            return render_template(
                'home.html',
                **dict(user=user, form=form, my_coord=my_coord, places=places))
    elif request.method == 'GET':
        return render_template(
            "home.html",
            **dict(user=user, form=form, my_coord=my_coord, places=places))
    else:
        return "else"
Ejemplo n.º 29
0
def nearby(tid):
    """Nearby uses flask_wtform and wikipedia apis.

    Get the address, query for places around it
    (currently wikipedia, may become locations of tickets),
    return results.
    """
    tid = tid
    ticket = Ticket.query.get(tid)
    pickup_address = ticket.pickup_address
    pickup_ll = geocoder.google(pickup_address)
    p_lat, p_lng = pickup_ll.lat, pickup_ll.lng
    form = AddressForm()
    places = []
    my_coordinates = (p_lat, p_lng)
    lat_lng = (p_lat, p_lng)

    if request.method == 'POST':
        if form.validate() is False:
            return render_template('nearby.html', form=form, tid=tid,
                                   ticket=ticket)
        else:
            address = form.address.data
            p = Place()
            my_coordinates = p.address_to_latlng(address)
            places = p.main(address)

            return render_template('nearby.html', form=form, places=places,
                                   my_coordinates=my_coordinates, tid=tid,
                                   lat_lng=lat_lng, ticket=ticket)

    elif request.method == 'GET':
        return render_template("nearby.html", form=form, places=places,
                               my_coordinates=my_coordinates, tid=tid,
                               lat_lng=lat_lng, ticket=ticket)
Ejemplo n.º 30
0
def home():
	if 'email' not in session:
		return redirect(url_for('login'))
	
	form = AddressForm()
	places = []
	my_coordinates = (37.4221, -122.0844)
	
	if request.method == "POST":
		if form.validate() == False:
			return render_template("home.html", form=form)
		else:
			# get the address
			address = form.address.data

			# query for addresses nearby
			p = Place()

			my_coordinates = p.address_to_latlng(address)
			places = p.query(address)


			# return those results
			return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places)
			

	elif request.method == "GET":
		return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places)
Ejemplo n.º 31
0
def home():
    form = AddressForm()

    places = []
    my_coordinates = (37.4221, -122.0844)

    if 'email' not in session:
        return redirect(url_for('login'))

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('home.html', form=form)
        else:
            #get the address
            address = form.address.data

            #want to use geodata api - make a model (models.py)
            #query places around address
            p = Place()
            my_coordinates = p.address_to_latlng(address)
            places = p.query(address)

            return render_template('home.html',
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)

    elif request.method == 'GET':
        return render_template("home.html",
                               form=form,
                               my_coordinates=my_coordinates,
                               places=places)
Ejemplo n.º 32
0
def home():
    if 'email' not in session:
        return redirect(url_for('login'))

    form = AddressForm()

    places = []
    my_coordinates = (40.7127750, -74.0059730)

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('home.html', form=form)
        else:
            #get address
            address = form.address.data

            #search places around it
            p = Place()
            my_coordinates = p.address_to_latlng(address)
            places = p.query(address)

            #return results

            return render_template('home.html',
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   places=places)

    elif request.method == 'GET':
        return render_template('home.html',
                               form=form,
                               my_coordinates=my_coordinates,
                               places=places)
Ejemplo n.º 33
0
def home():
    if 'email' not in session:
        return redirect(url_for('login'))

    form = AddressForm()
    buses = []
    my_coordinates = (38.905276, -76.981588)

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('home.html', form=form)
        else:
            # get the address
            address = form.address.data
            #query for buses around it
            b = Bus()
            my_coordinates = b.address_to_latlng(address)

            buses, closest = b.query(address)
            #return those results
            return render_template('home.html',
                                   form=form,
                                   my_coordinates=my_coordinates,
                                   buses=buses,
                                   closest=closest)

    elif request.method == 'GET':
        bad = {'name': '______', 'own': '______', 'dist': '______'}
        return render_template('home.html',
                               form=form,
                               my_coordinates=my_coordinates,
                               buses=buses,
                               closest=bad)
Ejemplo n.º 34
0
def home():
    form = AddressForm()
    places, lat_lon = [], (12.836649, 77.655809)
    if request.method == 'POST':
        if not form.validate():
            return render_template('home.html', form=form)
        else:
            address = form.address.data
            p = Place()
            fetched_lat_lon = p.address_to_latlng(address)

            if any(lat_lon):
                places = p.query(address)
                return render_template('home.html',
                                       form=form,
                                       my_coordinates=fetched_lat_lon,
                                       places=places)
            else:
                return render_template('home.html', form=form)

    elif request.method == 'GET':
        return render_template('home.html',
                               form=form,
                               my_coordinates=lat_lon,
                               places=places)
Ejemplo n.º 35
0
def edit_address(request, address_id):
    try:
        address = Address.objects.get(pk=address_id)
        if address.user == request.user:
            if request.method == 'POST':
                form = AddressForm(request.POST)
                if form.is_valid():
                    address.location.house_number = form.cleaned_data['house_number']
                    address.location.street = form.cleaned_data['street']
                    address.location.city_name = form.cleaned_data['city_name']
                    address.location.zip_code = form.cleaned_data['zip_code']
                    address.location.save()
                    coord = find_coordinates(address.location.house_number,address.location.street,address.location.zip_code,address.location.city_name)
                    address.location.latitude = float(coord.split(",")[2])
                    address.location.longitude = float(coord.split(",")[3])
                    address.location.save()
                    request.user.message_set.create(message="Adresse modifiée.")
                    return HttpResponseRedirect('/users/address/edit/%d'% address.id)
                else:
                    return render_to_response('users/add_address.html', {'form':form},RequestContext(request))
            else:
                data = pre_fill_address(address)
                form = AddressForm(data)
                return render_to_response('users/add_address.html', {'form':form},RequestContext(request))
        else:
            request.user.message_set.create(message="Vous ne pouvez pas modifier cette adresse.")
            return HttpResponseRedirect('/users/%d/'% address.user.id)
    except Address.DoesNotExist:
        request.user.message_set.create(message="L'adresse demandée n'existe pas.")
        return HttpResponseRedirect('/users/%d/'%request.user.id)
Ejemplo n.º 36
0
def home():
	if 'email' not in session:
		return redirect(url_for('login'))

	form = AddressForm()

	places = []
	my_coordinates = (37.4221, -122.0844)

	if request.method == 'POST':
		if not form.validate():
			return render_template('home.html', form=form)

		# Handle the Form here.
		# Get the adress.
		address = form.address.data

		# Query for places around it.
		p = Place()
		my_coordinates = p.address_to_latlng(address)
		places = p.query(address)

		# Return those results.
		return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places)
	elif request.method == 'GET':
		return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places)
Ejemplo n.º 37
0
def edit_address():
    user = current_user._get_current_object()
    if user == None:
        abort(404)

    province_select = u''
    city_select = u''
    district_select = u''

    id = request.args.get('id', -1, type=int)
    if id != -1:
        address = Address.query.get_or_404(id)
        province_select = address.province
        city_select = address.city
        district_select = address.district
    else:
        address = Address()
        address.user_id = user.id
    province_select = request.args.get('province', province_select)
    city_select = request.args.get('city', city_select)
    district_select = request.args.get('district', district_select)
    form = AddressForm(province=province_select,
                       city=city_select,
                       district=district_select,
                       street=address.street,
                       reciplents=address.reciplents,
                       zip_code=address.zip_code,
                       phone_number=address.phone_number)
    province_choices = [(u'', u'')] + [(p.name, p.name)
                                       for p in Province.query.all()]
    form.province.choices = province_choices

    province_in_form = Province.query.filter_by(name=province_select).first()
    if province_in_form:
        city_choices = [((u'', u''))] + [(c.name, c.name)
                                         for c in province_in_form.citys]
        form.city.choices = city_choices

    city_in_form = City.query.filter_by(name=city_select).first()
    if city_in_form:
        district_choices = [(u'', u'')] + [(d.name, d.name)
                                           for d in city_in_form.districts]
        form.district.choices = district_choices

    if form.validate_on_submit():
        address.province = form.province.data
        address.city = form.city.data
        address.district = form.district.data
        address.street = form.street.data
        address.reciplents = form.reciplents.data
        address.zip_code = form.zip_code.data
        address.phone_number = form.phone_number.data
        print address.province
        db.session.add(address)
        return redirect(request.args.get('next') or url_for('mall.address'))

    return render_template('edit_address.html', form=form)
Ejemplo n.º 38
0
def customer_custom_addr_create(request):
    address_form = AddressForm(request.POST)
    if address_form.is_valid():
        address_dict = address_form.cleaned_data
        customer_model = request.user_meta['customer_model']
        addr_bean = customer.create_custom_addr(customer_model, address_dict)
        return json_response_from_object(OK, addr_bean)
    else:
        return json_response(PARAM_REQUIRED, address_form.errors)
Ejemplo n.º 39
0
def index():
    form = AddressForm()
    if form.validate_on_submit():
        return redirect(url_for('civics.get_reps',
                                street=form.street.data,
                                city=form.city.data,
                                state=form.state.data,
                                zip=form.zip.data))
    return render_template('submit_address.html', title='Address', form=form)
Ejemplo n.º 40
0
def edit_address():
    user = current_user._get_current_object()
    if user == None:
        abort(404)  
    
    province_select = u''
    city_select = u''
    district_select = u''
    
    id = request.args.get('id', -1, type=int)
    if id!=-1:
        address = Address.query.get_or_404(id)
        province_select = address.province
        city_select = address.city
        district_select = address.district
    else:
        address = Address()
        address.user_id = user.id
    province_select = request.args.get('province', province_select)
    city_select = request.args.get('city', city_select)
    district_select = request.args.get('district', district_select)
    form = AddressForm(
        province = province_select, 
        city = city_select, 
        district = district_select,
        street = address.street,
        reciplents = address.reciplents,
        zip_code = address.zip_code,
        phone_number = address.phone_number)
    province_choices = [(u'',u'')] + [ (p.name, p.name) for p in Province.query.all() ]
    form.province.choices =  province_choices
    
    province_in_form = Province.query.filter_by(name=province_select).first()
    if province_in_form:
        city_choices = [((u'',u''))] + [(c.name, c.name) for c in province_in_form.citys]
        form.city.choices = city_choices

    city_in_form = City.query.filter_by(name=city_select).first()
    if city_in_form:
        district_choices = [(u'', u'')] + [ (d.name, d.name) for d in city_in_form.districts ]
        form.district.choices = district_choices
        
    if form.validate_on_submit():        
        address.province = form.province.data
        address.city = form.city.data
        address.district = form.district.data
        address.street = form.street.data
        address.reciplents = form.reciplents.data
        address.zip_code = form.zip_code.data
        address.phone_number = form.phone_number.data
        print address.province
        db.session.add(address)
        return redirect(request.args.get('next') or url_for('mall.address'))

    return render_template('edit_address.html', form=form)
Ejemplo n.º 41
0
Archivo: views.py Proyecto: eknuth/pimh
def get_neighborhood(request):
    if request.method == 'POST': # If the form has been submitted...
        form = AddressForm(request.POST)
        if form.is_valid():
            n = get_neighborhood_by_address(form.cleaned_data['address'])
            return HttpResponseRedirect('/neighborhood/%s' % n.slug)
    else:
        form = AddressForm()
        return render_to_response('homeland.html', {
                'form': form,
                })
Ejemplo n.º 42
0
def ajax_addresses(request):
    split={}
    
    if request.is_ajax():
        form=AddressForm(request.GET)
        if form.is_valid():
            cd = form.cleaned_data
            sr = SplitAddress.Splitter_Regex()
            split = SplitAddress.Splitter(sr,cd['address1'],cd['address2'],cd['has_attn']).addys
            #return render(request,'address_checker/splitter.html',context)
            return HttpResponse(json.dumps(split), content_type="application/json")
Ejemplo n.º 43
0
def home():

    form = AddressForm()

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('home.html', form=form)
        else:
            pass

    elif request.method == 'GET':
         if 'email' not in session :
             return redirect(url_for('signin'))
         return render_template('home.html', form= form)
Ejemplo n.º 44
0
    def post(self, request, *args, **kwargs):
        restaurant_form = RestaurantForm(request.POST, request.FILES, prefix='restaurant')
        address_form = AddressForm(request.POST, prefix='address')

        if not (restaurant_form.is_valid() and address_form.is_valid()):
            return render(request, 'business/edit_restaurant_page.html',
                          {'restaurant_form': restaurant_form, 'address_form': address_form})

        restaurant = Restaurant.objects.get(baseUser=request.user)
        address = Address.objects.get(restaurant=restaurant)

        RestaurantForm(request.POST, request.FILES, prefix='restaurant', instance=restaurant).save()
        AddressForm(request.POST, prefix='address', instance=address).save()

        return HttpResponseRedirect(reverse('business:RestaurantPage'))
Ejemplo n.º 45
0
def registration(request):
    #return HttpResponse("Done")
    """
    form = OnBoardingForm()
    c = {'form':form}
    c.update(csrf(request))
    return render_to_response("login_admin/PlayersRegistration.html",c)
    """
    context = RequestContext(request)
    if request.method == 'POST':
        form = OnBoardingForm(request.POST)
        form1=AddressForm(request.POST)
        print 'abcdef'
        print form['first_name'].value()
        ffirst_name=form['first_name'].value()
        fmiddle_name=form['middle_name'].value()
        flast_name=form['last_name'].value()
        femail_id=form['email_id'].value()
        fcontact_no=form['contact_no'].value()
        fsports=form['sports'].value()
        print fsports
        ftotal_yrs_exp=form['total_yrs_exp'].value()
        fsec_ques1=form['sec_ques1'].value()
        fsec_ans1=form['sec_ans1'].value()
        fsec_ques2=form['sec_ques2'].value()
        fsec_ans2=form['sec_ans2'].value()
        frole=form['role'].value()       
        if form.is_valid():
            
            #Rohini changes
            key=form1.save()     
            form=Onboarding.objects.create(first_name=ffirst_name,middle_name=fmiddle_name,last_name=flast_name,email_id=femail_id,contact_no=fcontact_no,sports_id=fsports,total_yrs_exp=ftotal_yrs_exp,sec_ques_id=fsec_ques1,sec_ans1=fsec_ans1,sec_ans2=fsec_ans2,address_id=key.address_id,role_id=frole)
            form.save()
            print 'after saving form'
          
        else:
            # The supplied form contained errors - just print them to the terminal.
            print form.errors
    else:
        # If the request was not a POST, display the form to enter details.
        form = OnBoardingForm()
    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    form = OnBoardingForm()
    c = {'form':form}
    c.update(csrf(request))
Ejemplo n.º 46
0
def manage_address(request, address_id = None):
    '''Add an address to the user's address book'''
    context = {}
    next = request.GET.get('next','browse_addresses')
    context['next'] = next

    if address_id:
        try:
            address = Address.objects.get( id = int(address_id),
                user = request.user, ab_type = 1 )
        except ObjectDoesNotExist:
            raise Http404

    if request.method == 'POST':
        if request.POST.has_key('cancel'):
            return redirect(next)
        if address_id:
            form = AddressForm(request.POST, instance = address)
        else:
            form = AddressForm(request.POST)
        if form.is_valid():
            # Save the new address
            address = form.save(commit=False)
            address.user = request.user
            address.imap_server = request.session['host']
            address.ab_type = 1
            address.save()
            return redirect(next)
        else:
            # Show errors:
            context['form'] = form
    else:
        # Empty form
        if address_id:
            context['form'] = AddressForm(instance = address)
        else:
            # Try to get initialization values
            first_name = request.GET.get('first_name','')
            last_name = request.GET.get('last_name','')
            email = request.GET.get('email','')
            context['form'] = AddressForm(data = {'first_name':first_name,
                                                  'last_name':last_name,
                                                  'email':email})

    return render_to_response('sab/manage_address.html', context ,
        context_instance=RequestContext(request))
Ejemplo n.º 47
0
def editAddress():
    form = AddressForm(request.form)
    if form.validate_on_submit():
        address = form.address.data
        print address
        newAddress = Address(address)
        print newAddress.address
        db.session.add(newAddress)
        db.session.commit()
        return 'success'

    addresses = Address.query.all()
    return render_template(
            'admin/address.html',
            form=form,
            addresses=addresses
            )
Ejemplo n.º 48
0
def home():
	if 'email' not in session:
		return redirect(url_for('login'))
	form = AddressForm()
	places = []
	my_coords = geocoder.google('Mountain View, CA').latlng
	if request.method == 'POST':
		if not form.validate():
			return render_template('home.html', form=form, my_coords=my_coords)
		else:
			address = form.address.data
			p = Place()
			my_coords = p.address_to_latlng(address)
			places = p.query(address)
			return render_template('home.html', form=form, my_coords=my_coords, places=places)
	elif request.method == 'GET':
		return render_template('home.html', form=form, my_coords=my_coords,places=places)
Ejemplo n.º 49
0
    def post(self, request, *args, **kwargs):

        restaurant_form = RestaurantForm(request.POST, request.FILES, prefix='restaurant')
        address_form = AddressForm(request.POST, prefix='address')

        if not (restaurant_form.is_valid() and address_form.is_valid()):
            return render(request, 'business/signup.html',
                          {'restaurant_form': restaurant_form, 'address_form': address_form})

        restaurant = restaurant_form.save(commit=False)
        restaurant.baseUser = request.user
        restaurant.save()

        address = address_form.save(commit=False)
        address.restaurant = restaurant
        address.save()

        return HttpResponseRedirect(reverse('business:RestaurantPage'))
Ejemplo n.º 50
0
def client_address_update(name, address_id):
	response = render_template('404.html')
	session_id = request.cookies.get('session_id')
	result_message = request.args.get('result_message')
	error_message = request.args.get('error_message')
	if session_id:
		flag, result = furls.auth_session_state(session_id)
		if flag and result['role'] == 'Client':
			flag, uresult = furls.client_info(result['user_id'])
			form = AddressForm()
			city = request.args.get('city')
			flag, restr_result = furls.restaurant_get_cities()
			form.city.choices = [(addr, addr) for addr in restr_result['cities_list'] if addr != city]
			form.city.choices.insert(0, (city, city))
			if form.validate_on_submit():
				city = request.form.get('city')
				street = request.form.get('street')
				station = request.form.get('station')
				entrance = request.form.get('entrance')
				floor = request.form.get('floor')
				passcode = request.form.get('passcode')	
				flag, restr_result = furls.client_address_update(address_id, city,\
					street, station, entrance, passcode, floor)
				if flag:
					response = redirect(url_for('main.client_address_list',\
						name=name, address_id=address_id,result_message='Updated!'))
				else:
					response = redirect(url_for('main.client_address_list',\
						name=name, address_id=address_id,error_message=restr_result['message']))
			else:
				city = request.args.get('city')
				street = request.args.get('street')
				station = request.args.get('station')
				entrance = request.args.get('entrance')
				floor = request.args.get('floor')
				passcode = request.args.get('passcode')
				response = make_response(render_template('addresses_edit.html', \
					user=uresult, form=form, city=city, street=street, station=station,\
					entrance=entrance, passcode=passcode, floor=floor, address_id=address_id))
			response.set_cookie('session_id', result['session_id'])	
	return response
Ejemplo n.º 51
0
def add_address(request):
    if request.method == 'POST':
        form = AddressForm(request.POST)
        if form.is_valid():
            location = Location(house_number=form.cleaned_data['house_number'],
                                street=form.cleaned_data['street'],
                                city_name=form.cleaned_data['city_name'],
                                zip_code=form.cleaned_data['zip_code'])
            location.save()
            coord = find_coordinates(location.house_number,location.street,location.zip_code,location.city_name)
            location.latitude = float(coord.split(",")[2])
            location.longitude = float(coord.split(",")[3])
            location.save()
            address = Address(user=request.user,location=location)
            address.save()
            request.user.message_set.create(message="Adresse ajoutée.")
            return HttpResponseRedirect('/users/address/edit/%s'%address.id)
        else:
            return render_to_response('users/add_address.html', {'form':form},RequestContext(request))
    else:
        form = AddressForm()
        return render_to_response('users/add_address.html', {'form':form},RequestContext(request))
Ejemplo n.º 52
0
def edit_address(request):
    if request.user.is_superuser:
        return HttpResponseRedirect('/admin')
    profile = request.user.profile
    if profile.has_address():
        address = profile.address
    else:
        address = Address()
    if request.method == 'POST':
        form = AddressForm(request.POST, instance=address)
        if form.is_valid():
            address = form.save()
            if not profile.has_address():
                profile.address = address
                profile.status = 'present'
                profile.is_admin = True
                profile.user.is_staff = True
                profile.user.groups.add(Group.objects.get(name='Flat Admin'))
                profile.save()
                profile.user.save()
                return HttpResponseRedirect('/item/')
    else:
        form = AddressForm(instance=address)
    return render_to_response('address.html', {'form': form}, context_instance=RequestContext(request))