def getMutablePropertiesFromRequest(self, request, mutable_permission = 'operations_mutable'): """ """ params = extractPostData(request) allowed_fields = [fieldName for fieldName in self.schema if self.schema[fieldName].get(mutable_permission, 0)] properties = {fieldName: params.get(fieldName) for fieldName in allowed_fields if params.get(fieldName, None) is not None} return properties
def Like(context, request): try: checkRequestConsistency(request) data = extractPostData(request) except: return HTTPBadRequest() try: checkDataLike(data) checkIsValidUser(context, data) checkIsValidActivity(context, data) except: return HTTPBadRequest() # Once verified the id of the user, convert the userid to an ObjectId data['actor']['_id'] = ObjectId(data['actor']['id']) del data['actor']['id'] # Once verified the activity is valid, convert the id to an ObjectId data['object']['_id'] = ObjectId(data['object']['id']) del data['object']['id'] # Set published date format published = rfc3339(time.time()) data['published'] = published # Insert activity in the database context.db.activity.insert(data) # Search for the referenced activity by id and update his likes.items field person = { '_id': data['actor']['_id'], 'objectType': 'person', 'username': data['actor']['username'] } context.db.activity.update({'_id': data['object']['_id']}, { '$push': { 'object.likes.items': person }, '$inc': { 'object.likes.totalItems': 1 } }) return HTTPOk()
def getMutablePropertiesFromRequest(self, request, mutable_permission='operations_mutable' ): """ """ params = extractPostData(request) allowed_fields = [ fieldName for fieldName in self.schema if self.schema[fieldName].get(mutable_permission, 0) ] properties = { fieldName: params.get(fieldName) for fieldName in allowed_fields if params.get(fieldName, None) is not None } return properties
def Like(context, request): try: checkRequestConsistency(request) data = extractPostData(request) except: return HTTPBadRequest() try: checkDataLike(data) checkIsValidUser(context, data) checkIsValidActivity(context, data) except: return HTTPBadRequest() # Once verified the id of the user, convert the userid to an ObjectId data['actor']['_id'] = ObjectId(data['actor']['id']) del data['actor']['id'] # Once verified the activity is valid, convert the id to an ObjectId data['object']['_id'] = ObjectId(data['object']['id']) del data['object']['id'] # Set published date format published = rfc3339(time.time()) data['published'] = published # Insert activity in the database context.db.activity.insert(data) # Search for the referenced activity by id and update his likes.items field person = {'_id': data['actor']['_id'], 'objectType': 'person', 'username': data['actor']['username']} context.db.activity.update({'_id': data['object']['_id']}, { '$push': {'object.likes.items': person}, '$inc': {'object.likes.totalItems': 1} }) return HTTPOk()
def fromRequest(self, request, rest_params={}): self.mdb_collection = request.context.db[self.collection] self.data = RUDict({}) self.data.update(extractPostData(request)) self.data.update(rest_params) # Since we are building from a request, # overwrite actor with the validated one from the request in source self.data['actor'] = request.actor self.processFields() #check if the object we pretend to create already exists existing_object = self.alreadyExists() if not existing_object: # if we are creating a new object, set the current date and build self['published'] = datetime.datetime.utcnow() self._on_create_custom_validations() self.buildObject() else: # if it's already on the DB, just populate with the object data self.update(existing_object)