def widget(): c = request.args.get('c') or abort(404) matched = re_container.match(c) or abort(404) event_id = matched.groupdict()['id'] response = Response(content_type="text/javascript") response.data = render_template('events/widget.js', container=c, event=Event.get(event_id)) return response
def attend(id): callback = request.args.get('callback', 'callback') http_response = Response(content_type='text/javascript') response = {'response': 'ok', 'txt': 'You were saved as an event attendee'} event = Event.get(id) if g.user.is_anonymous(): try: data = participant.check(request.args.to_dict()) data.update({'password': '******', 'roles': ['user']}) u = User.create(**data) event.participants.append(u) db.session.commit() except t.DataError as e: response = {'response': 'err', 'txt': e.as_dict()} else: event.participants.append(g.user) db.session.commit() http_response.data = "{}({})".format(callback, json_dumps(response)) return http_response
def create_event(self, story, author): event = Event(**event_data) story.events.append(event) for user in self.create_visitors(): event.participants.append(user) return event.save()