Ejemplo n.º 1
0
def main():
    db_session.global_init('db/schedule.db')
    session = db_session.create_session()

    user = User()
    user.id = 654984156316546
    session.add(user)
    session.commit()

    event = Event(periodcity=0,
                  user_id=654984156316546,
                  text='сходить в магазин')
    session.add(event)
    session.commit()

    event = Event(id=15,
                  periodcity=1,
                  user_id=654984156316546,
                  text='запустить робот пылесос')
    session.add(event)
    session.commit()

    event_description = EventDescription(event_id=15, text='2')
    session.add(event_description)
    session.commit()
Ejemplo n.º 2
0
def add_available_date(event: Event, start_date: datetime.datetime,
                       tiime: int) -> Event:
    booking = Booking()
    booking.check_in_time = start_date
    booking.check_out_time = start_date + datetime.timedelta(minutes=tiime)

    event = Event.objects(id=event.id).first()
    event.bookings.append(booking)
    event.save()

    return event
Ejemplo n.º 3
0
def add_event(update, context):
    '''Ввод описания мероприятия, созадние записи в БД'''
    if update.message.text.lower() != 'нет':
        context.user_data['new_event']['about'] = update.message.text
    else:
        context.user_data['new_event']['about'] = ''
    reply_keyboard = [['Да', 'Нет'], ['Мероприятия', '/stop_post']]
    markup = ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True)
    try:
        event = Event()
        event.name = context.user_data['new_event']['name']
        print(event.name)
        event.date = context.user_data['new_event']['date']
        print(event.date)
        event.organization = context.user_data['new_event']['org']
        print(event.organization)
        event.about = context.user_data['new_event']['about']

        db_sess.add(event)
        db_sess.commit()
        message_to_all(
            context, f'''Анонс мероприятия:\n
                        {event.organization}\n
                        {event.name}\n
                        {event.date}\n
                        {event.about}''')
        update.message.reply_text(
            "Добавлено! Хотите добавить еще мероприятие?", reply_markup=markup)
    except:
        markup = user_keyboard(context)
        update.message.reply_text("Не удалось добавить мероприятие",
                                  reply_markup=markup)
    return 5
Ejemplo n.º 4
0
def get_bookings_for_user(email: str) -> List[Booking]:
    account = find_account_by_email(email)

    booked_events = Event.objects() \
        .filter(bookings__tmember_owner_id=account.id) \
        .only('bookings', 'name')

    def map_event_to_booking(event, booking):
        booking.event = event
        return booking

    bookings = [
        map_event_to_booking(event, booking) for event in booked_events
        for booking in event.bookings if booking.tmember_owner_id == account.id
    ]

    return bookings
Ejemplo n.º 5
0
def get_available_events(checkin: datetime.datetime,
                         checkout: datetime.datetime,
                         sport: Sport) -> List[Event]:
    min_size = sport.duration_minutes
    location = sport.location

    query = Event.objects() \
        .filter(duration_minutes__lte=min_size) \
        .filter(bookings__check_in_time__lte=checkin) \
        .filter(bookings__check_out_time__gte=checkout)

    #if sport.allow_non_friends:
    #   query = query.filter(allow_non_friends=True)

    events = query.order_by('rating_price', '-duration_minutes')

    final_events = []
    for c in events:
        for b in c.bookings:
            if b.check_in_time <= checkin and b.check_out_time >= checkout and b.tmember_sport_id is None:
                final_events.append(c)

    return final_events
Ejemplo n.º 6
0
def find_events_for_user(account: Owner) -> List[Event]:
    query = Event.objects(id__in=account.event_ids)
    events = list(query)

    return events
Ejemplo n.º 7
0
def register_event(active_account: Owner, name, allow_non_friends,
                   in_public_place, in_outdoors, duration_minutes,
                   rating_price, location) -> Event:
    event = Event()

    event.name = name
    event.location = location
    event.duration_minutes = duration_minutes
    event.in_public_place = in_public_place
    event.in_outdoors = in_outdoors
    event.allow_non_friends = allow_non_friends
    event.rating_price = rating_price

    event.save()

    account = find_account_by_email(active_account.email)
    account.event_ids.append(event.id)
    account.save()

    return event