Ejemplo n.º 1
0
def register_startup(request):
    if request.user.is_authenticated:
        HttpResponseRedirect('/profile/' + str(request.user.id))
    user_form = RegisterForm(request.POST)
    address_form = AddressForm(request.POST)
    startup_form = StartupForm(request.POST, request.FILES)
    context = {
        'user_form': user_form,
        'address_form': address_form,
        'startup_form': startup_form,
    }
    if request.method == 'POST':
        if user_form.is_valid() and startup_form.is_valid(
        ) and address_form.is_valid():
            user_form.save()
            temp = startup_form.save(commit=False)
            temp.user = User.objects.latest('date_joined')
            Group.objects.get(name='Startup').user_set.add(temp.user)
            cleaned_info = address_form.cleaned_data
            go = form_address_exists(cleaned_info)
            if go == None:
                address_form.save()
                temp.address = Address.objects.all().order_by("-id")[0]
            else:
                temp.address = go
            temp.save()
            startup_form.save_m2m()
            user = authenticate(username=user_form.cleaned_data["username"],
                                password=user_form.cleaned_data["password1"])
            auth_login(request, user)
            return HttpResponseRedirect('/profile/' + str(temp.user.id))
    return render(request, 'register_startup.html', context)
Ejemplo n.º 2
0
def edit_address():
    form = AddressForm(current_user.username)
    if form.validate_on_submit():
        language = guess_language(form.address.data)
        if language == 'UNKNOWN' or len(language) > 5:
            language = ''
        address = Address(body=form.address.data, author=current_user)
        db.session.add(address)
        db.session.commit()
        flash(_('Your changes have been saved.'))
        return redirect(url_for('edit_address'))
    page = request.args.get('page', 1, type=int)
    addresses = current_user.addresses.order_by(
        Address.timestamp.desc()).paginate(page, 25, False)
    next_url = url_for('index', page=addresses.next_num) \
        if addresses.has_next else None
    prev_url = url_for('index', page=addresses.prev_num) \
        if addresses.has_prev else None

    return render_template('edit_address.html',
                           title=_('Edit Address'),
                           form=form,
                           addresses=addresses.items,
                           next_url=next_url,
                           prev_url=prev_url)
Ejemplo n.º 3
0
def edit_address(address_id):
    address = Address.query.get(address_id)
    if not address or address.user_id != current_user.id:
        return redirect(url_for('address_book'))

    form = AddressForm()
    if form.validate_on_submit():
        address.first_name = form.first_name.data.title()
        address.last_name = form.last_name.data.title()
        address.address = form.address.data.title()
        address.city = form.city.data.title()
        address.state = form.state.data
        address.zip_code = form.zip_code.data

        db.session.commit()
        return redirect(url_for('address_book'))

    form.first_name.data = address.first_name
    form.last_name.data = address.last_name
    form.address.data = address.address
    form.city.data = address.city
    form.state.data = address.state
    form.zip_code.data = address.zip_code

    return render_template(
        'address_form.html',
        form=form,
        form_title="Edit Address",
    )
Ejemplo n.º 4
0
def signup():
    version = randint(0, 1000000)
    login = LoginForm()
    address = AddressForm()
    if address.validate_on_submit():
        x, y = get_lambert(address.address.data)
        size = int(address.window.data)
        tif = GeoTIFF.get_tif_from_point(x, y).crop_location(x, y, size, size)
        if address.projection.data == "2D": tif.png()
        else:
            xaxis = go.XAxis(range=[0.2, 1],
                             showgrid=False,
                             zeroline=False,
                             visible=False)
            yaxis = go.YAxis(range=[0.2, 1],
                             showgrid=False,
                             zeroline=False,
                             visible=False)
            layout = go.Layout(xaxis=xaxis,
                               yaxis=yaxis,
                               paper_bgcolor='rgba(0,0,0,0)',
                               scene_aspectmode='manual',
                               scene_aspectratio=dict(x=1.5, y=1.5, z=0.5),
                               margin=dict(l=0, r=0, b=0, t=0))
            fig = go.Figure(data=[go.Surface(z=tif.arr)], layout=layout)
            fig.write_image(directory + "/app/static/plot.png")

    return render_template("geoloc.html",
                           version=version,
                           form={
                               "login": login,
                               "address": address
                           })
Ejemplo n.º 5
0
 def test_AddressForm_invalid(self):
     form = AddressForm(
         data={
             'postal_code': "",
             'city': "Oslo",
             'street_address': "Teppeveien 22B",
             'country': "Mongolia"
         })
     self.assertFalse(form.is_valid())
Ejemplo n.º 6
0
def textaddress():
    #adding form that accepts address
    form = AddressForm()

    # text to address and value form
    if form.validate_on_submit():

        address = form.address.data

        # bing address grabber
        bing_locator = geocoders.Bing(bing_key)
        address = bing_locator.geocode(address).raw

        # Zillow call (could be replaced with Zillow function)
        zillow_api = zillow.ValuationApi()
        house = address['address']['addressLine']
        postal_code = address['address']['postalCode']

        house_data = zillow_api.GetSearchResults(zillow_key, house,
                                                 postal_code)
        price = house_data.zestimate.amount

        # set address back to street address and zip code
        address = address['name']

        ### START GOOGLE STREET VIEW IMAGE HANDLING ###

        # Set image_url to Google Street View of address

        image_url = f'https://maps.googleapis.com/maps/api/streetview?size=600x600&location={address}&key={google_key}'

        # Image write out to uploads folder
        image = requests.get(image_url)

        basepath = os.path.abspath('app/')
        filelist = re.findall(r'\w+', address)
        filename = ''.join(filelist)
        final_path = f'{basepath}/uploads/{filename}.jpg'
        open(f'{final_path}', 'wb').write(image.content)

        # render template with passed variables when form validates
        return render_template('text_form.html',
                               title='Output',
                               price=price,
                               address=address,
                               file_path=f'{filename}.jpg',
                               photo=open(f'{final_path}', 'rb'))

    #keep same page with form if form does not validate
    return render_template('textaddress.html',
                           title='Submit Address',
                           form=form)
Ejemplo n.º 7
0
def textaddress():
    form = AddressForm()

    if form.validate_on_submit():
        # flash('Login requested for user {}'.format(form.address.data))

        address = form.address.data

        bing_key = ''
        bing_locator = geocoders.Bing(bing_key)
        address = bing_locator.geocode(address).raw

        zillow_key = ''
        zillow_api = zillow.ValuationApi()
        house = address['address']['addressLine']
        postal_code = address['address']['postalCode']

        house_data = zillow_api.GetSearchResults(zillow_key, house,
                                                 postal_code)
        price = house_data.zestimate.amount
        address = address['name']

        google_key = ''

        ### START GOOGLE STREET VIEW IMAGE HANDLING ###

        # Set image_url to Google Street View of address
        # I don't know how this will need to be saved / returned for use in Flask
        image_url = f'https://maps.googleapis.com/maps/api/streetview?size=600x600&location={address}&key={google_key}'

        # Put image handling code for Flask here
        image = requests.get(image_url)

        basepath = os.path.abspath('app/')
        filelist = re.findall(r'\w+', address)
        filename = ''.join(filelist)
        final_path = f'{basepath}/uploads/{filename}.jpg'
        open(f'{final_path}', 'wb').write(image.content)

        return render_template('text_form.html',
                               title='Output',
                               price=price,
                               file_path=f'{filename}.jpg',
                               photo=open(f'{final_path}', 'rb'))

        # return redirect('/textaddress')

    return render_template('textaddress.html',
                           title='Submit Address',
                           form=form)
Ejemplo n.º 8
0
def geocode():
    form = AddressForm()
    if form.validate_on_submit():
        geocode_string = {'addressLine': form.address.data}
        geocode_response = requests.request('GET',
                                            geocode_url,
                                            headers=headers,
                                            params=geocode_string)

        flash('Geocode Requested For: {} and geocode string {}'.format(
            form.address.data, geocode_string))
        flash(geocode_response.text)

        return redirect(url_for('geocode'))
    return render_template('geocode.html', form=form)
Ejemplo n.º 9
0
def create():
    """ Address New """
    form = AddressForm()
    if form.validate_on_submit():
        form_data = {
            'name': form.name.data,
            'address': form.address.data,
            'zip': form.zip.data,
            'city': form.city.data,
            'state': form.state.data
        }
        validator = ZipService()
        validator.validate_address(form_data)
        flash('{} Created Successfully'.format(form.name.data))
        return redirect('/')
    return render_template('create.html', form=form)
Ejemplo n.º 10
0
def create_address(request):
    if request.method == 'POST':
        form = AddressForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            data['user'] = request.session['user']['id']
            response = api_create_address(data, request.session['user']['token'])
            if response.ok:
                return HttpResponseRedirect(reverse('profile'))
            return render(request, 'address/create_address.html', {
                'form': form, 'errors': response.json()['errors']
            })
    else:
        form = AddressForm()

    return render(request, 'address/create_address.html', {'form': form})
Ejemplo n.º 11
0
def add_address():
    form = AddressForm()
    if form.validate_on_submit():
        address = Address(first_name=form.first_name.data.title(),
                          last_name=form.last_name.data.title(),
                          address=form.address.data.title(),
                          city=form.city.data.title(),
                          state=form.state.data,
                          zip_code=form.zip_code.data,
                          user_id=current_user.id)
        db.session.add(address)
        db.session.commit()
        return redirect(url_for('address_book'))

    return render_template('address_form.html',
                           form=form,
                           form_title='Add A New Address')
Ejemplo n.º 12
0
def edit_person(request):
    user = request.user
    group = user.groups.first()
    if str(group) == "Person":
        person = get_object_or_404(Person, user_id=user.id)
        address = person.address
        if request.method == 'POST':
            user_form = UpdateForm(
                request.POST,
                instance=user,
                initial={'fullname': user.first_name + " " + user.last_name})
            address_form = AddressForm(request.POST, instance=address)
            person_form = PersonForm(request.POST,
                                     request.FILES,
                                     instance=person)
            if user_form.is_valid() and address_form.is_valid(
            ) and person_form.is_valid():
                user_form.save()
                address_form.save()
                person_form.save()
                return HttpResponseRedirect("/profile/" + str(user.id) + "/")
        else:
            user_form = UpdateForm(
                instance=user,
                initial={'fullname': user.first_name + " " + user.last_name})
            address_form = AddressForm(instance=address)
            person_form = PersonForm(instance=person)
        context = {
            'user_form': user_form,
            'address_form': address_form,
            'person_form': person_form,
        }
        return render(request, 'edit_person.html', context)
    else:
        return HttpResponseRedirect("/index/")
Ejemplo n.º 13
0
def hazard():
    form = AddressForm()
    if form.validate_on_submit():
        hazard_request = dict(
            reportList=
            'floodRatingFEMA,floodRiskScore,slosh,stormSurge,propertyInformation,wildfireRiskScore',
            addressLine=form.address.data)
        resp = requests.request('GET',
                                reports_url,
                                headers=headers,
                                params=hazard_request)

        flash('Hazard Requested For: {}'.format(form.address.data))
        flash(resp.text)

        return redirect(url_for('hazard'))

    return render_template('hazard.html', form=form)
Ejemplo n.º 14
0
def address():
    form = AddressForm(request.form)
    addr = models.User.query.filter_by(id=current_user.id).first().addr

    if form.validate() and not addr:
        new = models.Address(
            form.addr.data,
            form.city.data,
            form.state.data,
            form.zip.data,
            form.radius.data,
            current_user.id
        )
        db.session.add(new)
        db.session.commit()
        flash('Address added!')
    else:
        flash('You can only have one address.')

    return redirect(url_for('user_config'))
Ejemplo n.º 15
0
def getAddressForm():
    form = AddressForm()
    print("form.data", form.data)
    form['csrf_token'].data = request.cookies['csrf_token']
    print(",,,,,,,,,,,,,,,,,,,,,,,,,,,", form['csrf_token'].data)

    if form.validate_on_submit():
        streetData = form.data['street_address']
        cityData = form.data['city']
        stateData = form.data['state']
        zipData = form.data['zip_code']
        address = Address(userId=current_user.id,
                          street_address=streetData,
                          city=cityData,
                          state=stateData,
                          zip_code=zipData)
        db.session.add(address)
        db.session.commit()
        return "hello"
    print("did not work")
    return "error: address incomplete"
Ejemplo n.º 16
0
def edit_address(request, address_id):
    response = api_get_address(address_id, request.session['user']['token'])
    if response.ok:
        address = response.json()
        if request.method == 'POST':
            form = AddressForm(request.POST)
            if form.is_valid():
                data = form.cleaned_data
                data['user'] = request.session['user']['id']
                data['id'] = str(response.json()['id'])
                response = api_edit_address(data, request.session['user']['token'])
                if response.ok:
                    return HttpResponseRedirect(reverse('profile'))
                return render(request, 'address/edit_address.html', {
                    'form': form, 'errors': response.json()['errors'], 'id': address_id
                })
        else:
            form = AddressForm(initial=address)

        return render(request, 'address/edit_address.html', {'form': form, 'id': address_id})
    return HttpResponseRedirect(reverse('profile'))
Ejemplo n.º 17
0
def edit_startup(request):
    user = request.user
    group = user.groups.first()
    if str(group) == "Startup":
        startup = get_object_or_404(Startup, user_id=user.id)
        address = startup.address
        if request.method == 'POST':
            user_form = UpdateForm(
                request.POST,
                instance=user,
                initial={'fullname': user.first_name + " " + user.last_name})
            address_form = AddressForm(request.POST, instance=address)
            startup_form = StartupForm(request.POST,
                                       request.FILES,
                                       instance=startup)
            if user_form.is_valid() and address_form.is_valid(
            ) and startup_form.is_valid():
                user_form.save()
                address_form.save()
                startup_form.save()
                return HttpResponseRedirect("/profile/" + str(user.id) + "/")
        else:
            user_form = UpdateForm(
                instance=user,
                initial={'fullname': user.first_name + " " + user.last_name})
            address_form = AddressForm(instance=address)
            startup_form = StartupForm(instance=startup)

        context = {
            'user_form': user_form,
            'address_form': address_form,
            'startup_form': startup_form,
        }
        return render(request, 'edit_startup.html', context)
    else:
        return HttpResponseRedirect("/index/")