# Path: gitcms/tagging/models.py
# class Tag(models.Model):
#     name = models.CharField(u'tag', max_length=255)
#     slug = models.SlugField(u'slug')
#     def __unicode__(self):
#         return self.slug
#     class Meta:
#         verbose_name_plural = tr(u'Tags')
# 
# Path: gitcms/pages/models.py
# class Article(models.Model):
#     title = models.CharField(u'title', max_length=255)
#     url = models.CharField(u'url', max_length=255)
#     meta = models.TextField(u'meta')
#     author = models.TextField(u'author', max_length=255)
#     tags = models.ManyToManyField(Tag)
#     content = models.TextField(u'content')
#     def __unicode__(self):
#         return '%s (%s)' % (self.title, self.url)


from gitcms.tagging.models import Tag
from gitcms.pages.models import Article
from django.shortcuts import get_object_or_404, render_to_response

def bytag(request, tag):
    tag = get_object_or_404(Tag, slug=tag)
    articles = Article.objects.filter(tags=tag)
    return render_to_response(
                'pages/list.html',
                {
                    'pagetitle' : ('Articles tagged %s' % tag.name),
                    'articles' : articles,
                })

def article(request, url):
    if len(url) and url[-1] == '/': url = url[:-1]

# Path: gitcms/tagging/models.py
# class Tag(models.Model):
#     name = models.CharField(u'tag', max_length=255)
#     slug = models.SlugField(u'slug')
#     def __unicode__(self):
#         return self.slug
#     class Meta:
#         verbose_name_plural = tr(u'Tags')
# 
# Path: gitcms/pages/models.py
# class Article(models.Model):
#     title = models.CharField(u'title', max_length=255)
#     url = models.CharField(u'url', max_length=255)
#     meta = models.TextField(u'meta')
#     author = models.TextField(u'author', max_length=255)
#     tags = models.ManyToManyField(Tag)
#     content = models.TextField(u'content')
#     def __unicode__(self):
#         return '%s (%s)' % (self.title, self.url)


# Path: gitcms/pages/views.py
from gitcms.tagging.models import Tag
from gitcms.pages.models import Article
from django.shortcuts import get_object_or_404, render_to_response


def bytag(request, tag):
    tag = get_object_or_404(Tag, slug=tag)
    articles = Article.objects.filter(tags=tag)
    return render_to_response(
                'pages/list.html',
                {
                    'pagetitle' : ('Articles tagged %s' % tag.name),
                    'articles' : articles,
                })

def article(request, url):
    if len(url) and url[-1] == '/': url = url[:-1]

    article = get_object_or_404(Article, url=url)