Пример #1
0
 def get_project(self, project_id):
     project = Project.query.filter(Project.id == project_id).first()
     if not project:
         raise NotFoundException(Project)
     if not auth.current_user.is_admin and project.creator != auth.current_user:
         raise ForbiddenException()
     return project
Пример #2
0
    def delete(self):
        parser = reqparse.RequestParser()
        parser.add_argument('ids',
                            type=int,
                            action='append',
                            location='json',
                            required=True)
        args = parser.parse_args()

        to_be_deleted = []
        for project_id in args['ids']:
            project = Project.query.filter(Project.id == project_id).first()
            if not project:
                raise NotFoundException(f'Project {project_id} not found')
            to_be_deleted.append(project)

        for project in to_be_deleted:
            db.session.delete(project)

        db.session.commit()

        return jsonify(
            {'message': 'Project {} deleted'.format(str(args['ids']))})
Пример #3
0
 def get(self, map_id):
     m = Map.query.filter(Map.id == map_id).first()
     if not m:
         raise NotFoundException(Map)
     return m
Пример #4
0
 def get_marker(self, map_id, marker_id):
     marker = Marker.query.filter(Marker.map_id == map_id,
                                  Marker.id == marker_id).first()
     if not marker:
         raise NotFoundException(Marker)
     return marker