Ejemplo n.º 1
0
def tag(name):
    """Returns a Tag object for the given name"""

    slug = Tag.clean_tag(name)

    log.debug('Looking for Tag with slug "%s"...' % (slug,))
    t, created = Tag.objects.get_or_create(slug=slug, defaults={'name': name})
    log.debug('Found Tag %s. Name: %s Slug: %s Created: %s' % (t.pk, t.name, t.slug, created))

    if not t.name:
        t.name = name
        t.save()

    return t
Ejemplo n.º 2
0
def article_tags(tagstr):
    """
    Convert a space-delimited list of tags to their :class:`Tag` equivalients.

    TODO:   Improve tags to support multiple words (make ``django-articles`` use
            ``django-taggit``!)

    :param tagstr: Tags in the form, ``one two three``.
    """
    from publish.conf import DB
    from articles.models import Tag

    tag = lambda n: Tag.objects.using(DB).get_or_create(name=Tag.clean_tag(n))[0]
    return [tag(t) for t in tagstr.split()]
Ejemplo n.º 3
0
 def test_get_absolute_url(self):
     name = 'Hi There'
     t = Tag.objects.create(name=name)
     self.assertEqual(t.get_absolute_url(), reverse('articles_display_tag', args=[Tag.clean_tag(name)]))