def get(self, startKey=None): ''' Return activities by pack of LIMIT at JSON format. If a start key is given in URL (it means a date like 2010-10-05-12-30-48), activities until this date are returned. Else latest activities are returned. Arguments: *startKey* The date until where activities should be returned. ''' if startKey: dateString = date_util.get_db_utc_date_from_url_date(startKey) docs = ActivityManager.get_all(startKey=dateString, tag="all") else: docs = ActivityManager.get_all() for doc in docs: try: subdoc = Activity.get_db().get(doc.docId) doc.subdoc = subdoc except: pass self.return_documents(docs)
def clear_all_activities_from_database(step): activities = ActivityManager.get_all() while activities: for activity in activities: activity.delete() activities = ActivityManager.get_all()
def post(self, key): ''' Resend post with *key* as key to the contact given in the posted JSON. Corresponding activity ID is given inside the posted json. Here is the format : {"contactId":"data","activityId":"data"} ''' micropost = MicroPostManager.get_micropost(key) data = self.get_body_as_dict(expectedFields=["contactId", "activityId"]) if micropost and data: contactId = data["contactId"] activityId = data["activityId"] contact = ContactManager.getTrustedContact(contactId) activity = ActivityManager.get_activity(activityId) if not contact: self.return_failure("Contact not found", 404) elif not activity: self.return_failure("Activity not found", 404) else: if contact.name: info_str = "Attempt to resend a post to contact: %s." logger.info(info_str % contact.name) self.forward_to_contact(micropost, contact, activity) else: self.return_failure("Micropost not found", 404)
def put(self, key): ''' Resend deletion of micropost with *key* as key to the contact given in the posted JSON. Corresponding activity ID is given inside the posted json. Here is the format : {"contactId":"data","activityId":"data"} ''' data = self.get_body_as_dict( expectedFields=["contactId", "activityId", "extra"]) if data: contactId = data["contactId"] activityId = data["activityId"] date = data["extra"] contact = ContactManager.getTrustedContact(contactId) activity = ActivityManager.get_activity(activityId) if not contact: self.return_failure("Contact not found", 404) elif not activity: self.return_failure("Activity not found", 404) else: user = UserManager.getUser() micropost = MicroPost( authorKey=user.key, date=date_util.get_date_from_db_date(date) ) logger.info( "Attempt to resend a post deletion to contact: {}.".format( contact.name)) httpClient = ContactClient() body = micropost.toJson(localized=False) try: httpClient.put(contact, CONTACT_PATH, body, callback=(yield gen.Callback("retry"))) response = yield gen.Wait("retry") if response.error: self.return_failure( "Deleting micropost to contact failed.") else: for error in activity.errors: if error["contactKey"] == contact.key: activity.errors.remove(error) activity.save() self.return_success( "Micropost correctly redeleted.") except: self.return_failure("Deleting micropost to contact failed.") else: self.return_failure("Micropost not found", 404)
def put(self, key): """ Resend deletion of micropost with *key* as key to the contact given in the posted JSON. Corresponding activity ID is given inside the posted json. Here is the format : {"contactId":"data","activityId":"data"} """ data = self.get_body_as_dict(expectedFields=["contactId", "activityId", "extra"]) if data: contactId = data["contactId"] activityId = data["activityId"] date = data["extra"] contact = ContactManager.getTrustedContact(contactId) activity = ActivityManager.get_activity(activityId) if not contact: self.return_failure("Contact not found", 404) elif not activity: self.return_failure("Activity not found", 404) else: user = UserManager.getUser() picture = Picture(authorKey=user.key, date=date_util.get_date_from_db_date(date)) info = "Attempt to resend a picture deletion to contact: {}." logger.info(info.format(contact.name)) self.forward_to_contact(picture, contact, activity, method="PUT") else: self.return_failure("Micropost not found", 404)
def post(self, key): ''' Resend post with *key* as key to the contact given in the posted JSON. Corresponding activity ID is given inside the posted json. Here is the format : {"contactId":"data","activityId":"data"} ''' common = CommonManager.get_common(key) idInfos = self.request.body ids = json_decode(idInfos) if common and idInfos: contactId = ids["contactId"] activityId = ids["activityId"] contact = ContactManager.getTrustedContact(contactId) activity = ActivityManager.get_activity(activityId) if not contact: self.return_failure("Contact not found", 404) elif not activity: self.return_failure("Activity not found", 404) else: info = "Attemp to resend a common to contact: {}." logger.info(info.format(contact.name)) self.forward_to_contact(common, contact, activity) else: self.return_failure("Common not found", 404)
def post(self, key): ''' Resend post with *key* as key to the contact given in the posted JSON. Corresponding activity ID is given inside the posted json. Here is the format : {"contactId":"data","activityId":"data"} ''' picture = PictureManager.get_picture(key) idInfos = self.request.body ids = json_decode(idInfos) if picture and idInfos: contactId = ids["contactId"] activityId = ids["activityId"] contact = ContactManager.getTrustedContact(contactId) activity = ActivityManager.get_activity(activityId) if not contact: self.return_failure("Contact not found", 404) elif not activity: self.return_failure("Activity not found", 404) else: info = "Attemp to resend a picture to contact: {}." logger.info(info.format(contact.name)) self.forward_to_contact(picture, contact, activity) else: self.return_failure("Picture not found", 404)
def post(self, key): ''' Resend post with *key* as key to the contact given in the posted JSON. Corresponding activity ID is given inside the posted json. Here is the format : {"contactId":"data","activityId":"data"} ''' micropost = MicroPostManager.get_micropost(key) data = self.get_body_as_dict( expectedFields=["contactId", "activityId"]) if micropost and data: contactId = data["contactId"] activityId = data["activityId"] contact = ContactManager.getTrustedContact(contactId) activity = ActivityManager.get_activity(activityId) if not contact: self.return_failure("Contact not found", 404) elif not activity: self.return_failure("Activity not found", 404) else: if contact.name: info_str = "Attempt to resend a post to contact: %s." logger.info(info_str % contact.name) self.forward_to_contact(micropost, contact, activity) else: self.return_failure("Micropost not found", 404)
def put(self, key): ''' Resend deletion of micropost with *key* as key to the contact given in the posted JSON. Corresponding activity ID is given inside the posted json. Here is the format : {"contactId":"data","activityId":"data"} ''' data = self.get_body_as_dict( expectedFields=["contactId", "activityId", "extra"]) if data: contactId = data["contactId"] activityId = data["activityId"] date = data["extra"] contact = ContactManager.getTrustedContact(contactId) activity = ActivityManager.get_activity(activityId) if not contact: self.return_failure("Contact not found", 404) elif not activity: self.return_failure("Activity not found", 404) else: user = UserManager.getUser() common = Common(authorKey=user.key, date=date_util.get_date_from_db_date(date)) info = "Attemp to resend a common deletion to contact: {}." logger.info(info.format(contact.name)) self.forward_to_contact(common, contact, activity, method="PUT") else: self.return_failure("Micropost not found", 404)
def checks_that_contact_update_activity_is_properly_created(step): activity = ActivityManager.get_all().first() assert "modifies" == activity.verb assert "profile" == activity.docType assert False == activity.isMine assert "default contact 2" == activity.author
def and_activity_has_no_more_errors(step): activity = ActivityManager.get_activity(world.activity._id) assert 0 == len(activity.errors)
def and_first_activity_has_no_more_errors(step): activity = ActivityManager.get_activity(world.activity._id) assert 0 == len(activity.errors)
def checks_that_deletion_activity_was_created(step): activity = ActivityManager.get_mine().first() assert activity is not None assert activity.verb == "deletes", activity.toDict() assert activity.docType == "note" assert activity.isMine
def retrieve_last_activities(step): world.activities = ActivityManager.get_all()
def retrieve_last_activities_of_owner(step): world.activities = ActivityManager.get_mine()
def retrieve_activities_from_date(step, date): world.activities = ActivityManager.get_all(date)
def retrieve_owner_activities_from_date(step, date): world.activities = ActivityManager.get_mine(date)
def get_activity_with_default_activity_id(step): world.new_activity = ActivityManager.get_activity(world.activity._id) assert world.new_activity is not None
def put(self, key): ''' Resend deletion of micropost with *key* as key to the contact given in the posted JSON. Corresponding activity ID is given inside the posted json. Here is the format : {"contactId":"data","activityId":"data"} ''' data = self.get_body_as_dict( expectedFields=["contactId", "activityId", "extra"]) if data: contactId = data["contactId"] activityId = data["activityId"] date = data["extra"] contact = ContactManager.getTrustedContact(contactId) activity = ActivityManager.get_activity(activityId) if not contact: self.return_failure("Contact not found", 404) elif not activity: self.return_failure("Activity not found", 404) else: user = UserManager.getUser() micropost = MicroPost( authorKey=user.key, date=date_util.get_date_from_db_date(date)) logger.info( "Attempt to resend a post deletion to contact: {}.".format( contact.name)) httpClient = ContactClient() body = micropost.toJson(localized=False) try: httpClient.put(contact, CONTACT_PATH, body, callback=(yield gen.Callback("retry"))) response = yield gen.Wait("retry") if response.error: self.return_failure( "Deleting micropost to contact failed.") else: for error in activity.errors: if error["contactKey"] == contact.key: activity.errors.remove(error) activity.save() self.return_success( "Micropost correctly redeleted.") except: self.return_failure( "Deleting micropost to contact failed.") else: self.return_failure("Micropost not found", 404)