def execute(self): invite_attendee = None if self.invite_attendee_id: invite_attendee = InviteAttendee.get_by_unique_id( self.invite_attendee_id) invite = Invite.get_by_unique_id(self.invite_unique_id) if invite is None: raise InviteNotFoundException() author = None if invite_attendee is not None: author = invite_attendee.name or invite_attendee.email or invite_attendee.phone if invite.comments is None: invite.comments = [] comment = Comment() comment.author = author comment.comment = self.comment comment.commented_on = datetime.datetime.now() invite.comments.append(comment) invite.put() return comment
def execute(self): invite_attendee = None if self.invite_attendee_id: invite_attendee = InviteAttendee.get_by_unique_id( self.invite_attendee_id ) invite = Invite.get_by_unique_id(self.invite_unique_id) if invite is None: raise InviteNotFoundException() author = None if invite_attendee is not None: author = invite_attendee.name or invite_attendee.email or invite_attendee.phone if invite.comments is None: invite.comments = [] comment = Comment() comment.author = author comment.comment = self.comment comment.commented_on = datetime.datetime.now() invite.comments.append(comment) invite.put() return comment
def query(self): """ Returns a list of comments from the invite [ { 'author': '', 'comment': '', 'on': '' } ] """ invite = Invite.get_by_unique_id(self.invite_unique_id) if invite.comments is None: invite.comments = [] def date_compare(x, y): if x.commented_on > y.commented_on: return -1 return 1 return [{ 'unique_id': c.unique_id, 'author': c.author, 'comment': c.comment, 'on': convert_to_user_date(c.commented_on, invite.utc_offset).strftime("%Y-%m-%d %H:%M") } for c in sorted(invite.comments, cmp=date_compare)]
def query(self): """ Returns a list of comments from the invite [ { 'author': '', 'comment': '', 'on': '' } ] """ invite = Invite.get_by_unique_id(self.invite_unique_id) if invite.comments is None: invite.comments = [] def date_compare(x, y): if x.commented_on > y.commented_on: return -1 return 1 return [ { 'unique_id': c.unique_id, 'author': c.author, 'comment': c.comment, 'on': convert_to_user_date( c.commented_on, invite.utc_offset ).strftime("%Y-%m-%d %H:%M") } for c in sorted(invite.comments, cmp=date_compare) ]
def execute(self): invite_attendee = None invite_attendee = InviteAttendee( unique_id=guid() ) invite_attendee.name = self.name invite_attendee.email = self.email if self.status: invite_attendee.attendee_status = self.status invite_attendee.phone = self.phone if self.contact_unique_id: contact = Contact.get_by_unique_id( self.contact_unique_id ) if contact: invite_attendee.contact = contact.key if not self.invite: self.invite = Invite.get_by_unique_id(self.invite_unique_id) invite_attendee.invite = self.invite.key invite_attendee.is_organizer = self.is_organizer if self.user: UpdateUserOnAttendeesCommand.update_user_on_attendee(self.user, invite_attendee) elif invite_attendee.email: # We can only correlate by email now user = self.user_from_email(invite_attendee.email) if user: UpdateUserOnAttendeesCommand.update_user_on_attendee(user, invite_attendee) invite_attendee.put() return invite_attendee.unique_id
def execute(self): invite_attendee = None if self.invite_attendee_id: invite_attendee = InviteAttendee.get_by_unique_id( self.invite_attendee_id) else: invite_attendee = InviteAttendee(unique_id=guid()) invite_attendee.name = self.name invite_attendee.email = self.email invite_attendee.phone = self.phone contact = None if self.user and self.unique_id: contact = Contact.get_by_unique_id(self.unique_id) elif self.user: contact = Contact(unique_id=guid(), user=self.user) # Here we update the contact with the appropiate Data if contact: invite_attendee.contact = contact.key contact.name = self.name contact.email = self.email contact.phone = self.phone contact.put() invite = Invite.get_by_unique_id(self.invite_id) invite_attendee.invite = invite.key invite_attendee.put() return invite_attendee.unique_id
def query(self): """ Returns a list of Invite Attendee Notifications This is a valid data-format: [ { 'invite_attendee_id': '', 'name': u'', 'phone': 'email': '', 'status': '', 'response_on':'', 'notified': True|False } ] """ if not self.invite: self.invite = Invite.get_by_unique_id(self.invite_unique_id) if not self.invite: raise InviteNotFoundException() invite_attendee_notifications = InviteAttendeeNotification.get_by_invite( self.invite) result = [] for invite_attendee in self.invite.get_attendees(): invite_attendee_query = InviteAttendeeQuery( invite_attendee).query() invite_attendee_query['notified'] = self._is_notified( invite_attendee, invite_attendee_notifications) result.append(invite_attendee_query) return result
def view_confirmation(self, invite_id): invite = Invite.get_by_unique_id(invite_id) if not invite.organizer_email: raise Exception( "There's no need for a confirmation email for this invite") return self.render_template("invite_confirmation.html", organizer_email=invite.organizer_email)
def confirm(self, confirmation_id): #we are using the confirmation_id as the invite_id for now invite = Invite.get_by_unique_id(confirmation_id) if not invite: raise Exception("We couldn't find the invite. Check if your link is valid.") command = PostInviteToVoiceflowsCommand(invite) command.execute() return self.redirect('/invite/' + invite.unique_id + '/edit')
def execute(self): image = Image() image.image_key = self.image_key image.put() invite = Invite.get_by_unique_id(self.unique_id) invite.poster_picture = image.key invite.put() return invite.poster_picture.urlsafe()
def confirm(self, confirmation_id): #we are using the confirmation_id as the invite_id for now invite = Invite.get_by_unique_id(confirmation_id) if not invite: raise Exception( "We couldn't find the invite. Check if your link is valid.") command = PostInviteToVoiceflowsCommand(invite) command.execute() return self.redirect('/invite/' + invite.unique_id + '/edit')
def _get_invite_model(self, invite_id): """ Get the invite by id TODO: Think about the location of this function. """ invite_entity = Invite.get_by_unique_id(invite_id) if invite_entity is None: raise Exception("Invite not found with id: %s" % invite_id) return InviteModel(invite_entity)
def execute(self): invite = Invite.get_by_unique_id(self.unique_id) if invite.start < datetime.now(): raise InviteCannotBeEditedException( "This invite is in the past it cannot be edited anymore") copy_over(self, invite) invite.put() index_invite(invite) return invite.unique_id
def execute(self): invite = Invite.get_by_unique_id(self.unique_id) if invite.start < datetime.now(): raise InviteCannotBeEditedException( "This invite is in the past it cannot be edited anymore" ) copy_over(self, invite) invite.put() index_invite(invite) return invite.unique_id
def view_invite(self, invite_id, invite_attendee_id=None): if not invite_id: return self.redirect_to('home') invite = Invite.get_by_unique_id(invite_id) invite_query = query.CompleteInviteQuery(invite=invite) invite_attendee = self._try_to_get_attendee(invite, invite_attendee_id) return self.render_template( 'invite.html', invite=json.dumps(invite_query.query(), cls=DateTimeEncoder), invite_attendee=json.dumps(invite_attendee, cls=DateTimeEncoder), )
def execute(self): invite = Invite.get_by_unique_id(self.invite_unique_id) if invite.start < datetime.now(): raise InviteCannotBeEditedException( "This invite is in the past it cannot be edited anymore") bulk_ids = [] if self.commands: for command in self.commands: bulk_ids.append(command.execute()) return bulk_ids
def execute(self): invite = Invite.get_by_unique_id(self.invite_unique_id) if invite.start < datetime.now(): raise InviteCannotBeEditedException( "This invite is in the past it cannot be edited anymore" ) bulk_ids = [] if self.commands: for command in self.commands: bulk_ids.append(command.execute()) return bulk_ids
def _edit_invite(self, invite_id=None, invite_attendee_id=None): """Get the full invite, with contacts and responses""" if not invite_id: return self.redirect_to('home') invite = Invite.get_by_unique_id(invite_id) invite_query = query.CompleteInviteQuery(invite=invite) invite_attendee = self._try_to_get_attendee(invite, invite_attendee_id) return self.render_template( 'invite.html', edit='True', invite=json.dumps(invite_query.query(), cls=DateTimeEncoder), invite_attendee=json.dumps(invite_attendee, cls=DateTimeEncoder) if invite_attendee else None, )
def execute(self): if not self.invite: self.invite = Invite.get_by_unique_id(self.invite_unique_id) invite_attendees = self.invite.get_attendees() if self.invite.start < datetime.now(): raise Exception("Invite is in the past, it cannot be broadcasted") if not invite_attendees: raise Exception("The invite has no attendees") bulk = BulkNotifyAttendeesCommand( invite=self.invite, attendees_unique_ids=[x.unique_id for x in self.invite.get_attendees()] ) bulk.execute()
def query(self): """ Returns an Attendee on the Invite containing the parameter user """ if not self.invite: self.invite = Invite.get_by_unique_id(self.invite_id) invite_attendee = InviteAttendee.query(ndb.AND( InviteAttendee.user == self.user.key, InviteAttendee.invite == self.invite.key, )).get() if not invite_attendee: return None return InviteAttendeeQuery(invite_attendee).query()
def execute(self): if not self.invite: self.invite = Invite.get_by_unique_id(self.invite_unique_id) invite_attendees = self.invite.get_attendees() if self.invite.start < datetime.now(): raise Exception("Invite is in the past, it cannot be broadcasted") if not invite_attendees: raise Exception("The invite has no attendees") bulk = BulkNotifyAttendeesCommand( invite=self.invite, attendees_unique_ids=[ x.unique_id for x in self.invite.get_attendees() ]) bulk.execute()
def query(self): """ Returns an Attendee on the Invite containing the parameter user """ if not self.invite: self.invite = Invite.get_by_unique_id(self.invite_id) invite_attendee = InviteAttendee.query( ndb.AND( InviteAttendee.user == self.user.key, InviteAttendee.invite == self.invite.key, )).get() if not invite_attendee: return None return InviteAttendeeQuery(invite_attendee).query()
def execute(self): invite_attendee = None if self.invite_attendee_id: invite_attendee = InviteAttendee.get_by_unique_id(self.invite_attendee_id) else: invite_attendee = InviteAttendee( unique_id=guid() ) invite_attendee.name = self.name invite_attendee.email = self.email invite_attendee.phone = self.phone contact = None if self.user and self.unique_id: contact = Contact.get_by_unique_id( self.unique_id ) elif self.user: contact = Contact( unique_id=guid(), user=self.user ) # Here we update the contact with the appropiate Data if contact: invite_attendee.contact = contact.key contact.name = self.name contact.email = self.email contact.phone = self.phone contact.put() invite = Invite.get_by_unique_id(self.invite_id) invite_attendee.invite = invite.key invite_attendee.put() return invite_attendee.unique_id
def query(self): """ Returns the invite organizer minimally formatted This is a valid data-format: { 'unique_id': '', 'name': u'', 'phone': 'email': '', 'status':, 'is_organizer':, } """ if not self.invite: self.invite = Invite.get_by_unique_id(self.invite_unique_id) invite_attendee = InviteAttendee.query( ndb.AND( InviteAttendee.invite == self.invite.key, InviteAttendee.is_organizer == True ) ).get() if not invite_attendee: return None attendee = { 'unique_id': invite_attendee.unique_id, 'invite_attendee_id': invite_attendee.unique_id, 'name': invite_attendee.name, 'phone': invite_attendee.phone, 'email': invite_attendee.email, 'user_id': invite_attendee.user.id() if invite_attendee.user else None, 'status': AttendeeStatus.ORGANIZER, 'notifications': [], 'acknowledges': [] } return attendee
def check_permissions(self, *args, **kwargs): try: invite_id = read_parameter_from_request('invite_id', self, kwargs=kwargs,safe=False) invite = Invite.get_by_unique_id(invite_id) if not invite: raise Exception( "This is not a valid Event. " "Please check the url you're trying to access" ) invite_attendee_id = None if InvitePermission.Attendee in permissions or InvitePermission.Organizer in permissions: invite_attendee_id = read_parameter_from_request('invite_attendee_id', self, kwargs) current_user = None session_token = read_token(self) if session_token and ValidateSessionTokenCommand( session_token=session_token ).execute(): current_user = SessionToken.get_user_from_session_token( session_token_id=session_token ) if not ValidateInvitePermissionsCommand( invite, current_user=current_user, invite_attendee_id=invite_attendee_id, permissions=permissions ).execute(): raise AuthenticationException("You dont have the permissions to modify the current Event") self.user = current_user except AuthenticationException, e: self.abort(401) raise e
def query(self): """ Returns the invite organizer minimally formatted This is a valid data-format: { 'unique_id': '', 'name': u'', 'phone': 'email': '', 'status':, 'is_organizer':, } """ if not self.invite: self.invite = Invite.get_by_unique_id(self.invite_unique_id) invite_attendee = InviteAttendee.query( ndb.AND(InviteAttendee.invite == self.invite.key, InviteAttendee.is_organizer == True)).get() if not invite_attendee: return None attendee = { 'unique_id': invite_attendee.unique_id, 'invite_attendee_id': invite_attendee.unique_id, 'name': invite_attendee.name, 'phone': invite_attendee.phone, 'email': invite_attendee.email, 'user_id': invite_attendee.user.id() if invite_attendee.user else None, 'status': AttendeeStatus.ORGANIZER, 'notifications': [], 'acknowledges': [] } return attendee
def execute(self): if not self.invite: self.invite = Invite.get_by_unique_id(self.invite_unique_id) invite_attendees = InviteAttendee.query( InviteAttendee.unique_id.IN(self.attendees_unique_ids) ).fetch() body = { 'invite_unique_id': self.invite.unique_id, 'uniquecall_id': guid(), 'attendees': [] } bulk_notifications = [] for invite_attendee in invite_attendees: if self._check_if_skip_attendee(invite_attendee): continue bulk_notifications += self.create_notification_records(invite_attendee) body['attendees'].append(NotifyAttendeeQuery( invite_attendee ).query()) group_id = EventQueue.get_group_id(self.invite.unique_id) EventQueue.push_event( endpoint=config.get('api_url') + "/attendees", headers=get_voiceflows_headers(), payload=body, group_id=group_id, #Same Group as Invite Creation priority=1 #Lower priority than Invite Creation ) ndb.put_multi(bulk_notifications)
def query(self): """ Returns a list of Invite Attendee Notifications This is a valid data-format: [ { 'invite_attendee_id': '', 'name': u'', 'phone': 'email': '', 'status': '', 'response_on':'', 'notified': True|False } ] """ if not self.invite: self.invite = Invite.get_by_unique_id(self.invite_unique_id) if not self.invite: raise InviteNotFoundException() invite_attendee_notifications = InviteAttendeeNotification.get_by_invite( self.invite ) result = [] for invite_attendee in self.invite.get_attendees(): invite_attendee_query = InviteAttendeeQuery(invite_attendee).query() invite_attendee_query['notified'] = self._is_notified( invite_attendee, invite_attendee_notifications ) result.append(invite_attendee_query) return result
def view_confirmation(self, invite_id): invite = Invite.get_by_unique_id(invite_id) if not invite.organizer_email: raise Exception("There's no need for a confirmation email for this invite") return self.render_template("invite_confirmation.html", organizer_email=invite.organizer_email)
def execute(self): invite = Invite.get_by_unique_id(self.unique_id) invite.title = self.invite_title invite.put() index_invite(invite)
def query(self): """ Returns a full fledge invite in a dictionary form It also contains attendees and responses from attendees { 'invite_unique_id 'attendees': [ { 'phone': '', 'email': '*****@*****.**', 'name': u'', 'status': '', 'last_response_on': '', 'notified': True|False } ], 'email_template':{ 'id': 0, #This number represents the TemplateModelId }, 'SmsTemplate':{ 'text': "Hello World" }, 'start': '2014-10-06 04:01AM', 'end': '2014-10-06 04:01AM', 'where': 'Location', 'title': 'Candle', 'sharing_options':{ 'facebook':True, }, palette: { name: '', main_color: #FFF, main_bg_color: #000 } 'user_id': u'5302669702856704' #Not mandatory, could be anonymous } """ if not self.invite: self.invite = Invite.get_by_unique_id(self.invite_unique_id) invite = self.invite if not invite: raise query.InviteNotFoundException() result = { 'unique_id': invite.unique_id, 'title': invite.title, 'start': convert_to_user_date( invite.start, invite.utc_offset ).strftime("%Y-%m-%d %H:%M"), 'end': convert_to_user_date( invite.end, invite.utc_offset ).strftime("%Y-%m-%d %H:%M") if invite.end is not None else '', 'description': invite.description, 'where': invite.where, 'poster_image_id': invite.poster_picture.urlsafe() if invite.poster_picture else None, 'palette': query.PaletteQuery(palette=invite.palette.get()).query() if invite.palette else None #'user_id': None if not invite.user else invite.user.get().id() } if invite.comments is None: invite.comments = [] invite_attendees = query.InviteAttendeesQuery( invite_unique_id=self.invite_unique_id ) invite_comments = query.InviteCommentsQuery( invite_unique_id=self.invite_unique_id ) result.update({ 'attendees': invite_attendees.query(), 'comments': invite_comments.query() }) return result
def execute(self): invite = Invite.get_by_unique_id(self.unique_id) invite.description = self.invite_description invite.put() index_invite(invite)
def query(self): """ Returns a full fledge invite in a dictionary form It also contains attendees and responses from attendees { 'invite_unique_id 'attendees': [ { 'phone': '', 'email': '*****@*****.**', 'name': u'', 'status': '', 'last_response_on': '', 'notified': True|False } ], 'email_template':{ 'id': 0, #This number represents the TemplateModelId }, 'SmsTemplate':{ 'text': "Hello World" }, 'start': '2014-10-06 04:01AM', 'end': '2014-10-06 04:01AM', 'where': 'Location', 'title': 'Candle', 'sharing_options':{ 'facebook':True, }, palette: { name: '', main_color: #FFF, main_bg_color: #000 } 'user_id': u'5302669702856704' #Not mandatory, could be anonymous } """ if not self.invite: self.invite = Invite.get_by_unique_id(self.invite_unique_id) invite = self.invite if not invite: raise query.InviteNotFoundException() result = { 'unique_id': invite.unique_id, 'title': invite.title, 'start': convert_to_user_date(invite.start, invite.utc_offset).strftime("%Y-%m-%d %H:%M"), 'end': convert_to_user_date(invite.end, invite.utc_offset).strftime("%Y-%m-%d %H:%M") if invite.end is not None else '', 'description': invite.description, 'where': invite.where, 'poster_image_id': invite.poster_picture.urlsafe() if invite.poster_picture else None, 'palette': query.PaletteQuery(palette=invite.palette.get()).query() if invite.palette else None #'user_id': None if not invite.user else invite.user.get().id() } if invite.comments is None: invite.comments = [] invite_attendees = query.InviteAttendeesQuery( invite_unique_id=self.invite_unique_id) invite_comments = query.InviteCommentsQuery( invite_unique_id=self.invite_unique_id) result.update({ 'attendees': invite_attendees.query(), 'comments': invite_comments.query() }) return result
def query(self): """ Returns a partial invite in a dictionary form It also contains attendees and responses from attendees { 'unique_id, 'email_template':{ 'id': 0, #This number represents the TemplateModelId }, 'SmsTemplate':{ 'text': "Hello World" }, 'start': '2014-10-06 04:01AM', 'end': '2014-10-06 04:01AM', 'where': 'Location', 'title': 'Candle', 'sharing_options':{ 'facebook':True, } 'user_id': u'5302669702856704' #Not mandatory, could be anonymous } """ if not self.invite: self.invite = Invite.get_by_unique_id(self.invite_unique_id) invite = self.invite email_template_model = TemplateModel() return { 'unique_id': invite.unique_id, 'title': invite.title, 'start': convert_to_user_date( invite.start, invite.utc_offset ).strftime("%Y-%m-%d %H:%M"), 'end': convert_to_user_date( invite.end, invite.utc_offset ).strftime("%Y-%m-%d %H:%M") if invite.end is not None else '', 'description': invite.description, 'where': invite.where, 'poster_image_id': invite.poster_picture.urlsafe() if invite.poster_picture else None, 'maxparticipants': 0, 'confirmed': 0, 'email_template': { 'subject': 'You have been invited to {{title}}', 'url': email_template_model.get_email_template_url(), 'response_url': email_template_model.get_email_response_url(), }, 'response_email_template': { 'subject': "Thank you {{name}} for your response", 'url': email_template_model.get_email_response_url(), 'redirect_url': email_template_model.get_email_redirect_url(), }, 'sms_template':{ 'body': "Hello world" #Not used for now }, #'user_id': None if not invite.user else invite.user.get().id() }