Пример #1
0
    def put(self, source_id):
        data = Source.parser.parse_args()
        source = SourceModel.find_by_id(source_id)

        if source is None:
            source = SourceModel(data)
        else:
            source.name = data['name']
            source.url = data['url']

        source.save_to_db()

        return source.json(), 201
Пример #2
0
    def post(self):
        data = Source.parser.parse_args()
        if SourceModel.find_by_name(data.name):
            return {
                'message':
                'An source with name "{}" already exists.'.format(data.name)
            }, 400

        source = SourceModel(data)

        try:
            source.save_to_db()
        except:
            return {"message": "An error occurred inserting the source."}, 500

        return source.json(), 201
Пример #3
0
 def mutate(self, info, pointID, url, name=None):
     point, pointRoot = PointModel.getCurrentByRootKey(pointID)
     newPointVersion = point.update(
         user=info.context.current_user,
         sourcesToAdd=[SourceModel(parent=point.key, url=url, name=name)])
     return AddSource(point=newPointVersion)