Ejemplo n.º 1
0
 def teste_pegar_todas_tags(self):
     self.primeiro_post.tags.set('python', 'django')
     self.segundo_post.tags.set('ruby', 'rails')
     self.terceiro_post.tags.set('php', 'miolo')
     pegar_todas_tags() |should| equal_to(
         ['django', 'miolo', 'php', 'python', 'rails', 'ruby']
    )
Ejemplo n.º 2
0
def post(request, slug):
    tags = pegar_todas_tags() 
    post = get_object_or_404(Post, slug=slug)

    return render_to_response(
        'posts/post.html',
        {'post': post, 'tags': tags},
        context_instance = RequestContext(request),
    )
Ejemplo n.º 3
0
def posts(request):
    tags = pegar_todas_tags()
    posts = Post.objects.all()
    
    return render_to_response(
        'posts/posts.html',
        {'posts': posts, 'tags': tags},
        context_instance = RequestContext(request),
    )
Ejemplo n.º 4
0
def busca(request):
    tags = pegar_todas_tags()
    todos_posts = Post.objects.all()
    posts = []
    for post in todos_posts:
        while post.conteudo.count('<img') != 0:
            posicao_inicial_imagem = post.conteudo.find('<img')
            posicao_final_imagem = post.conteudo.find('/>')
            tag_imagem = post.conteudo[posicao_inicial_imagem: posicao_final_imagem + 2]
            post.conteudo = post.conteudo.replace(tag_imagem, "")
        try:
            if request.POST['busca'] != '':
                request.session['busca'] = request.POST['busca']
                if request.POST['busca'].lower() in post.conteudo.lower():
                    posts.append(Post.objects.get(id=post.id))
        except:
            if request.session['busca'].lower() in post.conteudo.lower():
                posts.append(Post.objects.get(id=post.id))

    return render_to_response(
        'posts/busca.html',
        {'posts': posts, 'tags': tags},
        context_instance = RequestContext(request),
    )