Exemplo n.º 1
0
Arquivo: tag.py Projeto: MrPetru/spam
 def get_delete(self, tag_id, **kwargs):
     """Display a DELETE confirmation form."""
     tag = tag_get(tag_id)
     f_confirm.custom_method = 'DELETE'
     f_confirm.value = dict(tag_id=tag.id)
     tmpl_context.form = f_confirm
     return dict(title='%s %s?' % (_('Are you sure you want to delete tag:'),
                                                                     tag.id))
Exemplo n.º 2
0
Arquivo: tag.py Projeto: MrPetru/spam
    def post(self, taggable_id, tagids=[], new_tags=None):
        """Add tags to a ``taggable`` obect."""
        session = session_get()
        user = tmpl_context.user
        taggable = taggable_get(taggable_id)

        if isinstance(tagids, list):
            tags = [tag_get(i) for i in tagids]
        else:
            tags = [tag_get(tagids)]

        if new_tags:
            tags.extend([tag_get(name) for name in new_tags.split(', ')])

        added_tags = []
        updates = []
        for tag in tags:
            if tag not in taggable.tags:
                taggable.tags.append(tag)
                added_tags.append(tag)

                # prepare updates to notify clients
                updates.append(dict(item=tag, type='added', topic=TOPIC_TAGS,
                                                            filter=taggable_id))

        if added_tags:
            added = ', '.join([t.id for t in added_tags])
            msg = '%s %s %s' % (added,
                                n_('tag added to:',
                                   'tags added to:', len(added_tags)),
                                taggable_id)
            status = 'ok'

            # notify clients
            notify.send(updates)

            # log into Journal
            journal.add(user, '%s - %s' % (msg, taggable.tagged))
        else:
            msg = _('No new tag applied')
            status = 'info'

        return dict(msg=msg, status=status, updates=updates)
Exemplo n.º 3
0
Arquivo: tag.py Projeto: MrPetru/spam
    def remove(self, taggable_id, tagids=[]):
        """Remove tags from an object."""
        session = session_get()
        user = tmpl_context.user
        taggable = taggable_get(taggable_id)

        if isinstance(tagids, list):
            tags = [tag_get(i) for i in tagids]
        else:
            tags = [tag_get(tagids)]

        removed_tags = []
        updates = []
        for tag in tags:
            if tag in taggable.tags:
                taggable.tags.remove(tag)
                removed_tags.append(tag)

                # prepare updates
                updates.append(dict(item=tag, type='deleted', topic=TOPIC_TAGS,
                                                            filter=taggable_id))

        if removed_tags:
            removed = ', '.join([t.id for t in removed_tags])
            msg = '%s %s %s' % (removed,
                                n_('tag removed from:',
                                   'tags removed from:', len(removed_tags)),
                                taggable_id)
            status = 'ok'

            # notify clients
            notify.send(updates)

            # log into Journal
            journal.add(user, '%s - %s' % (msg, taggable.tagged))
        else:
            msg = _('No tag removed')
            status = 'info'

        return dict(msg=msg, status=status, updates=updates)
Exemplo n.º 4
0
Arquivo: tag.py Projeto: MrPetru/spam
    def post_delete(self, tag_id):
        """Delete a tag."""
        session = session_get()
        user = tmpl_context.user
        tag = tag_get(tag_id)

        session.delete(tag)

        msg = '%s %s' % (_('Deleted tag:'), tag.id)

        # log into Journal
        journal.add(user, '%s - %s' % (msg, tag))
        
        # notify clients
        updates = [dict(item=tag, type='deleted', topic=TOPIC_TAGS)]
        notify.send(updates)

        return dict(msg=msg, status='ok', updates=updates)
Exemplo n.º 5
0
Arquivo: tag.py Projeto: MrPetru/spam
 def get_one(self, taggable_id, tag_id):
     """This method is currently unused, but is needed for the 
     RESTController to work."""
     tag = tag_get(tag_id)
     return dict(tag=tag)