def event_signup(event_id): if EventRegister.check_if_registered(session['email'], event_id) is None: try: EventRegister.register_for_event(session['email'], event_id) return make_response(event_get(event_id)) except NoSuchEventExistException: abort(404) else: EventRegister.unregister_for_event(session['email'], event_id) return make_response(event_get(event_id))
def test_user_attended(self): user = "******" event = Event( title="Test event", description="Test description", start=datetime.datetime.utcnow().strftime('%m/%d/%Y %I:%M %p'), end=(datetime.datetime.utcnow() + datetime.timedelta(hours=1)).strftime('%m/%d/%Y %I:%M %p'), event_type="action", points=10) event.save_to_db() EventRegister.register_for_event(user, event.get_id()) EventRegister.set_user_attended(user, event.get_id().hex) self.assertEquals( EventRegister.get_user_attended(user, event.get_id().hex), True) EventRegister.set_user_attended(user, event.get_id().hex) self.assertEquals( EventRegister.get_user_attended(user, event.get_id().hex), False) Database.remove(Event.COLLECTION, {'_id': event.get_id()})
def update_attended(user, event_id): id_ = uuid.UUID(event_id) event = Event.get_by_id(id_) category = event.get_event_type() points = event.get_points() if EventRegister.get_user_attended(user, event_id): EventRegister.set_user_attended(user, event_id) User.update_user_points(user, category, -points) else: User.update_user_points(user, category, points) EventRegister.set_user_attended(user, event_id) return jsonify({"message": "ok"}), 200
def view_event_registrations(event_id): if session.contains('email') and session['email'] is not None: if User.get_user_permissions(session['email']) == 'admin': users = EventRegister.list_registered_users(event_id) return render_template('admin-event-registrations.html', users=users, event_id=event_id) else: abort(401)
def test_event_register(self): user = "******" event = Event(title="Test event", description="Test description", start=datetime.datetime.utcnow().strftime('%m/%d/%Y %I:%M %p'), end=(datetime.datetime.utcnow() + datetime.timedelta(hours=1)).strftime('%m/%d/%Y %I:%M %p'), event_type="action", points=10) event.save_to_db() EventRegister.register_for_event(user, event.get_id()) self.assertIsNotNone(EventRegister.check_if_registered(user, event.get_id())) Database.remove("registrations", {"user": user, "event": event.get_id()}) Database.remove(Event.COLLECTION, {'_id': event.get_id()})
def test_event_unregister(self): user = "******" event = Event( title="Test event", description="Test description", start=datetime.datetime.utcnow().strftime('%m/%d/%Y %I:%M %p'), end=(datetime.datetime.utcnow() + datetime.timedelta(hours=1)).strftime('%m/%d/%Y %I:%M %p'), event_type="action", points=10) event.save_to_db() EventRegister.register_for_event(user, event.get_id()) EventRegister.unregister_for_event(user, event.get_id()) self.assertIsNone( EventRegister.check_if_registered(user, event.get_id())) Database.remove(Event.COLLECTION, {'_id': event.get_id()})
def event_get(event_id): try: old_event = Event.get_by_id(event_id) registered = None if session.contains('email') and session['email'] is not None: registered = EventRegister.check_if_registered(session['email'], event_id) date = datetime.now() ff = old_event._end < date return render_template('items/event.html', event=old_event.to_json(), registered=registered, date=date) except NoSuchEventExistException: abort(404)
def event_get(event_id): try: old_event = Event.get_by_id(event_id) registered = None if session.contains('email') and session['email'] is not None: registered = EventRegister.check_if_registered( session['email'], event_id) date = datetime.now() ff = old_event._end < date return render_template('items/event.html', event=old_event.to_json(), registered=registered, date=date) except NoSuchEventExistException: abort(404)
def test_user_attended(self): user = "******" event = Event(title="Test event", description="Test description", start=datetime.datetime.utcnow().strftime('%m/%d/%Y %I:%M %p'), end=(datetime.datetime.utcnow() + datetime.timedelta(hours=1)).strftime('%m/%d/%Y %I:%M %p'), event_type="action", points=10) event.save_to_db() EventRegister.register_for_event(user, event.get_id()) EventRegister.set_user_attended(user, event.get_id().hex) self.assertEquals(EventRegister.get_user_attended(user, event.get_id().hex), True) EventRegister.set_user_attended(user, event.get_id().hex) self.assertEquals(EventRegister.get_user_attended(user, event.get_id().hex), False) Database.remove(Event.COLLECTION, {'_id': event.get_id()})