def resource_found(point): print(point) if isinstance(point, str): point = json.loads(point) idx = uuid.UUID(point['id']) tower_id = uuid.UUID(point['tower_id']) resource = None try: resource = Resource.get(tower_id=tower_id, id=idx) except DoesNotExist as e: print(e) if resource: print(resource) if not current_user.is_authenticated: user_id = uuid.UUID('5da5957c-9775-4f5f-b257-4a93a520b15c') else: user_id = current_user.id user_resource = UserFoundResource(id=resource.id, user_id=user_id, type=resource.type, lat=resource.lat, lon=resource.lon, quantity=resource.quantity, name=resource.name, description=resource.description, tower_id=resource.tower_id) user_resource.save() resource.delete() towerLocation = TowerLocation.get(lat=round(resource.lat / 1000), lon=round(resource.lon / 1000)) create_resource(str(tower_id), towerLocation.lat, towerLocation.lon, 1)
def validate(self, data: Dict): super(Policy, self).validate(data) effect = data.get('effect') action = data.get('action') resource = data.get('resource') if effect not in ['allow', 'deny']: raise ValidationError( message=f'unsupported effect "{effect}"' ) if action != '*' and int(action) not in [action.value for action in ActionTypes]: raise ValidationError( message=f'unsupported action "{action}"' ) if resource != '*': resource_obj = next( (resource for resource in Resource.get(filters={'name': [resource]})), None ) if not resource_obj: raise ValidationError( message=f'Resource Not Found "{resource}"' )