Exemple #1
0
def story_add_tag(story_id, tag_name, current_user=None):
    session = api_base.get_session()

    with session.begin(subtransactions=True):

        # Get a tag or create a new one
        tag = story_tags.tag_get_by_name(tag_name, session=session)
        if not tag:
            tag = story_tags.tag_create({"name": tag_name})

        story = story_get_simple(story_id,
                                 session=session,
                                 current_user=current_user)
        if not story:
            raise exc.NotFound(
                _("%(name)s %(id)s not found") % {
                    'name': "Story",
                    'id': story_id
                })

        if tag_name in [t.name for t in story.tags]:
            raise exc.DBDuplicateEntry(
                _("The Story %(id)d already has a tag %(tag)s") % {
                    'id': story_id,
                    'tag': tag_name
                })

        story.tags.append(tag)
        story.updated_at = datetime.datetime.now(tz=pytz.utc)
        session.add(story)
    session.expunge(story)
def story_add_tag(story_id, tag_name, current_user=None):
    session = api_base.get_session()

    with session.begin(subtransactions=True):

        # Get a tag or create a new one
        tag = story_tags.tag_get_by_name(tag_name, session=session)
        if not tag:
            tag = story_tags.tag_create({"name": tag_name})

        story = story_get_simple(
            story_id, session=session, current_user=current_user)
        if not story:
            raise exc.NotFound(_("%(name)s %(id)s not found") %
                               {'name': "Story", 'id': story_id})

        if tag_name in [t.name for t in story.tags]:
            raise exc.DBDuplicateEntry(
                _("The Story %(id)d already has a tag %(tag)s") %
                {'id': story_id, 'tag': tag_name})

        story.tags.append(tag)
        story.updated_at = datetime.datetime.now(tz=pytz.utc)

        session.add(story)
    session.expunge(story)
Exemple #3
0
    def post(self, tag_name):
        """Create a tag not attached to any Story.

        :param tag_name: The name of a new tag.
        """

        tag = tags_api.tag_create({"name": tag_name})
        return wmodels.Tag.from_db_model(tag)
Exemple #4
0
    def post(self, tag_name):
        """Create a tag not attached to any Story.

        :param tag_name: The name of a new tag.
        """

        tag = tags_api.tag_create({"name": tag_name})
        return wmodels.Tag.from_db_model(tag)
Exemple #5
0
    def post(self, tag_name):
        """Create a tag not attached to any Story.

        Example::

           curl https://my.example.org/api/v1/tags \\
           -H 'Authorization: Bearer MY_ACCESS_TOKEN' \\
           -H 'Content-Type: application/json;charset=UTF-8' \\
           --data-binary '{"tag_name":"created-via-api"}'

        :param tag_name: The name of a new tag.
        """

        tag = tags_api.tag_create({"name": tag_name})
        return wmodels.Tag.from_db_model(tag)
Exemple #6
0
    def post(self, tag_name):
        """Create a tag not attached to any Story.

        Example::

           curl https://my.example.org/api/v1/tags \\
           -H 'Authorization: Bearer MY_ACCESS_TOKEN' \\
           -H 'Content-Type: application/json;charset=UTF-8' \\
           --data-binary '{"tag_name":"created-via-api"}'

        :param tag_name: The name of a new tag.
        """

        tag = tags_api.tag_create({"name": tag_name})
        return wmodels.Tag.from_db_model(tag)