Пример #1
0
def city_event_list(request):
    if request.method == 'GET':
        with sqlite3.connect(Connection.db_path) as conn:
            city = request.GET['search']
            conn.row_factory = model_factory(Event)
            db_cursor = conn.cursor()

            db_cursor.execute(
                """
            select
            e.id,
            e.name,
            e.address,
            e.description,
            e.date,
            e.time,
            e.img_url,
            e.latitude,
            e.longitude,
            e.created_by_id
            from pregameApp_event e
            where e.address like ?
            """, (f'%{city}%', ))

            all_events = db_cursor.fetchall()

        template = 'events/events_list.html'
        context = {'events': all_events}

        return render(request, template, context)
Пример #2
0
def event_list(request):
    if request.method == 'GET':
        with sqlite3.connect(Connection.db_path) as conn:
            conn.row_factory = model_factory(Event)
            db_cursor = conn.cursor()

            db_cursor.execute("""
            select
            e.id,
            e.name,
            e.address,
            e.description,
            e.date,
            e.time,
            e.img_url,
            e.latitude,
            e.longitude,
            e.created_by_id
            from pregameApp_event e
            """)

            all_events = db_cursor.fetchall()

        template = 'events/events_list.html'
        context = {'events': all_events}

        return render(request, template, context)
# When posting a new event, the address in your data form is used to query googlemaps api
# to get the coordinates that are put into the object upon creation.
    elif request.method == 'POST':

        form_data = request.POST
        with sqlite3.connect(Connection.db_path) as conn:
            gmaps = googlemaps.Client(key=Mapkey)
            geocode_result = gmaps.geocode(form_data['address'])[0]
            event_lat = geocode_result['geometry']['location']['lat']
            event_long = geocode_result['geometry']['location']['lng']
            current_user = request.user

            db_cursor = conn.cursor()

            db_cursor.execute(
                """
            INSERT INTO pregameApp_event
            (
                name, address, description,
                date, time, img_url, latitude, longitude, created_by_id
            )
            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
            """, (form_data['name'], form_data['address'],
                  form_data['description'], form_data['date'],
                  form_data['time'], form_data['img_url'], event_lat,
                  event_long, current_user.id))

        return redirect(reverse('pregameApp:events'))
Пример #3
0
def get_user_rsvps(pregame_id, user_id):
    with sqlite3.connect(Connection.db_path) as conn:
        conn.row_factory = model_factory(UserPregame)
        db_cursor = conn.cursor()
        db_cursor.execute("""
        select
            rsvp.id,
            rsvp.pregame_id,
            rsvp.user_id
            
        from pregameApp_userpregame rsvp
        where rsvp.pregame_id = ? and rsvp.user_id = ?
        """, (pregame_id, user_id,))

        return db_cursor.fetchall()
Пример #4
0
def get_pregame_notes(pregame_id):
    with sqlite3.connect(Connection.db_path) as conn:
        conn.row_factory = model_factory(PregameNote)
        db_cursor = conn.cursor()
        db_cursor.execute("""
        select
            n.id,
            n.note,
            n.pregame_id,
            n.user_id,
            u.username
        from pregameApp_pregamenote n
        join auth_user u on n.user_id = u.id
        where n.pregame_id = ?
        """, (pregame_id,))
        return db_cursor.fetchall()
Пример #5
0
def get_events():
    with sqlite3.connect(Connection.db_path) as conn:
        conn.row_factory = model_factory(Event)
        db_cursor = conn.cursor()
        db_cursor.execute("""
        select
            e.id,
            e.name,
            e.address,
            e.description,
            e.date,
            e.time,
            e.img_url,
            e.latitude,
            e.longitude,
            e.created_by_id
        from pregameApp_event e
        """)
        return db_cursor.fetchall()
Пример #6
0
def get_pregames():
    with sqlite3.connect(Connection.db_path) as conn:
        conn.row_factory = model_factory(Pregame)
        db_cursor = conn.cursor()
        db_cursor.execute("""
        select
            p.id,
            p.name,
            p.address,
            p.description,
            p.date,
            p.time,
            p.img_url,
            p.latitude,
            p.longitude,
            p.created_by_id,
            p.event_id
        from pregameApp_pregame p
        """)
        return db_cursor.fetchall()
Пример #7
0
def pregame_list(request, event_id):
    if request.method == 'GET':
        with sqlite3.connect(Connection.db_path) as conn:
            conn.row_factory = model_factory(Pregame)
            db_cursor = conn.cursor()

            db_cursor.execute(
                """
            select
            p.id,
            p.name,
            p.address,
            p.description,
            p.date,
            p.time,
            p.img_url,
            p.latitude,
            p.longitude,
            p.created_by_id,
            p.event_id,
            e.name event_name,
            e.latitude event_lat,
            e.longitude event_long
            from pregameApp_pregame p
            join pregameApp_event e on p.event_id = e.id
            WHERE p.event_id = ?
            """, (event_id, ))

            all_event_pregames = db_cursor.fetchall()

        template = 'pregame/pregame_list.html'
        context = {
            'pregames': all_event_pregames,
            'event_id': event_id,
            'Mapkey': Mapkey
        }

        return render(request, template, context)
# When posting a new pregame, the address in your data form is used to query googlemaps api
# to get the coordinates that are put into the object upon creation.
    elif request.method == 'POST':

        form_data = request.POST
        with sqlite3.connect(Connection.db_path) as conn:
            gmaps = googlemaps.Client(key=Mapkey)
            geocode_result = gmaps.geocode(form_data['address'])[0]
            event_lat = geocode_result['geometry']['location']['lat']
            event_long = geocode_result['geometry']['location']['lng']
            current_user = request.user
            current_event = event_id

            db_cursor = conn.cursor()

            db_cursor.execute(
                """
            INSERT INTO pregameApp_pregame
            (
                name, address, description,
                date, time, img_url, latitude, longitude, created_by_id, event_id
            )
            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
            """, (form_data['name'], form_data['address'],
                  form_data['description'], form_data['date'],
                  form_data['time'], form_data['img_url'], event_lat,
                  event_long, current_user.id, current_event))

        return redirect(reverse('pregameApp:pregame', args=(event_id, )))