def createMicropost(content): micropost = MicroPost() micropost.author = UserManager.getUser().name micropost.authorKey = UserManager.getUser().key micropost.content = content micropost.isMine = True micropost.save() return micropost
def posts_are_created_on_first_newebe_with_tag_tag(step, nbposts, tag): for i in range(int(nbposts)): micropost = MicroPost(author=world.user.name, authorKey=world.user.key, content="content %s" % i, tags=[tag]) micropost.save() time.sleep(1)
def posts_are_created_on_first_newebe_with_tag_tag(step, nbposts, tag): for i in range(int(nbposts)): micropost = MicroPost( author = world.user.name, authorKey = world.user.key, content = "content %s" % i, tags = [tag] ) micropost.save() time.sleep(1)
def post(self): ''' When post request is received, micropost content is expected inside a string under *content* of JSON object. It is extracted from it then stored inside a new Microposts object. Micropost author and date are set from incoming data. ''' data = self.get_body_as_dict(expectedFields=["date", "authorKey"]) if data: db_date = data.get("date") date = date_util.get_date_from_db_date(db_date) authorKey = data.get("authorKey") contact = ContactManager.getTrustedContact(authorKey) micropost = MicroPostManager.get_contact_micropost( authorKey, db_date) if contact: if not micropost: micropost = MicroPost( authorKey=authorKey, author=data["author"], content=data['content'], date=date, attachments=data.get("attachments", []), pictures_to_download=data.get("pictures", []), commons_to_download=data.get("commons", []), isMine=False, tags=contact.tags) micropost.save() self.create_creation_activity(contact, micropost, "writes", "micropost") self._write_create_log(micropost) postIndexer = indexer.Indexer() postIndexer.index_micropost(micropost) for websocket_client in websocket_clients: websocket_client.write_message(micropost.toJson()) self.return_json(micropost.toJson(), 201) else: self.return_failure("Contact is not registered.", 405) else: self.return_failure("No data sent.", 405)
def post(self): """ When post request is received, micropost content is expected inside a string under *content* of JSON object. It is extracted from it then stored inside a new Microposts object. Micropost author and date are set from incoming data. """ data = self.get_body_as_dict(expectedFields=["date", "authorKey"]) if data: db_date = data.get("date") date = date_util.get_date_from_db_date(db_date) authorKey = data.get("authorKey") contact = ContactManager.getTrustedContact(authorKey) micropost = MicroPostManager.get_contact_micropost(authorKey, db_date) if contact: if not micropost: micropost = MicroPost( authorKey=authorKey, author=data["author"], content=data["content"], date=date, attachments=data.get("attachments", []), pictures_to_download=data.get("pictures", []), commons_to_download=data.get("commons", []), isMine=False, tags=contact.tags, ) micropost.save() self.create_creation_activity(contact, micropost, "writes", "micropost") self._write_create_log(micropost) postIndexer = indexer.Indexer() postIndexer.index_micropost(micropost) for websocket_client in websocket_clients: websocket_client.write_message(micropost.toJson()) self.return_json(micropost.toJson(), 201) else: self.return_failure("Contact is not registered.", 405) else: self.return_failure("No data sent.", 405)
def post(self): ''' When post request is received, micropost data are expected as a JSON object. It is extracted from it then stored inside a new Microposts object. Micropost author is automatically set with current user and current date is set as date. Created microposts are forwarded to contacts. ''' logger.info("Micropost post received.") data = self.get_body_as_dict(expectedFields=["content", "tags"]) if data and data["content"]: user = UserManager.getUser() converter = Converter() micropost = MicroPost(authorKey=user.key, author=user.name, content=data['content'], attachments=converter.convert(data), tags=data["tags"], pictures=data.get("pictures", []), commons=data.get("commons", [])) micropost.save() converter.add_files(micropost) self.create_owner_creation_activity(micropost, "writes", "micropost") self.send_creation_to_contacts(CONTACT_PATH, micropost) postIndexer = indexer.Indexer() postIndexer.index_micropost(micropost) logger.info("Micropost successfuly posted.") self.return_json(micropost.toJson()) else: self.return_failure( "Sent data were incorrects. No post was created.", 400)
def post(self): ''' When post request is received, micropost data are expected as a JSON object. It is extracted from it then stored inside a new Microposts object. Micropost author is automatically set with current user and current date is set as date. Created microposts are forwarded to contacts. ''' logger.info("Micropost post received.") data = self.get_body_as_dict(expectedFields=["content", "tags"]) if data and data["content"]: user = UserManager.getUser() converter = Converter() micropost = MicroPost( authorKey=user.key, author=user.name, content=data['content'], attachments=converter.convert(data), tags=data["tags"] ) micropost.save() converter.add_files(micropost) self.create_owner_creation_activity(micropost, "writes", "micropost") self.send_creation_to_contacts(CONTACT_PATH, micropost) postIndexer = indexer.Indexer() postIndexer.index_micropost(micropost) logger.info("Micropost successfuly posted.") self.return_json(micropost.toJson()) else: self.return_failure( "Sent data were incorrects. No post was created.", 400)
def given_there_are_3_posts_of_and_3_posts_of_my_contacts( step, nbposts, nbcontactposts): nbposts = int(nbposts) nbcontactposts = int(nbcontactposts) for i in range(1, nbposts + 1): micropost = MicroPost() micropost.author = UserManager.getUser().name micropost.authorKey = UserManager.getUser().key micropost.content = "my content {}".format(i) micropost.date = datetime.datetime(2011, i, 01, 11, 05, 12) micropost.isMine = True micropost.save() for i in range(1, nbcontactposts + 1): micropost = MicroPost() micropost.author = world.user2.name micropost.authorKey = world.user2.key micropost.content = "contact content {}".format(i) micropost.date = datetime.datetime(2011, i, 10, 11, 05, 12) micropost.isMine = False micropost.save()
def given_there_are_3_posts_of_and_3_posts_of_my_contacts(step, nbposts, nbcontactposts): nbposts = int(nbposts) nbcontactposts = int(nbcontactposts) for i in range(1, nbposts + 1): micropost = MicroPost() micropost.author = UserManager.getUser().name micropost.authorKey = UserManager.getUser().key micropost.content = "my content {}".format(i) micropost.date = datetime.datetime(2011, i, 01, 11, 05, 12) micropost.isMine = True micropost.save() for i in range(1, nbcontactposts + 1): micropost = MicroPost() micropost.author = world.user2.name micropost.authorKey = world.user2.key micropost.content = "contact content {}".format(i) micropost.date = datetime.datetime(2011, i, 10, 11, 05, 12) micropost.isMine = False micropost.save()