def find_a_porchfest(): default = Porchfest.objects(location=Location.objects( zip_code='14850').first()).first() form = FindAPorchfestForm(porchfest=default.id) form.porchfest.choices = [("", "---")] + [ (p.id, p.location.city + ", " + p.location.state + " " + p.start_time.strftime("%m-%d-%Y %H:%M") + " to " + p.end_time.strftime("%m-%d-%Y %H:%M")) for p in Porchfest.objects() ] return render_template('find_a_porchfest.html', form=form)
def addPorch(): form = PorchForm() porchfests = Porchfest.objects() form.porchfest_id.choices = [(p.id, p.location.city+", "+p.location.state+" "+p.start_time.strftime("%m-%d-%Y %H:%M")+" to "+p.end_time.strftime("%m-%d-%Y %H:%M")) for p in porchfests] form.time_slots.choices = [(t, t) for t in get_all_hours()] if form.validate_on_submit(): flash('Porch added!') porchfest = Porchfest.objects(id=form.porchfest_id.data).first() location = Location.objects(city=form.city.data, state=form.state.data).first() if location is None: location = Location(city=form.city.data, state=form.state.data, zip_code=form.zip.data) location.save(cascade=True) time_slots = [] porchfest_time = porchfest.start_time for time in form.time_slots.data: hour = None hour_int = int(time.split()[0]) if 'AM' in time: if hour_int is 12: hour = 0 else: hour = hour_int else: if hour_int is 12: hour = hour_int else: hour = hour_int + 12 time_slots.append(datetime(year=int(porchfest_time.year), month=int(porchfest_time.month), day=int(porchfest_time.day), hour=hour)) local_app = app address = form.address.data.split(' ') reqStr = "https://maps.googleapis.com/maps/api/geocode/json?address=" for i in address: reqStr = reqStr + i + "+" reqStr = reqStr[:-1] reqStr = reqStr + location.city + ",+" + location.state + "&key=" + app.config['GOOGLEMAPS_KEY'] res = requests.get(reqStr) resJSON = res.json() data = resJSON['results'][0] lat = data['geometry']['location']['lat'] long = data['geometry']['location']['lng'] newPorch = Porch(name=form.name.data, email=form.email.data, address=form.address.data, location=location, time_slots=time_slots, lat=str(lat), long=str(long)) newPorch.save(cascade=True) porchfest.porches.append(newPorch) porchfest.save(cascade=True) return redirect(url_for('index')) return render_template('addPorch.html', form=form)
def validate_zip(self, zip): porchfest = Porchfest.objects(id=self.porchfest_id.data).first() if porchfest.location.zip_code != zip.data: raise ValidationError( 'Does not match the zip code of the selected Porchfest!') for c in zip.data: if c.isalpha(): raise ValidationError('Zip code must consist of only integers')
def validate_state(self, state): if self.porch.data: if state.data == "": raise ValidationError( 'If you have a porch you must enter the state!') fest_location = Porchfest.objects( id=self.porchfest.data).first().location if fest_location.state != state.data: raise ValidationError( 'Does not match the state of the selected Porchfest!') else: if state.data != "": raise ValidationError( 'Leave state blank if you do not have a porch yet!')
def validate_city(self, city): if self.porch.data: if city.data == "": raise ValidationError( 'If you have a porch you must enter the city!') fest_location = Porchfest.objects( id=self.porchfest.data).first().location if fest_location.city != city.data: raise ValidationError( 'Does not match the city of the selected Porchfest!') else: if city.data != "": raise ValidationError( 'Leave city blank if you do not have a porch yet!')
def findaporchfest(): default = Porchfest.objects(location=Location.objects(zip_code='14850').first()).first() form = FindAPorchfestForm(porchfest=default.id) form.porchfest.choices = [("", "---")] + [(p.id, p.location.city + ", " + p.location.state + " " + p.start_time.strftime( "%m-%d-%Y %H:%M") + " to " + p.end_time.strftime("%m-%d-%Y %H:%M")) for p in Porchfest.objects()] markers = [] # get from shows not porches for s in default.shows: markers.append((float(s.porch.lat), float(s.porch.long), "<a href='{}'> {} </a><br><p>{}</p><br><p>{}</p>".format(url_for('artist', artist_name=s.artist.name), s.artist.name, s.porch.address, s.start_time.strftime("%m-%d-%Y %H:%M")))) # need a default lat and long for each fest to not crash if there are no porches myMap = Map( identifier="fest_map", lat=float(default.lat), lng=float(default.long), markers=markers, fit_markers_to_bounds=True, style='height:300px;width:100%;margin:0;', maptype_control=False, streetview_control=False, icon='http://maps.google.com/mapfiles/ms/icons/red-dot.png' ) return render_template('findaporchfest.html', form=form, mymap=myMap)
def validate_zip(self, zip): if self.porch.data: if zip.data == "": raise ValidationError( 'If you have a porch you must enter the zip code!') fest_location = Porchfest.objects( id=self.porchfest.data).first().location if fest_location.zip_code != zip.data: raise ValidationError( 'Does not match the zip code of the selected Porchfest!') for c in zip.data: if c.isalpha(): raise ValidationError( 'Zip code must consist of only integers') else: if zip.data != "": raise ValidationError( 'Leave zip code blank if you do not have a porch yet!')
def add_objects(): times = [ datetime(2019, 6, 26, 9, 0, 0), # start for porchfests datetime(2019, 6, 26, 17, 0, 0), # end for porchfests datetime(2019, 6, 26, 12, 0, 0), # first show end time datetime(2019, 6, 26, 15, 0, 0) # second show end time ] default_users = [ User(username='******', email='*****@*****.**', name='Ithaca One', member_of=[], follows=[]), User(username='******', email='*****@*****.**', name='Ithaca Two', member_of=[], follows=[]), User(username='******', email='*****@*****.**', name='Ithaca Three', member_of=[], follows=[]), User(username='******', email='*****@*****.**', name='Albany One', member_of=[], follows=[]) ] for user in default_users: user.set_password('default') user.save(cascade=True) default_locations = [ Location(city='Ithaca', state='NY', zip_code='14850'), Location(city='Albany', state='NY', zip_code='12203'), ] for location in default_locations: location.save(cascade=True) default_porches = [ Porch(name='Ithaca Porch 1', email='*****@*****.**', address='953 Danby Rd', location=Location.objects(city='Ithaca', state='NY').first(), time_slots=[times[2], times[3]]), Porch(name='Ithaca Porch 2', email='*****@*****.**', address='123 Ithaca Rd', location=Location.objects(city='Ithaca', state='NY').first(), time_slots=[times[0], times[1], times[3]]), Porch(name='Albany Porch 1', email='*****@*****.**', address='1200 Western Ave', location=Location.objects(city='Albany', state='NY').first(), time_slots=[times[0], times[1], times[2], times[3]]) ] for porch in default_porches: porch.save(cascade=True) default_artists = [ Artist(name='Artist 1', description='artist 1 desc', location=Location.objects(city='Ithaca', state='NY').first()), Artist(name='Artist 2', description='artist 2 desc', location=Location.objects(city='Ithaca', state='NY').first()), Artist(name='Artist 3', description='artist 3 desc', location=Location.objects(city='Albany', state='NY').first()) ] for artist in default_artists: artist.save(cascade=True) default_shows = [ Show(artist=Artist.objects(name='Artist 1').first(), porch=Porch.objects(name='Ithaca Porch 1').first(), start_time=times[0], end_time=times[2]), Show(artist=Artist.objects(name='Artist 2').first(), porch=Porch.objects(name='Ithaca Porch 2').first(), start_time=times[2], end_time=times[3]), Show(artist=Artist.objects(name='Artist 3').first(), porch=Porch.objects(name='Albany Porch 1').first(), start_time=times[0], end_time=times[2]) ] for show in default_shows: show.save(cascade=True) default_porchfests = [ Porchfest(location=Location.objects(city='Ithaca', state='NY').first(), start_time=times[0], end_time=times[1], porches=[ Porch.objects(name='Ithaca Porch 1').first(), Porch.objects(name='Ithaca Porch 2').first() ], shows=[ Show.objects(artist=Artist.objects( name='Artist 1').first()).first(), Show.objects(porch=Porch.objects( name='Ithaca Porch 2').first()).first() ]), Porchfest(location=Location.objects(city='Albany', state='NY').first(), start_time=times[0], end_time=times[1], porches=[Porch.objects(name='Albany Porch 1').first()], shows=[ Show.objects(artist=Artist.objects( name='Artist 3').first()).first() ]) ] for porchfest in default_porchfests: porchfest.save(cascade=True)
def artistFestSignUp(): form = ArtistPorchfestSignUpForm() porchfests = Porchfest.objects() form.porchfest.choices = [(str(p.id), p.location.city + ", " + p.location.state+" "+p.start_time.strftime("%m-%d-%Y %H:%M")+" to "+p.end_time.strftime("%m-%d-%Y %H:%M")) for p in porchfests] form.porch_selector.choices = [('None', '')] + [(str(p.id), p.address + " " + p.location.city + ", " + p.location.state) for p in Porch.objects()] form.time_slot.choices = [(t, t) for t in get_all_hours()] if form.validate_on_submit(): porchfest = Porchfest.objects(id=form.porchfest.data).first() porchfest_location = porchfest.location porchfest_time = porchfest.start_time form_time = form.time_slot.data hour_int = int(form_time.split()[0]) if 'AM' in form_time: if hour_int is 12: hour = 0 else: hour = hour_int else: if hour_int is 12: hour = hour_int else: hour = hour_int + 12 start_time = datetime(year=int(porchfest_time.year), month=int(porchfest_time.month), day=int(porchfest_time.day), hour=hour) end_time = start_time + timedelta(hours=1) artist = Artist.objects(name=current_user.name).first() if form.porch.data: location = Location.objects(city=form.city.data, state=form.state.data).first() if location is None: location = Location(city=form.city.data, state=form.state.data, zip_code=form.zip.data) location.save(cascade=True) porch = Porch.objects(address=form.address.data).first() if porch is None: time_slots = [] address = form.address.data.split(' ') reqStr = "https://maps.googleapis.com/maps/api/geocode/json?address=" for i in address: reqStr = reqStr + i + "+" reqStr = reqStr[:-1] reqStr = reqStr + location.city + ",+" + location.state + "&key=" + app.config['GOOGLEMAPS_KEY'] res = requests.get(reqStr) resJSON = res.json() data = resJSON['results'][0] lat = data['geometry']['location']['lat'] long = data['geometry']['location']['lng'] porch = Porch(name=form.porch_owner.data, email=form.porch_email.data, address=form.address.data, location=location, time_slots=time_slots, lat=str(lat), long=str(long)) porch.save(cascade=True) else: porch = Porch.objects(id=form.porch_selector.data).first() porch.time_slots.remove(start_time) porch.save(cascade=True) existing_show_for_artist = Show.objects(artist=artist, start_time=start_time).first() existing_show_for_porch = Show.objects(porch=porch, start_time=start_time).first() if existing_show_for_artist is not None or existing_show_for_porch is not None: flash('Show already exists!') else: show = Show(artist=artist, porch=porch, start_time=start_time, end_time=end_time) show.save(cascade=True) porchfest.shows.append(show) porchfest.save(cascade=True) flash('Signed up for ' + porchfest_location.city + ", " + porchfest_location.state + " porchfest!") return redirect(url_for('artist', artist_name=artist.name)) return render_template('artistToPorch.html', form=form)
def reset_db(): db.connection.drop_database('porchfestBAG') for location in Location.objects: location.delete() for artist in Artist.objects: artist.delete() for porch in Porch.objects: porch.delete() for fest in Porchfest.objects: fest.delete() for show in Show.objects: show.delete() times = [ datetime(2018, 12, 26, 9, 0, 0), # start for porchfests datetime(2018, 12, 26, 17, 0, 0), # end for porchfests datetime(2018, 12, 26, 12, 0, 0), # first show end time datetime(2018, 12, 26, 15, 0, 0) # second show end time ] default_locations = [ Location(city='Ithaca', state='NY', zip_code='14850'), Location(city='Binghamton', state='NY', zip_code='13901'), Location(city='Albany', state='NY', zip_code='12203'), Location(city='Winchester', state='MA', zip_code='01890') ] for location in default_locations: location.save(cascade=True) default_porches = [ Porch(name='Ithaca Porch 1', email='*****@*****.**', address='953 Danby Rd', location=Location.objects(city='Ithaca', state='NY').first(), time_slots=[times[2], times[3]], lat='42.4199351', long='-76.4969643'), Porch(name='Ithaca Porch 2', email='*****@*****.**', address='123 Ithaca Rd', location=Location.objects(city='Ithaca', state='NY').first(), time_slots=[times[0], times[1], times[3]], lat='42.438657', long='-76.4800496'), Porch(name='Albany Porch 1', email='*****@*****.**', address='501 Hudson Ave', location=Location.objects(city='Albany', state='NY').first(), time_slots=[times[0], times[1], times[3]], lat='42.662079', long='-73.780703'), ] for porch in default_porches: porch.save(cascade=True) default_artists = [ Artist(email='*****@*****.**', name='Artist 1', description='artist 1 desc', media_links=['https://www.spotify.com/artist1'], location=Location.objects(city='Ithaca', state='NY').first(), image='https://miquon.org/wp-content/uploads/2016/02/GenericUser.png'), Artist(email='*****@*****.**', name='Artist 2', description='artist 2 desc', media_links=['https://myspotify.com'], location=Location.objects(city='Albany', state='NY').first()) ] for artist in default_artists: artist.set_password('default') artist.save(cascade=True) default_shows = [ Show(artist=Artist.objects(name='Artist 1').first(), porch=Porch.objects(name='Ithaca Porch 1').first(), start_time=times[0], end_time=times[2]), Show(artist=Artist.objects(name='Artist 1').first(), porch=Porch.objects(name='Ithaca Porch 2').first(), start_time=times[2], end_time=times[3]), Show(artist=Artist.objects(name='Artist 2').first(), porch=Porch.objects(name='Albany Porch 1').first(), start_time=times[2], end_time=times[3]) ] for show in default_shows: show.save(cascade=True) default_porchfests = [ Porchfest(location=Location.objects(city='Ithaca', state='NY').first(), start_time=times[0], end_time=times[1], porches=[Porch.objects(name='Ithaca Porch 1').first(), Porch.objects(name='Ithaca Porch 2').first()], shows=[Show.objects(artist=Artist.objects(name='Artist 1').first()).first(), Show.objects(porch=Porch.objects(name='Ithaca Porch 2').first()).first()], lat='42.4440', long='-76.5019'), Porchfest(location=Location.objects(city='Binghamton', state='NY').first(), start_time=times[0], end_time=times[1], lat='42.0987', long='-75.9180'), Porchfest(location=Location.objects(city='Albany', state='NY').first(), start_time=times[0], end_time=times[1], lat='42.6526', long='-73.7562', shows=[Show.objects(porch=Porch.objects(name='Albany Porch 1').first()).first()]) ] for porchfest in default_porchfests: porchfest.save(cascade=True) flash("Database has been reset!") return redirect(url_for('index'))
def validate_porchfest_id(self, porchfest_id): porchfest = Porchfest.objects(id=porchfest_id.data).first() if porchfest is None: raise ValidationError('The selected porchfest does not exist!')