def index(): if request.method == 'POST': id = request.form['id'] name = request.form['name'] created = request.form['created'] status = request.form['status'] photo_url = request.form['photo_url'] event_url = request.form['event_url'] description = request.form['description'] event = Event(id=id, name=name, created=created, status=status, photo_url=photo_url, event_url=event_url, description=description) db.session.add(event) db.session.commit() events = Event.query.all() response_object = { 'status': 'success', 'data': { 'events': [event.to_json() for event in events] } } return jsonify(response_object), 200
def test_add_event(self): topic = Topic(name="Python", description="", abbreviation="py") entry = Entry(type="ticket", description="description") event = Event( name="learning new technologies", description="example description", url="https://example.com", start="2018-06-06 16:15:00Z", end="2018-06-06 17:15:00Z", duration=100000, topics=[topic], entry=[entry], category="test category", source="test", location="belfast", ) db.session.add(event) db.session.commit() self.assertEqual(event.name, "learning new technologies") self.assertEqual(event.description, "example description") self.assertEqual(event.url, "https://example.com") self.assertEqual(event.start, datetime(2018, 6, 6, 16, 15, 00)) self.assertEqual(event.end, datetime(2018, 6, 6, 17, 15, 00)) self.assertEqual(event.duration, 100000) self.assertEqual(event.category, "test category") self.assertEqual(event.location, "belfast")
def add_event( name, description, url, start, end, duration, topics, entry, location, channel, category, source, ): event = Event( name=name, description=description, url=url, start=start, end=end, duration=duration, topics=topics, entry=entry, location=location, channel=channel, category=category, source=source, ) db.session.add(event) db.session.commit() return event
def add_event( id, name, created, status, photo_url, event_url, description, group_name, member_type, time, source, ): event = Event( id=id, name=name, created=created, status=status, photo_url=photo_url, event_url=event_url, description=description, group_name=group_name, member_type=member_type, time=time, source=source, ) db.session.add(event) db.session.commit() return event
def add_event(): post_data = request.get_json() if not post_data: response_object = {'status': 'fail', 'message': 'Invalid payload.'} return make_response(jsonify(response_object)), 400 type_id = post_data.get('type_id') caregiver_id = post_data.get('caregiver_id') start_time = post_data.get('start_time') try: event = Event(type_id=type_id, caregiver_id=caregiver_id, start_time=start_time) db.session.add(event) db.session.commit() response_object = { 'status': 'success', 'message': 'Event created.', 'id': event.id } return make_response(jsonify(response_object)), 201 except exc.IntegrityError: db.session().rollback() response_object = {'status': 'fail', 'message': 'Invalid payload.'} return make_response(jsonify(response_object)), 400 except Exception: # other error e.g. invalid start_time response_object = {'status': 'fail', 'message': 'Invalid payload.'} return make_response(jsonify(response_object)), 400
def index(): if request.method == "POST": name = request.form["name"] description = request.form["description"] url = request.form["url"] start = request.form["start"] end = request.form["end"] duration = request.form["duration"] topics = request.form["topics"] location = request.form["location"] entry = request.form["entry"] category = request.form["category"] source = request.form["source"] source_id = request.form["source_id"] topic_list = extract_topics(topics) event = Event( name=name, description=description, url=url, start=start, end=end, duration=duration, topics=topic_list, entry=entry, location=location, category=category, source=source, source_id=source_id, ) db.session.add(event) db.session.commit() events = Event.query.filter(Event.deleted is None).all() response_object = { "status": "success", "data": { "events": [event.to_dict() for event in events] }, } return jsonify(response_object), 200
def add_event(id, name, created, status, photo_url, event_url, description): event = Event(id=id, name=name, created=created, status=status, photo_url=photo_url, event_url=event_url, description=description) db.session.add(event) db.session.commit() return event
def add_event(): post_data = request.get_json() response_object = {"status": "fail", "message": "Invalid payload."} if not post_data: return jsonify(response_object), 400 name = post_data.get("name") description = post_data.get("description") url = post_data.get("url") start = post_data.get("start") end = post_data.get("end") duration = post_data.get("duration") topics = post_data.get("topics") location = post_data.get("location") entries = post_data.get("entry") category = post_data.get("category") source = post_data.get("source") topics_list = extract_topics(topics) entry_list = extract_enteries(entries) try: event = Event.query.filter_by(name=name, start=start).first() if not event: event = Event( name=name, description=description, url=url, start=start, end=end, duration=duration, topics=topics_list, entry=entry_list, location=location, category=category, source=source, ) db.session.add(event) db.session.commit() response_object["status"] = "success" response_object["message"] = f"{name} was added!" return jsonify(response_object), 201 else: response_object["message"] = "Sorry. That id already exists." return jsonify(response_object), 202 except (exc.IntegrityError, ValueError): db.session.rollback() return jsonify(response_object), 400 except exc.IntegrityError: db.session.rollback() return jsonify(response_object), 400
def index(): if request.method == "POST": id = request.form["id"] name = request.form["name"] created = request.form["created"] status = request.form["status"] photo_url = request.form["photo_url"] event_url = request.form["event_url"] description = request.form["description"] group_name = request.form["group_name"] member_type = request.form["member_type"] time = request.form["time"] source = request.form["source"] event = Event( id=id, name=name, created=created, status=status, photo_url=photo_url, event_url=event_url, description=description, group_name=group_name, member_type=member_type, time=time, source=source, ) db.session.add(event) db.session.commit() events = Event.query.all() response_object = { "status": "success", "data": {"events": [event.to_json() for event in events]}, } return jsonify(response_object), 200
def seed_db(): """Seeds the database.""" created = datetime.utcfromtimestamp(1525290524).replace( tzinfo=timezone.utc) db.session.add( Event(id=1, name='Meetup name', created=created, status='upcoming', photo_url='http://example.com/photo.jpg', event_url='http://example.com/id=1', description='A description of the meetup')) db.session.commit()
def add_event(): post_data = request.get_json() response_object = {"status": "fail", "message": "Invalid payload."} if not post_data: return jsonify(response_object), 400 id = post_data.get("id") name = post_data.get("name") created = post_data.get("created") status = post_data.get("status") photo_url = post_data.get("photo_url") event_url = post_data.get("event_url") description = post_data.get("description") group_name = post_data.get("group_name") member_type = post_data.get("member_type") time = (post_data.get("time"),) source = post_data.get("source") try: event = Event.query.filter_by(id=id).first() if not event: event = Event( id=id, name=name, created=created, status=status, photo_url=photo_url, event_url=event_url, description=description, group_name=group_name, member_type=member_type, time=time, source=source, ) db.session.add(event) db.session.commit() response_object["status"] = "success" response_object["message"] = f"{name} was added!" return jsonify(response_object), 201 else: response_object["message"] = "Sorry. That id already exists." return jsonify(response_object), 202 except (exc.IntegrityError, ValueError): db.session.rollback() return jsonify(response_object), 400 except exc.IntegrityError: db.session.rollback() return jsonify(response_object), 400
def add_event(): post_data = request.get_json() response_object = {'status': 'fail', 'message': 'Invalid payload.'} if not post_data: return jsonify(response_object), 400 id = post_data.get('id') name = post_data.get('name') created = post_data.get('created') status = post_data.get('status') photo_url = post_data.get('photo_url') event_url = post_data.get('event_url') description = post_data.get('description') try: event = Event.query.filter_by(id=id).first() if not event: created = int(created) / 1000 created = datetime.utcfromtimestamp(created).replace( tzinfo=timezone.utc) event = Event(id=id, name=name, created=created, status=status, photo_url=photo_url, event_url=event_url, description=description) db.session.add(event) db.session.commit() response_object['status'] = 'success' response_object['message'] = f'{name} was added!' return jsonify(response_object), 201 else: response_object['message'] = 'Sorry. That id already exists.' return jsonify(response_object), 400 except exc.IntegrityError as e: db.session.rollback() return jsonify(response_object), 400 except (exc.IntegrityError, ValueError) as e: db.session.rollback() return jsonify(response_object), 400
def test_add(self): topic = Topic(name="Python", description="", abbreviation="py") entry = Entry(type="ticket", description="description") event = Event( name="learning new technologies", description="example description", url="https://example.com", start="2018-06-06 16:15:00Z", end="2018-06-06 17:15:00Z", duration=100000, topics=[topic], entry=[entry], category="test category", source="test", location="belfast", ) channel = Channel(name="test", url="", description="", topics=[topic], source="test") meetup = Meetup( name="learning new technologies", logo="https://example.com/image", url="https://example.com/meetup", description="the new shiny", topics=[topic], events=[event], channel=[channel], source="test", ) db.session.add(event) db.session.commit() self.assertEqual(meetup.name, "learning new technologies") self.assertEqual(meetup.logo, "https://example.com/image") self.assertEqual(meetup.url, "https://example.com/meetup") self.assertEqual(meetup.description, "the new shiny") self.assertEqual(len(meetup.topics), 1) self.assertEqual(len(meetup.events), 1) self.assertEqual(len(meetup.channel), 1)
def seed_db(): """Seeds the database.""" event_date = datetime(2019, 5, 2).timestamp() created = datetime.utcfromtimestamp(event_date).replace( tzinfo=timezone.utc) time = datetime.utcfromtimestamp(event_date).replace(tzinfo=timezone.utc) db.session.add( Event( id=1, name="Meetup name", created=created, status="upcoming", photo_url="http://example.com/photo.jpg", event_url="http://example.com/id=1", description="A description of the meetup", group_name="Meetup Group", member_type="Member", time=time, source="test", )) db.session.commit()
def add_event(): post_data = request.get_json() response_object = {"status": "fail", "message": "Invalid payload."} if not post_data: return jsonify(response_object), 400 name = post_data.get("name") description = post_data.get("description") url = post_data.get("url") start = post_data.get("start") end = post_data.get("end") duration = post_data.get("duration") topics = post_data.get("topics") location = post_data.get("location") entries = post_data.get("entry") category = post_data.get("category") source = post_data.get("source") source_id = post_data.get("source_id") topics_list = extract_topics(topics) entry_list = extract_enteries(entries) if existing_match_from_name(name, start): response_object[ "message"] = "Event with name and start already exists." return jsonify(response_object), 202 if source_id and existing_match_from_source_id(source, source_id): response_object[ "message"] = "Event from with source id already exists." return jsonify(response_object), 202 try: event = Event( name=name, description=description, url=url, start=start, end=end, duration=duration, topics=topics_list, entry=entry_list, location=location, category=category, source=source, source_id=source_id, ) db.session.add(event) db.session.commit() response_object["status"] = "success" response_object["message"] = f"{name} was added!" return jsonify(response_object), 201 except (exc.IntegrityError, ValueError): db.session.rollback() return jsonify(response_object), 400 except exc.IntegrityError: db.session.rollback() return jsonify(response_object), 400