def test_get_event(events): model.add_event(events, "12345", "Orel Birthday at ashkelon 7/2/2020", "Omer Daniel") res1 = model.get_event(events, "12345") assert type(res1) == dict res2 = model.get_event(events, "6789") assert res2 is None
def coming_or_not(update: Update, context: CallbackContext): chat_id = update.effective_chat.id name = update.effective_user.first_name coll = model.get_collection(DBNAME, 'events') list_of_stuff = model.get_event( events_collection, event_id['id'])['items'] # get list of things left to brings guest_info[ 'num_of_participants'] = update.callback_query.data # how many people will arrive keyboard = [[ InlineKeyboardButton("i don't want to bring anything, thanks", callback_data='no') ]] model.rsvp(coll, event_id['id'], chat_id, name, guest_info['num_of_participants']) # update the list of people goodbye_message = 'sorry to here your not coming {}, hope i see you soon'.format( name) coming_message = "see you soon {}, you will arrive as:{} people\n what would like to bring?".format( name, guest_info['num_of_participants']) if guest_info['num_of_participants'] == '0': context.bot.send_message(chat_id=chat_id, text=goodbye_message) else: for item in list_of_stuff: keyboard.append([InlineKeyboardButton(item, callback_data=item)]) context.bot.send_message(chat_id=chat_id, reply_markup=InlineKeyboardMarkup(keyboard), text=coming_message) print(list_of_stuff) return WHAT_TO_BRING
def attendee_event(): event_id = request.args.get('eid', None) if not event_id: event_id = request.form.get('eid', None) attendee_id = request.args.get('aid', None) if not attendee_id: attendee_id = request.form.get('aid', None) if not event_id or not attendee_id: return json.dumps({'success': False, 'error': { 'type': 'exception', 'message': 'Event Id or Attendee Id not specified'} }) if request.method == 'PUT': with app.event_update_lock: db_evt = model.get_event(get_db(), event_id) if 'limit' in db_evt: evt = model.get_event_free_places(get_db(), event_id) if evt['free_places'] <= 0: return json.dumps({'success': False, 'error': { 'type': 'outofplaces' }}) model.book_attendee_event(get_db(), attendee_id, event_id) elif request.method == 'DELETE': with app.event_update_lock: model.unbook_attendee_event(get_db(), attendee_id, event_id) return json.dumps({'success': True})
def test_rsvp(events): model.add_event(events, "12345", "Orel Birthday at ashkelon 7/2/2020", "Omer Daniel") model.rsvp(events, "12345", "1111", "Omer Daniel", 2) res = model.get_event(events, "12345") print(res['participants']) assert len(res['participants']) == 1
def test_friend_brings_item(events): model.add_event(events, "12345", "Orel Birthday at ashkelon 7/2/2020", "Omer Daniel") model.rsvp(events, "12345", "1111", "Omer Daniel", 2) model.add_items_to_event(events, "12345", "bamba") model.friend_brings_item(events, "12345", "1111", "bamba") res = model.get_event(events, "12345") assert res['participants'][0]['brings'][0] == "bamba"
def start(update: Update, context: CallbackContext): print(context.args) event_id['id'] = context.args[0] info_about_event = model.get_event(events_collection, event_id['id']) keyboard = [[InlineKeyboardButton("not this time", callback_data='0')], [InlineKeyboardButton("1", callback_data='1')], [InlineKeyboardButton("2", callback_data='2')], [InlineKeyboardButton("3", callback_data='3')], [InlineKeyboardButton("4", callback_data='4')], [InlineKeyboardButton("5", callback_data='5')]] reply_markup = InlineKeyboardMarkup(keyboard) user_name = update.message.from_user.first_name chat_id = update.effective_chat.id logger.info(f"> Start chat #{chat_id}") welcome_message = 'Hi, {} {} wants to know if you attend:{}'.format( user_name, info_about_event['name'], info_about_event['description']) update.message.reply_text(welcome_message, reply_markup=reply_markup) return COMING_OR_NOT
def what_to_bring(update: Update, context: CallbackContext): print(guest_info['brings']) user_id = update.effective_chat.id coll = model.get_collection(DBNAME, 'events') query = update.callback_query # what he brings model.friend_brings_item(coll, event_id['id'], user_id, query.data) guest_info['brings'].append(query.data) list_of_stuff = model.get_event(events_collection, event_id['id'])['items'] print(list_of_stuff) if guest_info['brings'] != 'no': keyboard = [[ InlineKeyboardButton("no thanks, it enough", callback_data=' ') ]] for item in list_of_stuff: keyboard.append([InlineKeyboardButton(item, callback_data=item)]) next_message = 'you choose to brings {}, do you want to bring another things?'.format( query.data) context.bot.send_message(chat_id=user_id, reply_markup=InlineKeyboardMarkup(keyboard), text=next_message) return SUMMERY print(list_of_stuff)
def PUT(self, userid, eventid): """Update a event""" data = web.data() data = demjson.decode(data) model.update_event(userid, eventid, data['starttime'], data['endtime'], data['place'], data['title'], data['description']) return demjson.encode(model.get_event(userid, eventid))
def GET(self, userid, eventid): """Get event""" event = model.get_event(userid, eventid) return demjson.encode(event)
def test_add_items_to_event(events): model.add_items_to_event(events, "12345", "bamba") model.add_items_to_event(events, "12345", "bisli") model.add_items_to_event(events, "12345", "cola") res = model.get_event(events, "12345") assert len(res['items']) == 3
def test_create_event(events): model.add_event(events, "12345", "Orel Birthday at ashkelon 7/2/2020", "Omer Daniel") event = model.get_event(events, "12345") assert event['description'] == "Orel Birthday at ashkelon 7/2/2020"
def GET(self,itemid): form = self.form() event = model.get_event(itemid) form.get('itemid').value = itemid return render.event(event,form)