(self, sketch_id, timeline_id)
return HTTP_STATUS_CODE_OK
Handles GET request to the resource.

        Args:
            sketch_id: Integer primary key for a sketch database model
            timeline_id: Integer primary key for a timeline database model
Handles GET request to the resource.
Handles GET request to the resource .
def post(self, sketch_id, timeline_id):
        """Handles GET request to the resource.

        Args:
            sketch_id: Integer primary key for a sketch database model
            timeline_id: Integer primary key for a timeline database model
        """
        sketch = Sketch.query.get_with_acl(sketch_id)
        if not sketch:
            abort(
                HTTP_STATUS_CODE_NOT_FOUND, 'No sketch found with this ID.')
        timeline = Timeline.query.get(timeline_id)
        if not timeline:
            abort(
                HTTP_STATUS_CODE_NOT_FOUND,
                'No timeline found with this ID.')

        if timeline.sketch is None:
            abort(
                HTTP_STATUS_CODE_NOT_FOUND,
                'No sketch associated with this timeline.')

        # Check that this timeline belongs to the sketch
        if timeline.sketch.id != sketch.id:
            abort(
                HTTP_STATUS_CODE_NOT_FOUND,
                'The sketch ID ({0:d}) does not match with the timeline '
                'sketch ID ({1:d})'.format(sketch.id, timeline.sketch.id))

        if not sketch.has_permission(user=current_user, permission='write'):
            abort(
                HTTP_STATUS_CODE_FORBIDDEN,
                'The user does not have write permission on the sketch.')

        form = forms.TimelineForm.build(request)
        if not form.validate_on_submit():
            abort(
                HTTP_STATUS_CODE_BAD_REQUEST, 'Unable to validate form data.')

        if form.labels.data:
            label_string = form.labels.data
            labels = json.loads(label_string)
            if not isinstance(labels, (list, tuple)):
                abort(
                    HTTP_STATUS_CODE_BAD_REQUEST, (
                        'Label needs to be a JSON string that '
                        'converts to a list of strings.'))
            if not all([isinstance(x, str) for x in labels]):
                abort(
                    HTTP_STATUS_CODE_BAD_REQUEST, (
                        'Label needs to be a JSON string that '
                        'converts to a list of strings (not all strings)'))

            label_action = form.label_action.data
            if label_action not in ('add', 'remove'):
                abort(
                    HTTP_STATUS_CODE_BAD_REQUEST,
                    'Label action needs to be either add or remove.')

            changed = False
            if label_action == 'add':
                changes = []
                for label in labels:
                    changes.append(
                        self._add_label(timeline=timeline, label=label))
                changed = any(changes)
            elif label_action == 'remove':
                changes = []
                for label in labels:
                    changes.append(
                        self._remove_label(timeline=timeline, label=label))
                changed = any(changes)

            if not changed:
                abort(
                    HTTP_STATUS_CODE_BAD_REQUEST,
                    'Label [{0:s}] not {1:s}'.format(
                        ', '.join(labels), label_action))

            db_session.add(timeline)
            db_session.commit()
            return HTTP_STATUS_CODE_OK

        timeline.name = form.name.data
        timeline.description = form.description.data
        timeline.color = form.color.data
        db_session.add(timeline)
        db_session.commit()

        # Update the last activity of a sketch.
        utils.update_sketch_last_activity(sketch)

        return HTTP_STATUS_CODE_OK
def post ( self , sketch_id , timeline_id ) : sketch = Sketch . query . get_with_acl ( sketch_id ) if not sketch : abort ( HTTP_STATUS_CODE_NOT_FOUND , 'No sketch found with this ID.' ) timeline = Timeline . query . get ( timeline_id ) if not timeline : abort ( HTTP_STATUS_CODE_NOT_FOUND , 'No timeline found with this ID.' ) if timeline . sketch is None : abort ( HTTP_STATUS_CODE_NOT_FOUND , 'No sketch associated with this timeline.' ) # Check that this timeline belongs to the sketch if timeline . sketch . id != sketch . id : abort ( HTTP_STATUS_CODE_NOT_FOUND , 'The sketch ID ({0:d}) does not match with the timeline ' 'sketch ID ({1:d})' . format ( sketch . id , timeline . sketch . id ) ) if not sketch . has_permission ( user = current_user , permission = 'write' ) : abort ( HTTP_STATUS_CODE_FORBIDDEN , 'The user does not have write permission on the sketch.' ) form = forms . TimelineForm . build ( request ) if not form . validate_on_submit ( ) : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'Unable to validate form data.' ) if form . labels . data : label_string = form . labels . data labels = json . loads ( label_string ) if not isinstance ( labels , ( list , tuple ) ) : abort ( HTTP_STATUS_CODE_BAD_REQUEST , ( 'Label needs to be a JSON string that ' 'converts to a list of strings.' ) ) if not all ( [ isinstance ( x , str ) for x in labels ] ) : abort ( HTTP_STATUS_CODE_BAD_REQUEST , ( 'Label needs to be a JSON string that ' 'converts to a list of strings (not all strings)' ) ) label_action = form . label_action . data if label_action not in ( 'add' , 'remove' ) : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'Label action needs to be either add or remove.' ) changed = False if label_action == 'add' : changes = [ ] for label in labels : changes . append ( self . _add_label ( timeline = timeline , label = label ) ) changed = any ( changes ) elif label_action == 'remove' : changes = [ ] for label in labels : changes . append ( self . _remove_label ( timeline = timeline , label = label ) ) changed = any ( changes ) if not changed : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'Label [{0:s}] not {1:s}' . format ( ', ' . join ( labels ) , label_action ) ) db_session . add ( timeline ) db_session . commit ( ) return HTTP_STATUS_CODE_OK timeline . name = form . name . data timeline . description = form . description . data timeline . color = form . color . data db_session . add ( timeline ) db_session . commit ( ) # Update the last activity of a sketch. utils . update_sketch_last_activity ( sketch ) return HTTP_STATUS_CODE_OK